From a39b0d9f9ad6f17c66d04caf3080b20ecc3f9910 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Fri, 5 Aug 2022 22:20:07 -0400 Subject: [PATCH] Add support for unit testing. --- tools/bin/td | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/bin/td b/tools/bin/td index 5f40a03..93c7a94 100644 --- a/tools/bin/td +++ b/tools/bin/td @@ -117,7 +117,27 @@ recipe_format() { # Execute all the unit tests and report any failures. recipe_test() { - echo "Unit tests are not implemented yet." + passed=0 + failed=0 + mkdir -p "build/tests" + for testSrc in $(find tests -name 'Test*.c'); do + testBin=$(basename "$testSrc" .c) + testBin="build/tests/$testBin" + + if ! $CC $CFLAGS -I src -o "$testBin" "$testSrc"; then + failed=$((failed + 1)) + break; + fi + + if ! "$testBin"; then + failed=$((failed + 1)) + break; + fi + + passed=$((passed + 1)) + done + echo "Passed: $passed, failed: $failed" + echo "Total: $((passed + failed))" } # Deploy the Telodendria website by copying the required files to