]> begriffs open source - libtap/blob - t/test.t
cmp_mem() improvements
[libtap] / t / test.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::More tests => 10;
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/cmp_mem", <<END;
56 1..7
57 ok 1 - Array must be equal to itself
58 not ok 2 - Arrays with different contents
59 #   Failed test 'Arrays with different contents'
60 #   at t/cmp_mem.c line 11.
61 #     Difference starts at offset 0
62 #          got: 0x00
63 #     expected: 0xff
64 not ok 3 - Arrays differ, but start the same
65 #   Failed test 'Arrays differ, but start the same'
66 #   at t/cmp_mem.c line 12.
67 #     Difference starts at offset 2
68 #          got: 0x00
69 #     expected: 0xff
70 ok 4 - Comparing 0 bytes of different arrays
71 not ok 5 - got == NULL
72 #   Failed test 'got == NULL'
73 #   at t/cmp_mem.c line 14.
74 #     got and/or expected are NULL
75 #          got: NULL
76 #     expected: not NULL
77 not ok 6 - expected == NULL
78 #   Failed test 'expected == NULL'
79 #   at t/cmp_mem.c line 15.
80 #     got and/or expected are NULL
81 #          got: not NULL
82 #     expected: NULL
83 not ok 7 - got == expected == NULL
84 #   Failed test 'got == expected == NULL'
85 #   at t/cmp_mem.c line 16.
86 #     got and/or expected are NULL
87 #          got: NULL
88 #     expected: NULL
89 # Looks like you failed 5 tests of 7 run.
90 END
91
92 cmd_eq_or_diff "t/diesok", <<END;
93 1..5
94 ok 1 - sanity
95 ok 2 - can't divide by zero
96 ok 3 - this is a perfectly fine statement
97 ok 4 - abort kills the program
98 ok 5 - supress output
99 END
100
101 cmd_eq_or_diff "t/is", <<END;
102 1..18
103 not ok 1 - this is that
104 #   Failed test 'this is that'
105 #   at t/is.c line 6.
106 #          got: 'this'
107 #     expected: 'that'
108 ok 2 - this is this
109 not ok 3
110 #   Failed test at t/is.c line 8.
111 #          got: 'this'
112 #     expected: 'that'
113 ok 4
114 ok 5 - null is null
115 not ok 6 - null is this
116 #   Failed test 'null is this'
117 #   at t/is.c line 11.
118 #          got: '(null)'
119 #     expected: 'this'
120 not ok 7 - this is null
121 #   Failed test 'this is null'
122 #   at t/is.c line 12.
123 #          got: 'this'
124 #     expected: '(null)'
125 not ok 8
126 #   Failed test at t/is.c line 13.
127 #          got: 'foo
128 # foo
129 # foo'
130 #     expected: 'bar
131 # bar
132 # bar'
133 ok 9
134 ok 10 - this isnt that
135 not ok 11 - this isnt this
136 #   Failed test 'this isnt this'
137 #   at t/is.c line 16.
138 #          got: 'this'
139 #     expected: anything else
140 ok 12
141 not ok 13
142 #   Failed test at t/is.c line 18.
143 #          got: 'this'
144 #     expected: anything else
145 not ok 14 - null isnt null
146 #   Failed test 'null isnt null'
147 #   at t/is.c line 19.
148 #          got: '(null)'
149 #     expected: anything else
150 ok 15 - null isnt this
151 ok 16 - this isnt null
152 ok 17
153 not ok 18
154 #   Failed test at t/is.c line 23.
155 #          got: 'foo
156 # foo
157 # foo'
158 #     expected: anything else
159 # Looks like you failed 9 tests of 18 run.
160 END
161
162 cmd_eq_or_diff "t/like", <<END;
163 1..3
164 ok 1 - strange ~~ /range/
165 ok 2 - strange !~~ /anger/
166 ok 3 - matches the regex
167 END
168
169 cmd_eq_or_diff "t/notediag", <<END;
170 # note no new line
171 # note new line
172 # diag no new line
173 # diag new line
174 END
175
176 cmd_eq_or_diff "t/simple", <<END;
177 1..24
178 ok 1
179 ok 2
180 ok 3
181 not ok 4
182 #   Failed test at t/simple.c line 9.
183 ok 5 - foo
184 ok 6 - bar
185 ok 7 - baz
186 ok 8 - quux
187 ok 9 - thud
188 ok 10 - wombat
189 ok 11 - blurgle
190 ok 12 - frob
191 not ok 13 - frobnicate
192 #   Failed test 'frobnicate'
193 #   at t/simple.c line 18.
194 ok 14 - eek
195 ok 15 - ook
196 ok 16 - frodo
197 ok 17 - bilbo
198 ok 18 - wubble
199 ok 19 - flarp
200 ok 20 - fnord
201 ok 21
202 not ok 22
203 #   Failed test at t/simple.c line 27.
204 ok 23 - good
205 not ok 24 - bad
206 #   Failed test 'bad'
207 #   at t/simple.c line 29.
208 # Looks like you failed 4 tests of 24 run.
209 END
210
211 cmd_eq_or_diff "t/skip", <<END;
212 1..8
213 ok 1 - quux
214 ok 2 - thud
215 ok 3 - wombat
216 ok 4 # skip need to be on windows
217 ok 5 - quux
218 ok 6 - thud
219 ok 7 - wombat
220 ok 8 # skip 
221 END
222
223 cmd_eq_or_diff "t/synopsis", <<END;
224 1..5
225 ok 1
226 not ok 2 - two different strings not that way?
227 #   Failed test 'two different strings not that way?'
228 #   at t/synopsis.c line 7.
229 #          got: 'fnord'
230 #     expected: 'eek'
231 ok 3 - 3 <= 8732
232 ok 4
233 not ok 5
234 #   Failed test at t/synopsis.c line 10.
235 #     3
236 #         >=
237 #     10
238 # Looks like you failed 2 tests of 5 run.
239 END
240
241 cmd_eq_or_diff "t/todo", <<END;
242 1..6
243 not ok 1 - foo # TODO
244 #   Failed (TODO) test 'foo'
245 #   at t/todo.c line 7.
246 ok 2 - bar # TODO
247 ok 3 - baz # TODO
248 not ok 4 - quux # TODO im not ready
249 #   Failed (TODO) test 'quux'
250 #   at t/todo.c line 12.
251 ok 5 - thud # TODO im not ready
252 ok 6 - wombat # TODO im not ready
253 END
254