tests: Print PASS/FAIL for each test.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 11 Jan 2020 20:07:47 +0000 (20:07 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 11 Jan 2020 20:17:35 +0000 (20:17 +0000)
Simple test harness.

.gitignore
Goalfile.in
stdlib/prelude.sh

index c7b71aa..f7f3271 100644 (file)
@@ -4,6 +4,7 @@
 *.cmx
 *.cma
 *.cmxa
+*.log
 *.o
 
 /man/*.?
index 3c6bf9d..623a09d 100644 (file)
@@ -38,6 +38,7 @@ goal clean = {
     done
     rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
     rm -f man/*.1 man/*.5
+    rm -f tests/*.log
 
     # We don't delete src/goals because it is required to do builds.
     # If you want to really delete it, use the maintainer-clean rule.
@@ -135,8 +136,19 @@ let tests = wrap ("test", wildcard ("tests/*.sh"))
 
 goal check () = : tests
 
-goal test (name) = {
+goal test (name) = @{
     t=`basename %name`
     cd tests
-    ../run ./$t
+    if ../run ./$t > $t.log 2>&1; then
+        start_green
+        echo -n "PASS: "
+        end_colour
+        echo $t
+    else
+        start_red
+        echo -n "FAIL: "
+        end_colour
+        echo $t
+        exit 1
+    fi
 }
index 60d5b9f..254c380 100644 (file)
@@ -26,3 +26,23 @@ function quoted_string ()
     # XXX This doesn't actually do quoting XXX
     echo -n "\"$1\""
 }
+
+# For printing strings in different colours, use these functions.
+function start_red ()
+{
+    echo -ne "\x1b[1;31m"
+}
+
+function start_green ()
+{
+    echo -ne "\x1b[0;32m"
+}
+
+function end_colour ()
+{
+    echo -ne "\x1b[0m"
+}
+function end_color ()
+{
+    echo -ne "\x1b[0m"
+}