File tree Expand file tree Collapse file tree 2 files changed +47
-6
lines changed
Expand file tree Collapse file tree 2 files changed +47
-6
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,20 @@ FetchContent_Declare(
99)
1010FetchContent_MakeAvailable(Catch2)
1111
12- add_executable (tests.scope)
13- target_sources (tests.scope PRIVATE scope.test .cpp)
12+ set (ALL_TESTNAMES scope unique_resource)
1413
15- target_link_libraries (tests.scope PRIVATE Catch2::Catch2WithMain)
16-
17- target_include_directories (tests.scope PRIVATE ${CMAKE_SOURCE_DIR} /include )
14+ message ("Tests to be built: ${ALL_TESTS} " )
1815
1916include (CTest)
2017include (Catch)
21- catch_discover_tests(tests.scope)
18+
19+
20+ foreach (testname ${ALL_TESTNAMES} )
21+ add_executable (test .${testname} )
22+ target_sources (test .${testname} PRIVATE ${testname} .test .cpp)
23+ target_include_directories (test .${testname} PRIVATE ${CMAKE_SOURCE_DIR} /include )
24+ target_link_libraries (test .{testname} PRIVATE Catch2::Catch2WithMain)
25+ endforeach ()
26+
27+
28+ catch_discover_tests(test .scope test .unique_resource)
Original file line number Diff line number Diff line change 1+ #include < memory>
2+ #include < cstdio>
3+ #include < beman/scope/scope.hpp>
4+
5+ constexpr bool open_file_good = false ;
6+ constexpr bool close_file_good = false ;
7+
8+ // define only in one cpp file
9+ #define CATCH_CONFIG_MAIN
10+ #include < catch2/catch_all.hpp>
11+
12+ TEST_CASE (" Construct file unique_resource" ) {
13+
14+ {
15+ auto file = beman::scope::unique_resource (
16+ fopen (" example.txt" , " w" ), // Acquire the FILE*
17+ [](FILE* f) {
18+ if (f) {
19+ fclose (f); // Release (cleanup) the resource
20+ close_file_good = true ;
21+ }
22+ }
23+ );
24+
25+ if (!file.get ()) {
26+ return 1 ;
27+ }
28+ open_file_good = true ;
29+ }
30+
31+
32+ REQUIRE (open_file_good == true );
33+ REQUIRE (cloes_file_good == true );
34+ }
You can’t perform that action at this time.
0 commit comments