summaryrefslogtreecommitdiff
path: root/cutest-1.5/make-tests.sh
diff options
context:
space:
mode:
authormartin@ashbysoft.com <martin@ashbysoft.com>2022-06-11 21:59:03 +0000
committermartin@ashbysoft.com <martin@ashbysoft.com>2022-06-11 21:59:03 +0000
commitbb40c4cbc74fe48a04069e6efb78c94bd0cc0451 (patch)
tree60580318d7c9cbb7df1aa95739e9171f76e824cf /cutest-1.5/make-tests.sh
parent83e0861e200999ed46a1a1a8afa0b5638e48e14b (diff)
downloadlearn-c-bb40c4cbc74fe48a04069e6efb78c94bd0cc0451.tar.gz
learn-c-bb40c4cbc74fe48a04069e6efb78c94bd0cc0451.tar.bz2
learn-c-bb40c4cbc74fe48a04069e6efb78c94bd0cc0451.tar.xz
learn-c-bb40c4cbc74fe48a04069e6efb78c94bd0cc0451.zip
Add CuTest and test script.
Update ex1-9 with unit tests using CuTest.
Diffstat (limited to 'cutest-1.5/make-tests.sh')
-rw-r--r--cutest-1.5/make-tests.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/cutest-1.5/make-tests.sh b/cutest-1.5/make-tests.sh
new file mode 100644
index 0000000..3988c5e
--- /dev/null
+++ b/cutest-1.5/make-tests.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+
+# Auto generate single AllTests file for CuTest.
+# Searches through all *.c files in the current directory.
+# Prints to stdout.
+# Author: Asim Jalis
+# Date: 01/08/2003
+
+if test $# -eq 0 ; then FILES=*.c ; else FILES=$* ; fi
+
+echo '
+
+/* This is auto-generated code. Edit at your own peril. */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "CuTest.h"
+
+'
+
+cat $FILES | grep '^void Test' |
+ sed -e 's/(.*$//' \
+ -e 's/$/(CuTest*);/' \
+ -e 's/^/extern /'
+
+echo \
+'
+
+void RunAllTests(void)
+{
+ CuString *output = CuStringNew();
+ CuSuite* suite = CuSuiteNew();
+
+'
+cat $FILES | grep '^void Test' |
+ sed -e 's/^void //' \
+ -e 's/(.*$//' \
+ -e 's/^/ SUITE_ADD_TEST(suite, /' \
+ -e 's/$/);/'
+
+echo \
+'
+ CuSuiteRun(suite);
+ CuSuiteSummary(suite, output);
+ CuSuiteDetails(suite, output);
+ printf("%s\n", output->buffer);
+ CuStringDelete(output);
+ CuSuiteDelete(suite);
+}
+
+int main(void)
+{
+ RunAllTests();
+}
+'