summaryrefslogtreecommitdiff
path: root/source/tests/defer.test.c
blob: 0eb85579e8211d093a639ae14adfab7291d2ce09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#if defined(__clang__) || defined(__APPLE__)
#  include "../kit/defer.h"

#  define KIT_TEST_FILE defer_block
#  include "../kit/test.h"

TEST("defer") {
  int defer_ref x = 1;

  {
    defer {
      x = 2;
    };

    x = 3;
  }

  REQUIRE_EQ(x, 2);
}

TEST("defer capture") {
  int defer_ref x = 1;

  {
    defer {
      if (x == 3)
        x = 2;
    };

    x = 3;
  }

  REQUIRE_EQ(x, 2);
}

#  undef KIT_TEST_FILE
#endif