Package: mallard-ducktype / 0.4-2

tests-runtests-Output-in-TAP-format-and-exit-nonzero-on-f.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
From: Simon McVittie <smcv@debian.org>
Date: Tue, 6 Feb 2018 17:31:18 +0000
Subject: tests/runtests: Output in TAP format, and exit nonzero on failure

This is a bit clearer (and more standardized) than "empty output is
success", and summarizing the differences between expected and actual
results on stderr is very useful for automated build environments
where the failing build environment won't be kept for subsequent
debugging.

Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://github.com/projectmallard/mallard-ducktype/pull/17
Applied-upstream: 0.5, commit:https://github.com/projectmallard/mallard-ducktype/commit/69a989f39cd9d26cc5c8c6492d0e0730621fd1f0
---
 .gitignore     |  1 +
 tests/runtests | 40 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index e1cd8e0..62320d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
 /build/
 /dist/
 /ducktype.egg-info/
+/tests/*.out
 __pycache__/
diff --git a/tests/runtests b/tests/runtests
index 91a40a3..fcec810 100755
--- a/tests/runtests
+++ b/tests/runtests
@@ -1,13 +1,47 @@
 #!/bin/sh
 
+set -e
+set -u
+
+count=0
+any_failed=0
+
 for duck in *.duck; do
+    count=$(( count + 1 ))
+    out=$(echo $duck | sed -e 's/\.duck$/.out/')
     page=$(echo $duck | sed -e 's/\.duck$/.page/')
     error=$(echo $duck | sed -e 's/\.duck$/.error/')
+    fail=""
     if [ -f "$page" ]; then
-        python3 runtest.py $duck | cmp - $page || echo $duck
+        python3 runtest.py "$duck" > "$out" || fail="exit status $?"
+        if ! cmp "$out" "$page" >&2; then
+            fail="${fail:+${fail}, }unexpected output"
+            diff -u "$out" "$page" >&2 || :
+        fi
     elif [ -f "$error" ]; then
-        python3 runtest.py $duck | cmp - $error || echo $duck
+        status=0
+        python3 runtest.py "$duck" > "$out" || :
+        if ! cmp "$out" "$error" >&2; then
+            fail="unexpected error message"
+            diff -u "$out" "$error" >&2 || :
+        fi
+    else
+        fail="neither $page nor $error exists"
+    fi
+    if [ -z "$fail" ]; then
+        echo "ok $count - $duck"
     else
-        echo $duck;
+        any_failed=1
+        echo "not ok $count - $duck: $fail"
     fi
 done
+
+echo "1..$count"
+
+if [ "$any_failed" = 0 ]; then
+    echo "# All tests successful"
+else
+    echo "# At least one test failed"
+fi
+
+exit $any_failed