mity / acutest

Simple header-only C/C++ unit testing facility.
MIT License
347 stars 96 forks source link

Implement TAP (https://testanything.org/) #17

Closed mity closed 5 years ago

mity commented 5 years ago

Fixes #16.

sandhose commented 5 years ago

Thanks for this!

I think there is an issue with stdout not being flushed before forking. When I pipe the output, the plan (1..n) repeats itself for each test, making the output invalid.

> ./tests/main --tap # Works as expected
1..5
ok 1 - ast/new
ok 2 - quad/new
ok 3 - quad/list
ok 4 - symbol/memory
ok 5 - symbol/same_name
> ./tests/main --tap | cat -
1..5
ok 1 - ast/new
1..5
ok 2 - quad/new
1..5
ok 3 - quad/list
1..5
ok 4 - symbol/memory
1..5
ok 5 - symbol/same_name
1..5

Not sure if it is a macOS specific issue, but here's a patch that solves it:

diff --git a/include/acutest.h b/include/acutest.h
index dba6370..5cf26b8 100644
--- a/include/acutest.h
+++ b/include/acutest.h
@@ -1162,8 +1162,10 @@ main(int argc, char** argv)
         /* TAP harness should provide some summary. */
         test_no_summary__ = 1;

-        if(!test_worker__)
+        if(!test_worker__) {
             printf("1..%d\n", (int) test_count__);
+            fflush(stdout);
+        }
     }

     /* Run the tests */
mity commented 5 years ago

Added the fflush() just before fork(), it's imho more robust.

Thanks for the testing.