tests: only activate 'unset' alias if required
[platform/upstream/automake.git] / t / tap-plan-errors.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # TAP support: the following situations should be flagged as errors:
18 #  - unmatched test plan (too few tests run)
19 #  - multiple test plans
20 #  - missing test plan
21 #  - misplaced test plan (tests run after a late plan)
22 # Checks about unplanned tests are performed in 'tap-unplanned.sh'
23 # and 'tap-skip-whole-badcount.sh'.  More checks about corner-cases
24 # in TAP plans are performed in 'tap-plan-corner.sh'.
25
26 . test-init.sh
27
28 . tap-setup.sh
29
30 my_check ()
31 {
32   cat > all.test
33   test -n "$err" || fatal_ "\$err not set before calling my_check"
34   cat all.test # For debugging.
35   $MAKE check >stdout && { cat stdout; exit 1; }
36   cat stdout
37   count_test_results "$@"
38   grep "^ERROR: all\\.test $err$" stdout
39   unset err
40 }
41
42 err='- too few tests run (expected 2, got 1)'
43 my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
44 1..2
45 ok 1
46 END
47
48 err='- too few tests run (expected 12, got 3)'
49 my_check total=4 pass=2 fail=0 xpass=0 xfail=1 skip=0 error=1 <<END
50 ok 1
51 ok 2
52 not ok 3 # TODO
53 1..12
54 END
55
56 err='- too few tests run (expected 1, got 0)'
57 my_check total=1 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
58 1..1
59 END
60
61 err='2 # AFTER LATE PLAN'
62 my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
63 ok 1
64 1..2
65 ok 2
66 END
67
68 err='5 # AFTER LATE PLAN'
69 my_check total=5 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
70 ok 1
71 ok 2
72 ok 3
73 ok 4
74 1..5
75 ok 5
76 END
77
78 err='- missing test plan'
79 my_check total=2 pass=1 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
80 ok 1
81 END
82
83
84 # The two test plans here are deliberately equal.
85 err='- multiple test plans'
86 my_check total=3 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
87 1..2
88 ok 1
89 ok 2
90 1..2
91 END
92
93 # The second plan is diagnosed as extra, and only the first one is
94 # relevant w.r.t. the number of the expected test.
95 err='- multiple test plans'
96 my_check total=4 pass=3 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
97 1..3
98 ok 1
99 ok 2
100 1..2
101 ok 3
102 END
103
104 # As above, in a slightly different situation.
105 err='- multiple test plans'
106 my_check total=3 pass=2 fail=0 xpass=0 xfail=0 skip=0 error=1 <<END
107 1..2
108 ok 1
109 ok 2
110 1..4
111 END
112
113 :