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