Skip to content

Commit 88e65f8

Browse files
KellesiVlada KanivetsSergiusTheBestCopilot
authored
Add tests for ScopeExit (KF-28, #48)
* add tests for ScopeExit * refactoring * add test * Update test/ScopeExitTest.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Vlada Kanivets <vlada.kanivets@apriorit.com> Co-authored-by: Sergey Podobry <sergius@apriorit.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ae5f858 commit 88e65f8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL
4444
HexTest.cpp
4545
MapTest.cpp
4646
Vector.cpp
47+
ScopeExitTest.cpp
4748
SingletonTest.cpp
4849
DoubleLinkedListTest.cpp
4950
ArrayUtilsTest.cpp

test/ScopeExitTest.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "pch.h"
2+
#include <kf/ScopeExit.h>
3+
4+
SCENARIO("SCOPE_EXIT macro")
5+
{
6+
GIVEN("A block of code with SCOPE_EXIT")
7+
{
8+
WHEN("The block is executed")
9+
{
10+
int value = 0;
11+
12+
{
13+
SCOPE_EXIT{ value++; };
14+
15+
THEN("Scoped function doesn't execute until scope ends")
16+
{
17+
REQUIRE(value == 0);
18+
}
19+
}
20+
21+
THEN("The cleanup code should execute after the block")
22+
{
23+
REQUIRE(value == 1);
24+
}
25+
}
26+
27+
WHEN("Multiple SCOPE_EXIT macros are used in the same block")
28+
{
29+
int value = 1;
30+
31+
{
32+
SCOPE_EXIT
33+
{
34+
value *= 5;
35+
};
36+
37+
SCOPE_EXIT
38+
{
39+
value += 2;
40+
};
41+
}
42+
43+
THEN("The cleanup code should execute in reverse order of declaration")
44+
{
45+
REQUIRE(value == 15);
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)