MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/scope_exit.cpp:8–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include "fl/stl/scope_exit.h"
7
8FL_TEST_FILE(FL_FILEPATH) {
9
10using namespace fl;
11
12FL_TEST_CASE("scope_exit - basic execution") {
13 int count = 0;
14 {
15 auto guard = make_scope_exit([&] { ++count; });
16 FL_CHECK_EQ(count, 0);
17 }
18 FL_CHECK_EQ(count, 1);
19}
20
21FL_TEST_CASE("scope_exit - release prevents execution") {
22 int count = 0;
23 {
24 auto guard = make_scope_exit([&] { ++count; });
25 guard.release();
26 }
27 FL_CHECK_EQ(count, 0);
28}
29
30FL_TEST_CASE("scope_exit - move transfers ownership") {
31 int count = 0;
32 {
33 auto guard1 = make_scope_exit([&] { ++count; });
34 auto guard2 = fl::move(guard1);
35 // guard1 moved-from — should not fire
36 }
37 // guard2 fires once
38 FL_CHECK_EQ(count, 1);
39}
40
41FL_TEST_CASE("scope_exit - multiple guards run in reverse order") {
42 fl::string order;
43 {
44 auto g1 = make_scope_exit([&] { order += "1"; });
45 auto g2 = make_scope_exit([&] { order += "2"; });
46 auto g3 = make_scope_exit([&] { order += "3"; });
47 }
48 // Destructors run in reverse declaration order
49 FL_CHECK_EQ(order, fl::string("321"));
50}
51
52} // FL_TEST_FILE

Callers

nothing calls this directly

Calls 3

make_scope_exitFunction · 0.85
stringClass · 0.50
releaseMethod · 0.45

Tested by

no test coverage detected