summaryrefslogtreecommitdiff
path: root/docs/application/testing.md
blob: 6e85c6f81b48cef51b9876487d4349a173439e4f (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
38
39
40
41
42
43
44
# Testing

---

## Macros

```c
TEST(NAME) {
    // TEST BODY
}

ASSERT(CONDITION, FAIL_STRING)

FAIL(FAIL_STRING)
```

## Object Definitions

```c
typedef struct {
    const char *name;
    kpl_error error;
} kpl_test;

// TODO STORE ERRORS FOR PRINT AT END

#define _TEST_FN(NAME) static void kpl_test_fn_##NAME(__attribute__(unused)) kpl_test *_test)

#define TEST(NAME) \
    _TEST_FN(NAME); \
    static void __attribute__((constructor)) _kpl_test_constructor_##NAME(void) { \
        kpl_test _test = { .name = #NAME; .error = nullptr }; \
        kpl_test_fn_##NAME(&test); \
        if (_test.error) { \
            /* TODO STORE ERROR */ \
        } \
        /* TODO PRINT STATUS */ \
    } \
    _TEST_FN(NAME)

// TODO ASSERT

// TODO FAIL
```