From 15f6e03347418caf2fdd178480c84295d417bae0 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Wed, 31 Jul 2024 23:32:36 +0200 Subject: Test suite --- bxgen.c | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'bxgen.c') diff --git a/bxgen.c b/bxgen.c index 68c131b..c5c5884 100755 --- a/bxgen.c +++ b/bxgen.c @@ -3861,18 +3861,15 @@ c8 *l_find(c8 *name) { // ================================================================ // -// EXAMPLE +// TEST SUITE // // ================================================================ -#if HELPERS && TESTING +#if TESTING -int main(int argc, char **argv) { - (void) argc; - (void) argv; - - LOG(INFO, "bxgen " VERSION); +#if HELPERS +b8 link_with_libc(void) { // ============================================================ // // Create the program semantic tree @@ -3936,16 +3933,48 @@ int main(int argc, char **argv) { } else if (HO != LE) { LOG(INFO, "Skip running the executable. Host data ordering is not compatible."); } else { - // Run the created executable file. + LOG(VERBOSE, "Running the executable"); + i32 ret = system("./test_foo"); - CHECK(WEXITSTATUS(ret) == 42, "Failure", -1); + if (WEXITSTATUS(ret) != 42) + return 0; } - LOG(INFO, "Bye!"); - return 0; + return 1; } -#endif +#endif // HELPERS -#endif +i32 main(i32 argc, c8 **argv) { + LOG(INFO, "bxgen " VERSION); + + i32 status = 0; + + i32 num_tests = 0; + i32 num_passed = 0; + + #define RUN_TEST_(t) \ + do { \ + ++num_tests; \ + if (t()) { \ + ++num_passed; \ + LOG(INFO, #t " - OK"); \ + } else \ + LOG(ERROR, #t " - FAIL"); \ + } while (0) + + #if HELPERS + RUN_TEST_(link_with_libc); + #endif + + #undef RUN_TEST_ + + LOG(INFO, "%d of %d tests passed.", num_passed, num_tests); + + return num_passed == num_tests ? 0 : -1; +} + +#endif // TESTING + +#endif // IMPLEMENTATION -- cgit v1.2.3