]> begriffs open source - libtap/blob - t/tap.t
Generate testing command in subroutine
[libtap] / t / tap.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::More tests => 9;
5 use Test::Differences;
6
7 my $x = $^O eq 'MSWin32' ? ".exe" : "";
8
9 sub cmd_eq_or_diff {
10     my ($command, $expected) = @_;
11     my $output = `$command$x 2>&1`;
12     eq_or_diff($output, $expected, $command);
13 }
14
15 cmd_eq_or_diff "t/cmpok", <<END;
16 1..9
17 not ok 1
18 #   Failed test at t/cmpok.c line 6.
19 #     420
20 #         >
21 #     666
22 not ok 2 - the number 23 is definitely 55
23 #   Failed test 'the number 23 is definitely 55'
24 #   at t/cmpok.c line 7.
25 #     23
26 #         ==
27 #     55
28 not ok 3
29 #   Failed test at t/cmpok.c line 8.
30 #     23
31 #         ==
32 #     55
33 ok 4
34 # unrecognized operator 'frob'
35 not ok 5
36 #   Failed test at t/cmpok.c line 10.
37 #     23
38 #         frob
39 #     55
40 ok 6
41 not ok 7
42 #   Failed test at t/cmpok.c line 12.
43 #     55
44 #         +
45 #     -55
46 ok 8
47 not ok 9
48 #   Failed test at t/cmpok.c line 14.
49 #     55
50 #         %
51 #     5
52 # Looks like you failed 6 tests of 9 run.
53 END
54
55 cmd_eq_or_diff "t/diesok", <<END;
56 1..5
57 ok 1 - sanity
58 ok 2 - can't divide by zero
59 ok 3 - this is a perfectly fine statement
60 ok 4 - abort kills the program
61 ok 5 - supress output
62 END
63
64 cmd_eq_or_diff "t/is", <<END;
65 1..18
66 not ok 1 - this is that
67 #   Failed test 'this is that'
68 #   at t/is.c line 6.
69 #          got: 'this'
70 #     expected: 'that'
71 ok 2 - this is this
72 not ok 3
73 #   Failed test at t/is.c line 8.
74 #          got: 'this'
75 #     expected: 'that'
76 ok 4
77 ok 5 - null is null
78 not ok 6 - null is this
79 #   Failed test 'null is this'
80 #   at t/is.c line 11.
81 #          got: '(null)'
82 #     expected: 'this'
83 not ok 7 - this is null
84 #   Failed test 'this is null'
85 #   at t/is.c line 12.
86 #          got: 'this'
87 #     expected: '(null)'
88 not ok 8
89 #   Failed test at t/is.c line 13.
90 #          got: 'foo
91 # foo
92 # foo'
93 #     expected: 'bar
94 # bar
95 # bar'
96 ok 9
97 ok 10 - this isnt that
98 not ok 11 - this isnt this
99 #   Failed test 'this isnt this'
100 #   at t/is.c line 16.
101 #          got: 'this'
102 #     expected: anything else
103 ok 12
104 not ok 13
105 #   Failed test at t/is.c line 18.
106 #          got: 'this'
107 #     expected: anything else
108 not ok 14 - null isnt null
109 #   Failed test 'null isnt null'
110 #   at t/is.c line 19.
111 #          got: '(null)'
112 #     expected: anything else
113 ok 15 - null isnt this
114 ok 16 - this isnt null
115 ok 17
116 not ok 18
117 #   Failed test at t/is.c line 23.
118 #          got: 'foo
119 # foo
120 # foo'
121 #     expected: anything else
122 # Looks like you failed 9 tests of 18 run.
123 END
124
125 cmd_eq_or_diff "t/like", <<END;
126 1..3
127 ok 1 - strange ~~ /range/
128 ok 2 - strange !~~ /anger/
129 ok 3 - matches the regex
130 END
131
132 cmd_eq_or_diff "t/notediag", <<END;
133 # note no new line
134 # note new line
135 # diag no new line
136 # diag new line
137 END
138
139 cmd_eq_or_diff "t/simple", <<END;
140 1..24
141 ok 1
142 ok 2
143 ok 3
144 not ok 4
145 #   Failed test at t/simple.c line 9.
146 ok 5 - foo
147 ok 6 - bar
148 ok 7 - baz
149 ok 8 - quux
150 ok 9 - thud
151 ok 10 - wombat
152 ok 11 - blurgle
153 ok 12 - frob
154 not ok 13 - frobnicate
155 #   Failed test 'frobnicate'
156 #   at t/simple.c line 18.
157 ok 14 - eek
158 ok 15 - ook
159 ok 16 - frodo
160 ok 17 - bilbo
161 ok 18 - wubble
162 ok 19 - flarp
163 ok 20 - fnord
164 ok 21
165 not ok 22
166 #   Failed test at t/simple.c line 27.
167 ok 23 - good
168 not ok 24 - bad
169 #   Failed test 'bad'
170 #   at t/simple.c line 29.
171 # Looks like you failed 4 tests of 24 run.
172 END
173
174 cmd_eq_or_diff "t/skip", <<END;
175 1..8
176 ok 1 - quux
177 ok 2 - thud
178 ok 3 - wombat
179 ok 4 # skip need to be on windows
180 ok 5 - quux
181 ok 6 - thud
182 ok 7 - wombat
183 ok 8 # skip 
184 END
185
186 cmd_eq_or_diff "t/synopsis", <<END;
187 1..5
188 ok 1
189 not ok 2 - two different strings not that way?
190 #   Failed test 'two different strings not that way?'
191 #   at t/synopsis.c line 7.
192 #          got: 'fnord'
193 #     expected: 'eek'
194 ok 3 - 3 <= 8732
195 ok 4
196 not ok 5
197 #   Failed test at t/synopsis.c line 10.
198 #     3
199 #         >=
200 #     10
201 # Looks like you failed 2 tests of 5 run.
202 END
203
204 cmd_eq_or_diff "t/todo", <<END;
205 1..6
206 not ok 1 - foo # TODO
207 #   Failed (TODO) test 'foo'
208 #   at t/todo.c line 7.
209 ok 2 - bar # TODO
210 ok 3 - baz # TODO
211 not ok 4 - quux # TODO im not ready
212 #   Failed (TODO) test 'quux'
213 #   at t/todo.c line 12.
214 ok 5 - thud # TODO im not ready
215 ok 6 - wombat # TODO im not ready
216 END
217