Skip to content

Commit d92fd8f

Browse files
committed
refactor: tag_invoke CPOs for test utility customization
1 parent be90f89 commit d92fd8f

File tree

5 files changed

+343
-58
lines changed

5 files changed

+343
-58
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ target_include_directories(testutil INTERFACE ${VERILATOR_ROOT}/include)
2121
target_sources(testutil INTERFACE
2222
FILE_SET HEADERS
2323
BASE_DIRS src
24-
FILES src/NyuTestUtil.hpp
24+
FILES
25+
src/NyuTestUtil.hpp
26+
src/NyuCatch2TestUtil.hpp
2527
)
2628

2729
include(CMakePackageConfigHelpers)

src/CovRecorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class VerilatorCoverageReporter : public Catch::EventListenerBase {
2424
private:
2525
std::string makeFileName(const std::string& testName) {
2626
std::string fileName(testName.size(), '\0');
27-
std::string unsafe {"/<>:\"\\|?*"};
27+
std::string unsafe {R"(/<>:"\|?*)"};
2828
std::transform(testName.begin(), testName.end(), fileName.begin(),
2929
[&](char c) { return unsafe.find(c) == std::string::npos ? c : '_'; });
3030
return fileName + ".dat";

src/NyuCatch2TestUtil.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef NYU_CATCH2_TEST_UTIL
2+
#define NYU_CATCH2_TEST_UTIL
3+
4+
#include <NyuTestUtil.hpp>
5+
6+
#include <catch2/interfaces/catch_interfaces_capture.hpp>
7+
8+
namespace nyu {
9+
struct catch2_test_name_token {};
10+
11+
std::string tag_invoke(::nyu::get_test_name_t, ::nyu::catch2_test_name_token) {
12+
return Catch::getResultCapture().getCurrentTestName();
13+
}
14+
15+
template <typename Dut> decltype(auto) get_dut_catch2(dut_options opts = {}) {
16+
return ::nyu::get_dut<Dut>(std::move(opts), ::nyu::catch2_test_name_token {});
17+
}
18+
19+
} // namespace nyu
20+
21+
#endif // NYU_CATCH2_TEST_UTIL

0 commit comments

Comments
 (0)