File tree Expand file tree Collapse file tree 2 files changed +56
-4
lines changed
Expand file tree Collapse file tree 2 files changed +56
-4
lines changed Original file line number Diff line number Diff line change 11# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22
3+ include (FetchContent)
4+
5+ FetchContent_Declare(
6+ Catch2
7+ GIT_REPOSITORY https://github.com/catchorg/Catch2.git
8+ GIT_TAG v3.8.0
9+ )
10+ FetchContent_MakeAvailable(Catch2)
11+
312add_executable (beman.scope.tests.scope)
413target_sources (beman.scope.tests.scope PRIVATE scope.test .cpp)
514
6- target_link_libraries (beman.scope.tests.scope PRIVATE beman::scope)
15+ target_link_libraries (beman.scope.tests.scope PRIVATE Catch2::Catch2WithMain)
16+
17+ target_include_directories (beman.scope.tests.scope PRIVATE ${CMAKE_SOURCE_DIR} /include )
718
8- add_test (NAME beman.scope.tests.scope COMMAND beman.scope.tests.scope)
19+ include (CTest)
20+ include (Catch)
21+ catch_discover_tests(beman.scope.tests.scope)
Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22
3- int main () {
4- // TODO: Add tests
3+ #include < beman/scope/scope.hpp>
4+
5+ // define only in one cpp file
6+ #define CATCH_CONFIG_MAIN
7+ #include < catch2/catch_all.hpp>
8+
9+ // if this compiled and no exceptions are thrown, below tests will complete successfully
10+
11+ // This is testing the "language" - the ways in which we want to "start" the scope guard.
12+
13+ TEST_CASE (" Construct scope_exit" ) {
14+
15+ beman::scope::scope_exit guard_exit1 ([] {});
16+ beman::scope::scope_exit guard_exit2 = [] {};
17+ beman::scope::scope_exit guard_exit3 = {[] {}};
18+
19+ auto guard_exit4 = beman::scope::scope_exit ([] {});
20+
21+ REQUIRE (true );
22+ }
23+
24+ TEST_CASE (" Construct scope_fail" ) {
25+
26+ beman::scope::scope_fail guard_exit1 ([] {});
27+ beman::scope::scope_fail guard_exit2 = [] {};
28+ beman::scope::scope_fail guard_exit3 = {[] {}};
29+
30+ auto guard_exit4 = beman::scope::scope_fail ([] {});
31+
32+ REQUIRE (true );
533}
34+
35+ TEST_CASE (" Construct scope_success" ) {
36+
37+ beman::scope::scope_success guard_exit1 ([] {});
38+ beman::scope::scope_success guard_exit2 = [] {};
39+ beman::scope::scope_success guard_exit3 = {[] {}};
40+
41+ auto guard_exit4 = beman::scope::scope_success ([] {});
42+
43+ REQUIRE (true );
44+ }
You can’t perform that action at this time.
0 commit comments