소스 검색

More clean test result

Matthew Wang 11 년 전
부모
커밋
6bae53b2fd
2개의 변경된 파일29개의 추가작업 그리고 20개의 파일을 삭제
  1. 28
    17
      tests/regression.sh
  2. 1
    3
      tests/test_cdiff.py

+ 28
- 17
tests/regression.sh 파일 보기

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-set -o errexit
3
+TOP_DIR=$(cd $(dirname $0)/.. && pwd) || exit 1
4
+cd $TOP_DIR || exit 1
4
 
5
 
5
-SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
6
-CDIFF=$SELF_DIR/../cdiff
6
+CDIFF=./cdiff
7
 
7
 
8
 # To test with py3k: PYTHON=python3 make test
8
 # To test with py3k: PYTHON=python3 make test
9
 PYTHON=${PYTHON:-python}
9
 PYTHON=${PYTHON:-python}
26
     fi
26
     fi
27
 }
27
 }
28
 
28
 
29
-function cmpOutput()
29
+function cmp_output()
30
 {
30
 {
31
     local input=${1:?}
31
     local input=${1:?}
32
     local expected_out=${2:?}
32
     local expected_out=${2:?}
33
     local cdiff_opt=${3:-""}
33
     local cdiff_opt=${3:-""}
34
+    local cmd
34
 
35
 
35
-    echo -n "Test option '$cdiff_opt' with input '$input' ... "
36
-    if $PYTHON $CDIFF $cdiff_opt $input 2>/dev/null \
37
-            | diff -ubq $expected_out - >& /dev/null; then
36
+    cmd=$(printf "%-8s $CDIFF %-25s %-20s " $PYTHON "$input" "$cdiff_opt")
37
+    printf "$cmd"
38
+    if $cmd 2>/dev/null | diff -ubq $expected_out - >& /dev/null; then
38
         pass
39
         pass
39
         return 0
40
         return 0
40
     else
41
     else
41
-        fail "(expected output: '$expected_out')"
42
+        fail "!= $expected_out"
42
         return 1
43
         return 1
43
     fi
44
     fi
44
 }
45
 }
45
 
46
 
46
 function main()
47
 function main()
47
 {
48
 {
48
-    local rc=0
49
+    local total=0
50
+    local e=0
49
     local d
51
     local d
50
 
52
 
51
-    for d in $SELF_DIR/*/; do
52
-        cmpOutput "${d}in.diff" ${d}out.normal "-c always" || rc=1
53
-        cmpOutput "${d}in.diff" ${d}out.side-by-side "-c always -s" || rc=1
54
-        cmpOutput "${d}in.diff" ${d}out.w70 "-c always -s -w70" || rc=1
55
-        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto" || rc=1
56
-        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s" || rc=1
57
-        cmpOutput "${d}in.diff" "${d}in.diff" "-c auto -s -w70" || rc=1
53
+    for d in tests/*/; do
54
+        d=${d%/}
55
+        cmp_output $d/in.diff $d/out.normal "-c always" || ((e++))
56
+        cmp_output $d/in.diff $d/out.side-by-side "-c always -s" || ((e++))
57
+        cmp_output $d/in.diff $d/out.w70 "-c always -s -w70" || ((e++))
58
+        cmp_output $d/in.diff $d/in.diff "-c auto" || ((e++))
59
+        cmp_output $d/in.diff $d/in.diff "-c auto -s" || ((e++))
60
+        cmp_output $d/in.diff $d/in.diff "-c auto -s -w70" || ((e++))
61
+        (( total += 6 ))
58
     done
62
     done
59
-    return $rc
63
+
64
+    if (( e > 0 )); then
65
+        echo "*** $e out of $total tests failed." >&2
66
+        return 1
67
+    else
68
+        echo "All $total tests passed."
69
+        return 0
70
+    fi
60
 }
71
 }
61
 
72
 
62
 main "$@"
73
 main "$@"

+ 1
- 3
tests/test_cdiff.py 파일 보기

63
         items = ['hello', 'world', 'again', 'and', 'again']
63
         items = ['hello', 'world', 'again', 'and', 'again']
64
         stream = cdiff.PatchStream(Sequential(items))
64
         stream = cdiff.PatchStream(Sequential(items))
65
 
65
 
66
-        out = []
67
         _ = stream.read_stream_header(2)
66
         _ = stream.read_stream_header(2)
68
-        for item in stream:
69
-            out.append(item)
67
+        out = list(stream)
70
         self.assertEqual(out, items)
68
         self.assertEqual(out, items)
71
 
69
 
72
 
70