4 libtap - Write tests in C
14 is("fnord", "eek", "two different strings not that way?");
15 ok(3 <= 8732, "%d <= %d", 3, 8732);
16 like("fnord", "f(yes|no)r*[a-f]$");
25 not ok 2 - two different strings not that way?
26 # Failed test 'two different strings not that way?'
27 # at t/synopsis.c line 7.
33 # Failed test at t/synopsis.c line 10.
37 # Looks like you failed 2 tests of 5 run.
42 tap is an easy to read and easy to write way of creating tests for your
43 software. This library creates functions that can be used to generate it for
44 your C programs. It is mostly based on the Test::More Perl module.
52 - plan(SKIP_ALL, fmt, ...)
54 Use this to start a series of tests. When you know how many tests there
55 will be, you can put a number as a number of tests you expect to run. If
56 you do not know how many tests there will be, you can use plan(NO_PLAN)
57 or not call this function. When you pass it a number of tests to run, a
58 message similar to the following will appear in the output:
62 If you pass it SKIP_ALL, the whole test will be skipped.
67 Specify a test. the test can be any statement returning a true or false
68 value. You may optionally pass a format string describing the test.
70 ok(r = reader_new("Of Mice and Men"), "create a new reader");
71 ok(reader_go_to_page(r, 55), "can turn the page");
72 ok(r->page == 55, "page turned to the right one");
76 ok 1 - create a new reader
77 ok 2 - can turn the page
78 ok 3 - page turned to the right one
80 On failure, a diagnostic message will be printed out.
82 not ok 3 - page turned to the right one
83 # Failed test 'page turned to the right one'
84 # at reader.c line 13.
87 - is(got, expected, fmt, ...)
88 - isnt(got, unexpected)
89 - isnt(got, unexpected, fmt, ...)
91 Tests that the string you got is what you expected. with isnt, it is the
94 is("this", "that", "this is that");
98 not ok 1 - this is that
99 # Failed test 'this is that'
105 - cmp_ok(a, op, b, fmt, ...)
107 Compares two ints with any binary operator that doesn't require an lvalue.
108 This is nice to use since it provides a better error message than an
111 cmp_ok(420, ">", 666);
116 # Failed test at cmpok.c line 5.
121 - cmp_mem(got, expected, n)
122 - cmp_mem(got, expected, n, fmt, ...)
124 Tests that the first n bytes of the memory you got is what you expected.
125 You have to take care that the pointers are valid and n is not greater than
126 the the amount of memory allocated for either got or expected.
135 # Failed test at t/cmp_mem.c line 9.
136 # Difference starts at offset 0
140 - like(got, expected)
141 - like(got, expected, fmt, ...)
142 - unlike(got, unexpected)
143 - unlike(got, unexpected, fmt, ...)
145 Tests that the string you got matches the expected extended POSIX regex.
146 unlike is the reverse. These macros are the equivalent of a skip on
149 like("stranger", "^s.(r).*\\1$", "matches the regex");
153 ok 1 - matches the regex
160 Speciy that a test succeeded or failed. Use these when the statement is
161 longer than you can fit into the argument given to an ok() test.
164 - dies_ok(code, fmt, ...)
166 - lives_ok(code, fmt, ...)
168 Tests whether the given code causes your program to exit. The code gets
169 passed to a macro that will test it in a forked process. If the code
170 succeeds it will be executed in the parent process. You can test things
171 like passing a function a null pointer and make sure it doesnt
172 dereference it and crash.
174 dies_ok({abort();}, "abort does close your program");
175 dies_ok({int x = 0/0;}, "divide by zero crash");
176 lives_ok({pow(3.0, 5.0);}, "nothing wrong with taking 3**5");
178 On Windows, these macros are the equivalent of a skip.
182 Summarizes the tests that occurred and exits the main function. If
183 there was no plan, it will print out the number of tests as.
187 It will also print a diagnostic message about how many
190 # Looks like you failed 2 tests of 3 run.
192 If all planned tests were successful, it will return 0. If any test fails,
193 it will return the number of failed tests (including ones that were
194 missing). If they all passed, but there were missing tests, it will return
200 print out a message to the tap output. note prints to stdout and diag
201 prints to stderr. Each line is preceeded by a "# " so that you know its a
204 note("This is\na note\nto describe\nsomething.");
213 ok() and these functions return ints so you can use them like:
215 ok(1) && note("yo!");
216 ok(0) || diag("I have no idea what just happened");
219 - skip(test, n, fmt, ...)
222 Skip a series of n tests if test is true. You may give a reason why you are
223 skipping them or not. The (possibly) skipped tests must occur between the
224 skip and end_skip macros.
240 Specifies a series of tests that you expect to fail because they are not
250 # Failed (TODO) test at todo.c line 7
255 Immediately stops all testing.
257 BAIL_OUT("Can't go no further");
261 Bail out! Can't go no further