diff options
| author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2026-10-15 22:51:45 +0300 |
|---|---|---|
| committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2026-10-15 22:51:45 +0300 |
| commit | 662c7c620e6db915c5705bd0afa84925bb84704d (patch) | |
| tree | 3179c8fc3a8c36b2461e9dc6572ac5812d3a6112 /utest/utest-test.c | |
| parent | 491216939bd9824cc0da6d7ca7d7108595cb691d (diff) | |
| download | c-wares-662c7c620e6db915c5705bd0afa84925bb84704d.tar.gz c-wares-662c7c620e6db915c5705bd0afa84925bb84704d.zip | |
* C23 required.
* Less macro voodoo magic.
* The test declaration API changed.
* Now there's a test type with the test data.
* Now it's possible to set a time out for each test.
* It's now also possible to initialize data for each test separately.
* More importantly, each test is now isolated in its own process, so
that we beautifully report a crash and continue with the rest.
* Still less than 500loc even with all the comments!
Diffstat (limited to 'utest/utest-test.c')
| -rw-r--r-- | utest/utest-test.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/utest/utest-test.c b/utest/utest-test.c index 591ee32..df7d51b 100644 --- a/utest/utest-test.c +++ b/utest/utest-test.c @@ -2,23 +2,28 @@ static int a, b; -/* This should pass */ -TEST_BEGIN(test_pass) +void test_pass_run(utest *t) { - asserteq(a, 0); - assertneq(a, b); - expect(b > a, "expected b > a"); - TEST_OUT + asserteq(t, a, 0); + assertneq(t, a, b); + expect(t, b > a, "expected b > a"); } -TEST_END -/* This should fail */ -TEST_BEGIN(test_fail) +void test_fail_run(utest *t) { - expect(0, "oopsie!"); - TEST_OUT + expect(t, 0, "oopsie!"); +} + +void test_crash_run(utest *t) +{ + int *x = NULL; + *x = 8; +} + +void test_timeout_run(utest *t) +{ + sleep(10); } -TEST_END void test_init(void) { @@ -26,9 +31,16 @@ void test_init(void) printf("hello, world!\n\n"); } -void test_destroy(void) +void test_cleanup(void) { printf("\ngood bye!\n"); } -RUN_TEST_SUITE(test_init, test_destroy, test_pass, test_fail); +utest tests[] = { + UTEST_INIT_S(test_pass, 0), + UTEST_INIT_S(test_fail, 0), + UTEST_INIT_S(test_crash, 0), + UTEST_INIT_S(test_timeout, 1), +}; + +RUN_TEST_SUITE(test_init, test_cleanup, tests); |
