From ebc0cee38108813f4d3056f31f26cdde4b84c838 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:08:26 -0500 Subject: [PATCH 1/3] chore: simplify rs/tests.hpp --- rs-cpp/include/rs/tests.hpp | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/rs-cpp/include/rs/tests.hpp b/rs-cpp/include/rs/tests.hpp index 905d170cb..0ec506fed 100644 --- a/rs-cpp/include/rs/tests.hpp +++ b/rs-cpp/include/rs/tests.hpp @@ -5,8 +5,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -34,35 +36,8 @@ concept Lt = requires(T lhs, U rhs) { { lhs < rhs } -> std::convertible_to; }; -// Returns the module name from a file path. There are two cases: -// -// 1. src/Rustify/Tests.cc -> Rustify/Tests -// (when we run `make test` from the root directory) -// 2. ../../src/Rustify/Tests.cc -> Rustify/Tests -// (when we run `cabin test`) -// -// We first should remove `../../` if it exists, then remove the first -// directory name since it can be either `src` or `tests`. Finally, we remove -// the file extension, which is basically any of C++ source file extensions. -constexpr std::string_view getModName(std::string_view file) noexcept { - if (file.empty()) { - return file; - } - - std::size_t start = file.find("src/"); - if (start == std::string_view::npos) { - start = file.find("lib/"); - } - if (start == std::string_view::npos) { - return file; - } - - const std::size_t end = file.find_last_of('.'); - if (end == std::string_view::npos || end <= start) { - return file; - } - - return file.substr(start, end - start); +std::string getModName(std::string_view file) noexcept { + return std::filesystem::relative(file).replace_extension().string(); } constexpr std::string_view prettifyFuncName(std::string_view func) noexcept { @@ -85,13 +60,13 @@ constexpr std::string_view prettifyFuncName(std::string_view func) noexcept { inline void pass(const std::source_location& loc = std::source_location::current()) noexcept { - fmt::print(" test {}::{} ... {}ok{}\n", getModName(loc.file_name()), + std::print(" test {}::{} ... {}ok{}\n", getModName(loc.file_name()), prettifyFuncName(loc.function_name()), GREEN, RESET); } [[noreturn]] inline void error(const std::source_location& loc, const std::string_view msg) { - fmt::print(stderr, + std::print(stderr, "\n test {}::{} ... {}FAILED{}\n\n" "'{}' failed at '{}', {}:{}\n", getModName(loc.file_name()), prettifyFuncName(loc.function_name()), From 8b8476631c54384f579b526d4672f033254e4fc7 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:11:01 -0500 Subject: [PATCH 2/3] fix: include --- rs-cpp/include/rs/tests.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs-cpp/include/rs/tests.hpp b/rs-cpp/include/rs/tests.hpp index 0ec506fed..9000e9a4f 100644 --- a/rs-cpp/include/rs/tests.hpp +++ b/rs-cpp/include/rs/tests.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include From 6e9a0d45b23ec94997061562fa6f8c9dd3826c72 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:14:44 -0500 Subject: [PATCH 3/3] fix: remove noexcept --- rs-cpp/include/rs/tests.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rs-cpp/include/rs/tests.hpp b/rs-cpp/include/rs/tests.hpp index 9000e9a4f..c0827aed6 100644 --- a/rs-cpp/include/rs/tests.hpp +++ b/rs-cpp/include/rs/tests.hpp @@ -36,7 +36,7 @@ concept Lt = requires(T lhs, U rhs) { { lhs < rhs } -> std::convertible_to; }; -std::string getModName(std::string_view file) noexcept { +std::string getModName(std::string_view file) { return std::filesystem::relative(file).replace_extension().string(); } @@ -59,7 +59,7 @@ constexpr std::string_view prettifyFuncName(std::string_view func) noexcept { } inline void pass(const std::source_location& loc = - std::source_location::current()) noexcept { + std::source_location::current()) { std::print(" test {}::{} ... {}ok{}\n", getModName(loc.file_name()), prettifyFuncName(loc.function_name()), GREEN, RESET); }