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