diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-01-22 00:23:32 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-01-22 00:23:32 +0100 |
| commit | aaeb153ce869567f4f88f083dba28445216714f6 (patch) | |
| tree | 00848a7ee91478f68f26226d10685c579079fe88 /tests/test.c | |
| parent | 6dc6d1004393b7c093a3aef7456af67662d56fee (diff) | |
| download | nissy-aaeb153ce869567f4f88f083dba28445216714f6.tar.gz nissy-aaeb153ce869567f4f88f083dba28445216714f6.zip | |
Started working on testing (broken for now)
Diffstat (limited to 'tests/test.c')
| -rw-r--r-- | tests/test.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..c122db8 --- /dev/null +++ b/tests/test.c | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "fst_tests.h" | ||
| 3 | |||
| 4 | static bool run_test(Test *); | ||
| 5 | static bool run_suite(TestSuite *); | ||
| 6 | |||
| 7 | static bool | ||
| 8 | run_test(Test *test) | ||
| 9 | { | ||
| 10 | int i; | ||
| 11 | |||
| 12 | printf("Running test %s...", test->name); | ||
| 13 | for (i = 0; test->cases[i] != NULL; i++) { | ||
| 14 | if (!test->t(test->cases[i])) { | ||
| 15 | printf("FAILED!\n"); | ||
| 16 | return false; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | printf("OK\n"); | ||
| 21 | return true; | ||
| 22 | } | ||
| 23 | |||
| 24 | static bool | ||
| 25 | run_suite(TestSuite *suite) | ||
| 26 | { | ||
| 27 | int i; | ||
| 28 | |||
| 29 | if (suite->setup != NULL) | ||
| 30 | suite->setup(); | ||
| 31 | for (i = 0; suite->tests[i] != NULL; i++) | ||
| 32 | if(!run_test(suite->tests[i])) | ||
| 33 | return false; | ||
| 34 | if (suite->teardown != NULL) | ||
| 35 | suite->teardown(); | ||
| 36 | |||
| 37 | return true; | ||
| 38 | } | ||
| 39 | |||
| 40 | int main() { | ||
| 41 | if (!run_suite(&fst_pre_init_suite)) | ||
| 42 | return 1; | ||
| 43 | if (!run_suite(&fst_post_init_suite)) | ||
| 44 | return 1; | ||
| 45 | |||
| 46 | printf("All tests passed.\n"); | ||
| 47 | return 0; | ||
| 48 | } | ||
