Skip to content

Commit 914483d

Browse files
committed
reinstate catch2 into module test file, cleanup test
1 parent aff35b1 commit 914483d

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

tests/module.test.cpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
#define CATCH_CONFIG_MAIN
4+
#include <catch2/catch_all.hpp>
5+
6+
// for g++-15 the order is important -- import after includes
37
import beman.scope;
4-
// #include <stdexcept>
5-
// #include <string>
6-
#include <cassert>
7-
8-
// #define CATCH_CONFIG_MAIN
9-
// #include <catch2/catch_all.hpp>
10-
11-
// clang-format off
12-
// struct noisy_resource {
13-
// noisy_resource() { std::print( "construct noisy\n" ); }
14-
// ~noisy_resource() { std::print( "destroy noisy\n" ); }
15-
// };
16-
17-
//TEST_CASE("module-test", "[scope_module_test]") {
18-
int main()
19-
{
20-
bool exit_ran, success_ran, fail_ran = false;
8+
9+
struct DummyResource {
10+
bool& cleaned;
11+
12+
DummyResource(bool& flag) : cleaned(flag) { cleaned = false; }
13+
14+
bool is_clean() const { return cleaned; }
15+
};
16+
17+
TEST_CASE("module-test", "[scope_module_test]") {
18+
bool exit_ran, success_ran, fail_ran, cleaned = true;
2119
{
22-
beman::scope::scope_exit _([&exit_ran] { exit_ran = true; });
23-
beman::scope::scope_success _([&success_ran] { success_ran = true; });
24-
beman::scope::scope_fail _([&fail_ran] { fail_ran = true; });
25-
// auto resource_ptr = beman::scope::unique_resource(new noisy_resource(),
26-
// // Cleanup function
27-
// [](noisy_resource* ptr) { delete ptr; });
20+
// clang-format off
21+
beman::scope::scope_exit _se([&exit_ran] { exit_ran = true; });
22+
beman::scope::scope_success _ss([&success_ran] { success_ran = true; });
23+
beman::scope::scope_fail _sf([&fail_ran] { fail_ran = true; });
24+
auto resource_ptr = beman::scope::unique_resource(new DummyResource(cleaned),
25+
[](DummyResource* ptr) { ptr->cleaned =true; delete ptr; });
26+
REQUIRE(cleaned == false);
27+
REQUIRE(resource_ptr->is_clean() == false);
28+
// clang-format on
2829
} // Normal scope exit
2930

30-
assert(exit_ran == true);
31-
assert(success_ran == true);
32-
assert(fail_ran == false);
31+
REQUIRE(exit_ran == true);
32+
REQUIRE(success_ran == true);
33+
REQUIRE(fail_ran == false);
34+
REQUIRE(cleaned == true);
3335

34-
}
36+
}

0 commit comments

Comments
 (0)