summaryrefslogtreecommitdiffstats
path: root/tap
diff options
context:
space:
mode:
Diffstat (limited to 'tap')
-rw-r--r--tap/Makefile.am13
-rw-r--r--tap/README11
-rw-r--r--tap/tap.3368
-rw-r--r--tap/tap.c435
-rw-r--r--tap/tap.h89
-rw-r--r--tap/tests/Makefile.am7
-rw-r--r--tap/tests/README12
-rw-r--r--tap/tests/diag/Makefile.am13
-rw-r--r--tap/tests/diag/test.c46
-rw-r--r--tap/tests/diag/test.pl16
-rw-r--r--tap/tests/diag/test.t29
-rw-r--r--tap/tests/fail/Makefile.am13
-rw-r--r--tap/tests/fail/test.c46
-rw-r--r--tap/tests/fail/test.pl17
-rw-r--r--tap/tests/fail/test.t29
-rw-r--r--tap/tests/ok/Makefile.am3
-rw-r--r--tap/tests/ok/ok-hash/Makefile.am13
-rw-r--r--tap/tests/ok/ok-hash/test.c52
-rw-r--r--tap/tests/ok/ok-hash/test.pl24
-rw-r--r--tap/tests/ok/ok-hash/test.t29
-rw-r--r--tap/tests/ok/ok-numeric/Makefile.am13
-rw-r--r--tap/tests/ok/ok-numeric/test.c49
-rw-r--r--tap/tests/ok/ok-numeric/test.pl21
-rw-r--r--tap/tests/ok/ok-numeric/test.t29
-rw-r--r--tap/tests/ok/ok/Makefile.am13
-rw-r--r--tap/tests/ok/ok/test.c55
-rw-r--r--tap/tests/ok/ok/test.pl27
-rw-r--r--tap/tests/ok/ok/test.t29
-rw-r--r--tap/tests/pass/Makefile.am13
-rw-r--r--tap/tests/pass/test.c46
-rw-r--r--tap/tests/pass/test.pl17
-rw-r--r--tap/tests/pass/test.t29
-rw-r--r--tap/tests/plan/Makefile.am7
-rw-r--r--tap/tests/plan/no-tests/Makefile.am13
-rw-r--r--tap/tests/plan/no-tests/test.c43
-rw-r--r--tap/tests/plan/no-tests/test.pl14
-rw-r--r--tap/tests/plan/no-tests/test.t29
-rw-r--r--tap/tests/plan/no_plan/Makefile.am13
-rw-r--r--tap/tests/plan/no_plan/test.c43
-rw-r--r--tap/tests/plan/no_plan/test.pl14
-rw-r--r--tap/tests/plan/no_plan/test.t29
-rw-r--r--tap/tests/plan/not-enough-tests/Makefile.am13
-rw-r--r--tap/tests/plan/not-enough-tests/test.c49
-rw-r--r--tap/tests/plan/not-enough-tests/test.pl20
-rw-r--r--tap/tests/plan/not-enough-tests/test.t29
-rw-r--r--tap/tests/plan/sane/Makefile.am13
-rw-r--r--tap/tests/plan/sane/test.c43
-rw-r--r--tap/tests/plan/sane/test.pl14
-rw-r--r--tap/tests/plan/sane/test.t29
-rw-r--r--tap/tests/plan/skip_all/Makefile.am13
-rw-r--r--tap/tests/plan/skip_all/test.c38
-rw-r--r--tap/tests/plan/skip_all/test.pl11
-rw-r--r--tap/tests/plan/skip_all/test.t29
-rw-r--r--tap/tests/plan/too-many-plans/Makefile.am13
-rw-r--r--tap/tests/plan/too-many-plans/test.c49
-rw-r--r--tap/tests/plan/too-many-plans/test.pl20
-rw-r--r--tap/tests/plan/too-many-plans/test.t29
-rw-r--r--tap/tests/plan/too-many-tests/Makefile.am13
-rw-r--r--tap/tests/plan/too-many-tests/test.c46
-rw-r--r--tap/tests/plan/too-many-tests/test.pl17
-rw-r--r--tap/tests/plan/too-many-tests/test.t29
-rw-r--r--tap/tests/skip/Makefile.am13
-rw-r--r--tap/tests/skip/test.c69
-rw-r--r--tap/tests/skip/test.pl40
-rw-r--r--tap/tests/skip/test.t29
-rw-r--r--tap/tests/todo/Makefile.am13
-rw-r--r--tap/tests/todo/test.c68
-rw-r--r--tap/tests/todo/test.pl41
-rw-r--r--tap/tests/todo/test.t29
69 files changed, 2630 insertions, 0 deletions
diff --git a/tap/Makefile.am b/tap/Makefile.am
new file mode 100644
index 0000000..86147c5
--- /dev/null
+++ b/tap/Makefile.am
@@ -0,0 +1,13 @@
1# Tap self-tests are not implemented (yet?)
2# SUBDIRS = tests
3
4if USE_LIBTAP_LOCAL
5noinst_LTLIBRARIES = libtap.la
6libtap_la_SOURCES = tap.c tap.h
7include_HEADERS = tap.h
8endif USE_LIBTAP_LOCAL
9
10# see top comment
11#prove:
12# prove -v -r
13
diff --git a/tap/README b/tap/README
new file mode 100644
index 0000000..6c15be0
--- /dev/null
+++ b/tap/README
@@ -0,0 +1,11 @@
1NAME
2 tap -- write tests that implement the Test Anything Protocol
3
4SYNOPSIS
5 #include <tap.h>
6
7DESCRIPTION
8 The tap library provides functions for writing test scripts that produce
9 output consistent with the Test Anything Protocol. A test harness that
10 parses this protocol can run these tests and produce useful reports indi-
11 cating their success or failure.
diff --git a/tap/tap.3 b/tap/tap.3
new file mode 100644
index 0000000..4b23c24
--- /dev/null
+++ b/tap/tap.3
@@ -0,0 +1,368 @@
1.Dd December 20, 2004
2.Os
3.Dt TAP 3
4.Sh NAME
5.Nm tap
6.Nd write tests that implement the Test Anything Protocol
7.Sh SYNOPSIS
8.In tap.h
9.Sh DESCRIPTION
10The
11.Nm
12library provides functions for writing test scripts that produce output
13consistent with the Test Anything Protocol. A test harness that parses
14this protocol can run these tests and produce useful reports indicating
15their success or failure.
16.Ss PRINTF STRINGS
17In the descriptions that follow, for any function that takes as the
18last two parameters
19.Dq Fa char * , Fa ...
20it can be assumed that the
21.Fa char *
22is a
23.Fn printf
24-like format string, and the optional arguments are values to be placed
25in that string.
26.Ss TEST PLANS
27.Bl -tag -width indent
28.It Xo
29.Ft int
30.Fn plan_tests "unsigned int"
31.Xc
32.It Xo
33.Ft int
34.Fn plan_no_plan "void"
35.Xc
36.It Xo
37.Ft int
38.Fn plan_skip_all "char *" "..."
39.Xc
40.El
41.Pp
42You must first specify a test plan. This indicates how many tests you
43intend to run, and allows the test harness to notice if any tests were
44missed, or if the test program exited prematurely.
45.Pp
46To do this, use
47.Fn plan_tests ,
48which always returns 0. The function will cause your program to exit
49prematurely if you specify 0 tests.
50.Pp
51In some situations you may not know how many tests you will be running, or
52you are developing your test program, and do not want to update the
53.Fn plan_tests
54parameter every time you make a change. For those situations use
55.Fn plan_no_plan .
56It returns 0, and indicates to the test harness that an indeterminate number
57of tests will be run.
58.Pp
59Both
60.Fn plan_tests
61and
62.Fn plan_no_plan
63will cause your test program to exit prematurely with a diagnostic
64message if they are called more than once.
65.Pp
66If your test program detects at run time that some required functionality
67is missing (for example, it relies on a database connection which is not
68present, or a particular configuration option that has not been included
69in the running kernel) use
70.Fn plan_skip_all ,
71passing as parameters a string to display indicating the reason for skipping
72the tests.
73.Ss SIMPLE TESTS
74.Bl -tag -width indent
75.It Xo
76.Ft unsigned int
77.Fn ok "expression" "char *" "..."
78.Xc
79.It Xo
80.Ft unsigned int
81.Fn ok1 "expression"
82.Xc
83.It Xo
84.Ft unsigned int
85.Fn pass "char *" "..."
86.Xc
87.It Xo
88.Ft unsigned int
89.Fn fail "char *" "..."
90.Xc
91.El
92.Pp
93Tests are implemented as expressions checked by calls to the
94.Fn ok
95and
96.Fn ok1
97macros. In both cases
98.Fa expression
99should evaluate to true if the test succeeded.
100.Pp
101.Fn ok
102allows you to specify a name, or comment, describing the test which will
103be included in the output.
104.Fn ok1
105is for those times when the expression to be tested is self
106explanatory and does not need an associated comment. In those cases
107the test expression becomes the comment.
108.Pp
109These four calls are equivalent:
110.Bd -literal -offset indent
111int i = 5;
112
113ok(i == 5, "i equals 5"); /* Overly verbose */
114ok(i == 5, "i equals %d", i); /* Just to demonstrate printf-like
115 behaviour of the test name */
116ok(i == 5, "i == 5"); /* Needless repetition */
117ok1(i == 5); /* Just right */
118.Ed
119.Pp
120It is good practice to ensure that the test name describes the meaning
121behind the test rather than what you are testing. Viz
122.Bd -literal -offset indent
123ok(db != NULL, "db is not NULL"); /* Not bad, but */
124ok(db != NULL, "Database conn. succeeded"); /* this is better */
125.Ed
126.Pp
127.Fn ok
128and
129.Fn ok1
130return 1 if the expression evaluated to true, and 0 if it evaluated to
131false. This lets you chain calls from
132.Fn ok
133to
134.Fn diag
135to only produce diagnostic output if the test failed. For example, this
136code will include diagnostic information about why the database connection
137failed, but only if the test failed.
138.Bd -literal -offset indent
139ok(db != NULL, "Database conn. succeeded") ||
140 diag("Database error code: %d", dberrno);
141.Ed
142.Pp
143You also have
144.Fn pass
145and
146.Fn fail .
147From the Test::More documentation:
148.Bd -literal -offset indent
149Sometimes you just want to say that the tests have passed.
150Usually the case is you've got some complicated condition
151that is difficult to wedge into an ok(). In this case,
152you can simply use pass() (to declare the test ok) or fail
153(for not ok).
154
155Use these very, very, very sparingly.
156.Ed
157.Pp
158These are synonyms for ok(1, ...) and ok(0, ...).
159.Ss SKIPPING TESTS
160.Bl -tag -width indent
161.It Xo
162.Ft int
163.Fn skip "unsigned int" "char *" "..."
164.Xc
165.It Xo
166.Fn skip_start "expression" "unsigned int" "char *" "..."
167.Xc
168.It Xo
169.Sy skip_end
170.Xc
171.El
172.Pp
173Sets of tests can be skipped. Ordinarily you would do this because
174the test can't be run in this particular testing environment.
175.Pp
176For example, suppose some tests should be run as root. If the test is
177not being run as root then the tests should be skipped. In this
178implementation, skipped tests are flagged as being ok, with a special
179message indicating that they were skipped. It is your responsibility
180to ensure that the number of tests skipped (the first parameter to
181.Fn skip )
182is correct for the number of tests to skip.
183.Pp
184One way of implementing this is with a
185.Dq do { } while(0);
186loop, or an
187.Dq if( ) { } else { }
188construct, to ensure that there are no additional side effects from the
189skipped tests.
190.Bd -literal -offset indent
191if(getuid() != 0) {
192 skip(1, "because test only works as root");
193} else {
194 ok(do_something_as_root() == 0, "Did something as root");
195}
196.Ed
197.Pp
198Two macros are provided to assist with this. The previous example could
199be re-written as follows.
200.Bd -literal -offset indent
201skip_start(getuid() != 0, 1, "because test only works as root");
202
203ok(do_something_as_root() == 0, "Did something as root");
204
205skip_end; /* It's a macro, no parentheses */
206.Ed
207.Ss MARKING TESTS AS Dq TODO
208.Bl -tag -width indent
209.It Xo
210.Ft void
211.Fn todo_start "char *" "..."
212.Xc
213.It Xo
214.Ft void
215.Fn todo_end "void"
216.Xc
217.El
218.Pp
219Sets of tests can be flagged as being
220.Dq TODO .
221These are tests that you expect to fail, probably because you haven't
222fixed a bug, or finished a new feature yet. These tests will still be
223run, but with additional output that indicates that they are expected
224to fail. Should a test start to succeed unexpectedly, tools like
225.Xr prove 1
226will indicate this, and you can move the test out of the todo
227block. This is much more useful than simply commenting out (or
228.Dq #ifdef 0 ... #endif )
229the tests.
230.Bd -literal -offset indent
231todo_start("dwim() not returning true yet");
232
233ok(dwim(), "Did what the user wanted");
234
235todo_end();
236.Ed
237.Pp
238Should
239.Fn dwim
240ever start succeeding you will know about it as soon as you run the
241tests. Note that
242.Em unlike
243the
244.Fn skip_*
245family, additional code between
246.Fn todo_start
247and
248.Fn todo_end
249.Em is
250executed.
251.Ss SKIP vs. TODO
252From the Test::More documentation;
253.Bd -literal -offset indent
254If it's something the user might not be able to do, use SKIP.
255This includes optional modules that aren't installed, running
256under an OS that doesn't have some feature (like fork() or
257symlinks), or maybe you need an Internet connection and one
258isn't available.
259
260If it's something the programmer hasn't done yet, use TODO.
261This is for any code you haven't written yet, or bugs you have
262yet to fix, but want to put tests in your testing script
263(always a good idea).
264.Ed
265.Ss DIAGNOSTIC OUTPUT
266.Bl -tag -width indent
267.It Xo
268.Fr unsigned int
269.Fn diag "char *" "..."
270.Xc
271.El
272.Pp
273If your tests need to produce diagnostic output, use
274.Fn diag .
275It ensures that the output will not be considered by the TAP test harness.
276.Fn diag
277adds the necessary trailing
278.Dq \en
279for you.
280.Bd -literal -offset indent
281diag("Expected return code 0, got return code %d", rcode);
282.Ed
283.Pp
284.Fn diag
285always returns 0.
286.Ss EXIT STATUS
287.Bl -tag -width indent
288.It Xo
289.Fr int
290.Fn exit_status void
291.Xc
292.El
293.Pp
294For maximum compatability your test program should return a particular
295exit code. This is calculated by
296.Fn exit_status
297so it is sufficient to always return from
298.Fn main
299with either
300.Dq return exit_status();
301or
302.Dq exit(exit_status());
303as appropriate.
304.Sh EXAMPLES
305The
306.Pa tests
307directory in the source distribution contains numerous tests of
308.Nm
309functionality, written using
310.Nm .
311Examine them for examples of how to construct test suites.
312.Sh COMPATABILITY
313.Nm
314strives to be compatible with the Perl Test::More and Test::Harness
315modules. The test suite verifies that
316.Nm
317is bug-for-bug compatible with their behaviour. This is why some
318functions which would more naturally return nothing return constant
319values.
320.Pp
321If the
322.Lb libpthread
323is found at compile time,
324.Nm
325.Em should
326be thread safe. Indications to the contrary (and test cases that expose
327incorrect behaviour) are very welcome.
328.Sh SEE ALSO
329.Xr Test::More 1 ,
330.Xr Test::Harness 1 ,
331.Xr prove 1
332.Sh STANDARDS
333.Nm
334requires a
335.St -isoC-99
336compiler. Some of the
337.Nm
338functionality is implemented as variadic macros, and that functionality
339was not formally codified until C99. Patches to use
340.Nm
341with earlier compilers that have their own implementation of variadic
342macros will be gratefully received.
343.Sh HISTORY
344.Nm
345was written to help improve the quality and coverage of the FreeBSD
346regression test suite, and released in the hope that others find it
347a useful tool to help improve the quality of their code.
348.Sh AUTHORS
349.An "Nik Clayton" Aq nik@ngo.org.uk ,
350.Aq nik@FreeBSD.org
351.Pp
352.Nm
353would not exist without the efforts of
354.An "Michael G Schwern" Aq schqern@pobox.com ,
355.An "Andy Lester" Aq andy@petdance.com ,
356and the countless others who have worked on the Perl QA programme.
357.Sh BUGS
358Ideally, running the tests would have no side effects on the behaviour
359of the application you are testing. However, it is not always possible
360to avoid them. The following side effects of using
361.Nm
362are known.
363.Bl -bullet -offset indent
364.It
365stdout is set to unbuffered mode after calling any of the
366.Fn plan_*
367functions.
368.El
diff --git a/tap/tap.c b/tap/tap.c
new file mode 100644
index 0000000..97c20e9
--- /dev/null
+++ b/tap/tap.c
@@ -0,0 +1,435 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <ctype.h>
28#include <stdarg.h>
29#include <stdio.h>
30#include <stdlib.h>
31
32#include "tap.h"
33
34static int no_plan = 0;
35static int skip_all = 0;
36static int have_plan = 0;
37static unsigned int test_count = 0; /* Number of tests that have been run */
38static unsigned int e_tests = 0; /* Expected number of tests to run */
39static unsigned int failures = 0; /* Number of tests that failed */
40static char *todo_msg = NULL;
41static char *todo_msg_fixed = "libtap malloc issue";
42static int todo = 0;
43static int test_died = 0;
44
45/* Encapsulate the pthread code in a conditional. In the absence of
46 libpthread the code does nothing */
47#ifdef HAVE_LIBPTHREAD
48#include <pthread.h>
49static pthread_mutex_t M = PTHREAD_MUTEX_INITIALIZER;
50# define LOCK pthread_mutex_lock(&M);
51# define UNLOCK pthread_mutex_unlock(&M);
52#else
53# define LOCK
54# define UNLOCK
55#endif
56
57static void _expected_tests(unsigned int);
58static void _tap_init(void);
59static void _cleanup(void);
60
61/*
62 * Generate a test result.
63 *
64 * ok -- boolean, indicates whether or not the test passed.
65 * test_name -- the name of the test, may be NULL
66 * test_comment -- a comment to print afterwards, may be NULL
67 */
68unsigned int
69_gen_result(int ok, const char *func, char *file, unsigned int line,
70 char *test_name, ...)
71{
72 va_list ap;
73 char *local_test_name = NULL;
74 char *c;
75 int name_is_digits;
76
77 LOCK;
78
79 test_count++;
80
81 /* Start by taking the test name and performing any printf()
82 expansions on it */
83 if(test_name != NULL) {
84 va_start(ap, test_name);
85 vasprintf(&local_test_name, test_name, ap);
86 va_end(ap);
87
88 /* Make sure the test name contains more than digits
89 and spaces. Emit an error message and exit if it
90 does */
91 if(local_test_name) {
92 name_is_digits = 1;
93 for(c = local_test_name; *c != '\0'; c++) {
94 if(!isdigit(*c) && !isspace(*c)) {
95 name_is_digits = 0;
96 break;
97 }
98 }
99
100 if(name_is_digits) {
101 diag(" You named your test '%s'. You shouldn't use numbers for your test names.", local_test_name);
102 diag(" Very confusing.");
103 }
104 }
105 }
106
107 if(!ok) {
108 printf("not ");
109 failures++;
110 }
111
112 printf("ok %d", test_count);
113
114 if(test_name != NULL) {
115 printf(" - ");
116
117 /* Print the test name, escaping any '#' characters it
118 might contain */
119 if(local_test_name != NULL) {
120 flockfile(stdout);
121 for(c = local_test_name; *c != '\0'; c++) {
122 if(*c == '#')
123 fputc('\\', stdout);
124 fputc((int)*c, stdout);
125 }
126 funlockfile(stdout);
127 } else { /* vasprintf() failed, use a fixed message */
128 printf("%s", todo_msg_fixed);
129 }
130 }
131
132 /* If we're in a todo_start() block then flag the test as being
133 TODO. todo_msg should contain the message to print at this
134 point. If it's NULL then asprintf() failed, and we should
135 use the fixed message.
136
137 This is not counted as a failure, so decrement the counter if
138 the test failed. */
139 if(todo) {
140 printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
141 if(!ok)
142 failures--;
143 }
144
145 printf("\n");
146
147 if(!ok)
148 diag(" Failed %stest (%s:%s() at line %d)",
149 todo ? "(TODO) " : "", file, func, line);
150
151 free(local_test_name);
152
153 UNLOCK;
154
155 /* We only care (when testing) that ok is positive, but here we
156 specifically only want to return 1 or 0 */
157 return ok ? 1 : 0;
158}
159
160/*
161 * Initialise the TAP library. Will only do so once, however many times it's
162 * called.
163 */
164void
165_tap_init(void)
166{
167 static int run_once = 0;
168
169 LOCK;
170
171 if(!run_once) {
172 atexit(_cleanup);
173
174 /* stdout needs to be unbuffered so that the output appears
175 in the same place relative to stderr output as it does
176 with Test::Harness */
177 setbuf(stdout, 0);
178 run_once = 1;
179 }
180
181 UNLOCK;
182}
183
184/*
185 * Note that there's no plan.
186 */
187int
188plan_no_plan(void)
189{
190
191 LOCK;
192
193 _tap_init();
194
195 if(have_plan != 0) {
196 fprintf(stderr, "You tried to plan twice!\n");
197 test_died = 1;
198 UNLOCK;
199 exit(255);
200 }
201
202 have_plan = 1;
203 no_plan = 1;
204
205 UNLOCK;
206
207 return 0;
208}
209
210/*
211 * Note that the plan is to skip all tests
212 */
213int
214plan_skip_all(char *reason)
215{
216
217 LOCK;
218
219 _tap_init();
220
221 skip_all = 1;
222
223 printf("1..0");
224
225 if(reason != NULL)
226 printf(" # Skip %s", reason);
227
228 printf("\n");
229
230 UNLOCK;
231
232 exit(0);
233}
234
235/*
236 * Note the number of tests that will be run.
237 */
238int
239plan_tests(unsigned int tests)
240{
241
242 LOCK;
243
244 _tap_init();
245
246 if(have_plan != 0) {
247 fprintf(stderr, "You tried to plan twice!\n");
248 test_died = 1;
249 UNLOCK;
250 exit(255);
251 }
252
253 if(tests == 0) {
254 fprintf(stderr, "You said to run 0 tests! You've got to run something.\n");
255 test_died = 1;
256 UNLOCK;
257 exit(255);
258 }
259
260 have_plan = 1;
261
262 _expected_tests(tests);
263
264 UNLOCK;
265
266 return 0;
267}
268
269unsigned int
270diag(char *fmt, ...)
271{
272 va_list ap;
273
274 LOCK;
275
276 fputs("# ", stderr);
277
278 va_start(ap, fmt);
279 vfprintf(stderr, fmt, ap);
280 va_end(ap);
281
282 fputs("\n", stderr);
283
284 UNLOCK;
285
286 return 0;
287}
288
289void
290_expected_tests(unsigned int tests)
291{
292
293 LOCK;
294
295 printf("1..%d\n", tests);
296 e_tests = tests;
297
298 UNLOCK;
299}
300
301int
302skip(unsigned int n, char *fmt, ...)
303{
304 va_list ap;
305 char *skip_msg;
306
307 LOCK;
308
309 va_start(ap, fmt);
310 asprintf(&skip_msg, fmt, ap);
311 va_end(ap);
312
313 while(n-- > 0) {
314 test_count++;
315 printf("ok %d # skip %s\n", test_count,
316 skip_msg != NULL ?
317 skip_msg : "libtap():malloc() failed");
318 }
319
320 free(skip_msg);
321
322 UNLOCK;
323
324 return 1;
325}
326
327void
328todo_start(char *fmt, ...)
329{
330 va_list ap;
331
332 LOCK;
333
334 va_start(ap, fmt);
335 vasprintf(&todo_msg, fmt, ap);
336 va_end(ap);
337
338 todo = 1;
339
340 UNLOCK;
341}
342
343void
344todo_end(void)
345{
346
347 LOCK;
348
349 todo = 0;
350 free(todo_msg);
351
352 UNLOCK;
353}
354
355int
356exit_status(void)
357{
358 int r;
359
360 LOCK;
361
362 /* If there's no plan, just return the number of failures */
363 if(no_plan || !have_plan) {
364 UNLOCK;
365 return failures;
366 }
367
368 /* Ran too many tests? Return the number of tests that were run
369 that shouldn't have been */
370 if(e_tests < test_count) {
371 r = test_count - e_tests;
372 UNLOCK;
373 return r;
374 }
375
376 /* Return the number of tests that failed + the number of tests
377 that weren't run */
378 r = failures + e_tests - test_count;
379 UNLOCK;
380
381 return r;
382}
383
384/*
385 * Cleanup at the end of the run, produce any final output that might be
386 * required.
387 */
388void
389_cleanup(void)
390{
391
392 LOCK;
393
394 /* If plan_no_plan() wasn't called, and we don't have a plan,
395 and we're not skipping everything, then something happened
396 before we could produce any output */
397 if(!no_plan && !have_plan && !skip_all) {
398 diag("Looks like your test died before it could output anything.");
399 UNLOCK;
400 return;
401 }
402
403 if(test_died) {
404 diag("Looks like your test died just after %d.", test_count);
405 UNLOCK;
406 return;
407 }
408
409
410 /* No plan provided, but now we know how many tests were run, and can
411 print the header at the end */
412 if(!skip_all && (no_plan || !have_plan)) {
413 printf("1..%d\n", test_count);
414 }
415
416 if((have_plan && !no_plan) && e_tests < test_count) {
417 diag("Looks like you planned %d tests but ran %d extra.",
418 e_tests, test_count - e_tests);
419 UNLOCK;
420 return;
421 }
422
423 if((have_plan || !no_plan) && e_tests > test_count) {
424 diag("Looks like you planned %d tests but only ran %d.",
425 e_tests, test_count);
426 UNLOCK;
427 return;
428 }
429
430 if(failures)
431 diag("Looks like you failed %d tests of %d.",
432 failures, test_count);
433
434 UNLOCK;
435}
diff --git a/tap/tap.h b/tap/tap.h
new file mode 100644
index 0000000..e64f9d5
--- /dev/null
+++ b/tap/tap.h
@@ -0,0 +1,89 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27/* '## __VA_ARGS__' is a gcc'ism. C99 doesn't allow the token pasting
28 and requires the caller to add the final comma if they've ommitted
29 the optional arguments */
30#ifdef __GNUC__
31# define ok(e, test, ...) ((e) ? \
32 _gen_result(1, __func__, __FILE__, __LINE__, \
33 test, ## __VA_ARGS__) : \
34 _gen_result(0, __func__, __FILE__, __LINE__, \
35 test, ## __VA_ARGS__))
36
37# define ok1(e) ((e) ? \
38 _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
39 _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
40
41# define pass(test, ...) ok(1, test, ## __VA_ARGS__);
42# define fail(test, ...) ok(0, test, ## __VA_ARGS__);
43
44# define skip_start(test, n, fmt, ...) \
45 do { \
46 if((test)) { \
47 skip(n, fmt, ## __VA_ARGS__); \
48 continue; \
49 }
50#elif __STDC_VERSION__ >= 199901L /* __GNUC__ */
51# define ok(e, ...) ((e) ? \
52 _gen_result(1, __func__, __FILE__, __LINE__, \
53 __VA_ARGS__) : \
54 _gen_result(0, __func__, __FILE__, __LINE__, \
55 __VA_ARGS__))
56
57# define ok1(e) ((e) ? \
58 _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
59 _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
60
61# define pass(...) ok(1, __VA_ARGS__);
62# define fail(...) ok(0, __VA_ARGS__);
63
64# define skip_start(test, n, ...) \
65 do { \
66 if((test)) { \
67 skip(n, __VA_ARGS__); \
68 continue; \
69 }
70#else /* __STDC_VERSION__ */
71# error "Needs gcc or C99 compiler for variadic macros."
72#endif /* __STDC_VERSION__ */
73
74# define skip_end } while(0);
75
76unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...);
77
78int plan_no_plan(void);
79int plan_skip_all(char *);
80int plan_tests(unsigned int);
81
82unsigned int diag(char *, ...);
83
84int skip(unsigned int, char *, ...);
85
86void todo_start(char *, ...);
87void todo_end(void);
88
89int exit_status(void);
diff --git a/tap/tests/Makefile.am b/tap/tests/Makefile.am
new file mode 100644
index 0000000..481a967
--- /dev/null
+++ b/tap/tests/Makefile.am
@@ -0,0 +1,7 @@
1SUBDIRS= diag
2SUBDIRS+= fail
3SUBDIRS+= ok
4SUBDIRS+= pass
5SUBDIRS+= plan
6SUBDIRS+= skip
7SUBDIRS+= todo
diff --git a/tap/tests/README b/tap/tests/README
new file mode 100644
index 0000000..a15fec2
--- /dev/null
+++ b/tap/tests/README
@@ -0,0 +1,12 @@
1Most of the tests follow the same pattern.
2
3 * test.pl that uses Test::More, and demonstrates whatever functionality
4 that we're trying to test. This is the reference code.
5
6 * test.c, which tests the libtap reimplementation of the same functionality.
7
8 * test.t, which compiles the .c program, runs both test scripts, and then
9 diffs their output to make sure it's identical.
10
11 Right now, test.t is identical in every directory. This sucks somewhat.
12 It should either be a symlink to a common script
diff --git a/tap/tests/diag/Makefile.am b/tap/tests/diag/Makefile.am
new file mode 100644
index 0000000..c1ccb75
--- /dev/null
+++ b/tap/tests/diag/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../src
10test_LDFLAGS = -L../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/diag/test.c b/tap/tests/diag/test.c
new file mode 100644
index 0000000..401db64
--- /dev/null
+++ b/tap/tests/diag/test.c
@@ -0,0 +1,46 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 plan_tests(2);
37
38 rc = diag("A diagnostic message");
39 diag("Returned: %d", rc);
40
41 /* Make sure the failure is passed through */
42 ok(1, "test 1") || diag("ok() failed, and shouldn't");
43 ok(0, "test 2") || diag("ok() passed, and shouldn't");
44
45 return exit_status();
46}
diff --git a/tap/tests/diag/test.pl b/tap/tests/diag/test.pl
new file mode 100644
index 0000000..621dc27
--- /dev/null
+++ b/tap/tests/diag/test.pl
@@ -0,0 +1,16 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10plan tests => 2;
11
12$rc = diag("A diagnostic message");
13diag("Returned: $rc");
14
15ok(1, 'test 1') or diag "ok() failed, and shouldn't";
16ok(0, 'test 2') or diag "ok() passed, and shouldn't";
diff --git a/tap/tests/diag/test.t b/tap/tests/diag/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/diag/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/fail/Makefile.am b/tap/tests/fail/Makefile.am
new file mode 100644
index 0000000..c1ccb75
--- /dev/null
+++ b/tap/tests/fail/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../src
10test_LDFLAGS = -L../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/fail/test.c b/tap/tests/fail/test.c
new file mode 100644
index 0000000..621b6c2
--- /dev/null
+++ b/tap/tests/fail/test.c
@@ -0,0 +1,46 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(2);
37 diag("Returned: %d", rc);
38
39 rc = fail("test to fail");
40 diag("Returned: %d", rc);
41
42 rc = fail("test to fail %s", "with extra string");
43 diag("Returned: %d", rc);
44
45 return exit_status();
46}
diff --git a/tap/tests/fail/test.pl b/tap/tests/fail/test.pl
new file mode 100644
index 0000000..73de1a7
--- /dev/null
+++ b/tap/tests/fail/test.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 2;
11diag("Returned: " . sprintf('%d', $rc));
12
13$rc = fail('test to fail');
14diag("Returned: $rc");
15
16$rc = fail('test to fail with extra string');
17diag("Returned: $rc");
diff --git a/tap/tests/fail/test.t b/tap/tests/fail/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/fail/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/ok/Makefile.am b/tap/tests/ok/Makefile.am
new file mode 100644
index 0000000..c949748
--- /dev/null
+++ b/tap/tests/ok/Makefile.am
@@ -0,0 +1,3 @@
1SUBDIRS = ok
2SUBDIRS += ok-hash
3SUBDIRS += ok-numeric
diff --git a/tap/tests/ok/ok-hash/Makefile.am b/tap/tests/ok/ok-hash/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/ok/ok-hash/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/ok/ok-hash/test.c b/tap/tests/ok/ok-hash/test.c
new file mode 100644
index 0000000..16be137
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.c
@@ -0,0 +1,52 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(4);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, "Test with no hash");
40 diag("Returned: %d", rc);
41
42 rc = ok(1, "Test with one # hash");
43 diag("Returned: %d", rc);
44
45 rc = ok(1, "Test with # two # hashes");
46 diag("Returned: %d", rc);
47
48 rc = ok(1, "Test with ## back to back hashes");
49 diag("Returned: %d", rc);
50
51 return exit_status();
52}
diff --git a/tap/tests/ok/ok-hash/test.pl b/tap/tests/ok/ok-hash/test.pl
new file mode 100644
index 0000000..306ddca
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.pl
@@ -0,0 +1,24 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 4;
11diag("Returned: " . sprintf("%d", $rc));
12
13
14$rc = ok(1, 'Test with no hash');
15diag("Returned: $rc");
16
17$rc = ok(1, 'Test with one # hash');
18diag("Returned: $rc");
19
20$rc = ok(1, 'Test with # two # hashes');
21diag("Returned: $rc");
22
23$rc = ok(1, 'Test with ## back to back hashes');
24diag("Returned: $rc");
diff --git a/tap/tests/ok/ok-hash/test.t b/tap/tests/ok/ok-hash/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/ok/ok-numeric/Makefile.am b/tap/tests/ok/ok-numeric/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/ok/ok-numeric/test.c b/tap/tests/ok/ok-numeric/test.c
new file mode 100644
index 0000000..0e33a74
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.c
@@ -0,0 +1,49 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(3);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, "First test");
40 diag("Returned: %d", rc);
41
42 rc = ok(1, "1");
43 diag("Returned: %d", rc);
44
45 rc = ok(1, "Third test");
46 diag("Returned: %d", rc);
47
48 return exit_status();
49}
diff --git a/tap/tests/ok/ok-numeric/test.pl b/tap/tests/ok/ok-numeric/test.pl
new file mode 100644
index 0000000..86f165f
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.pl
@@ -0,0 +1,21 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 3;
11diag("Returned: " . sprintf("%d", $rc));
12
13
14$rc = ok(1, 'First test');
15diag("Returned: $rc");
16
17$rc = ok(1, '1');
18diag("Returned: $rc");
19
20$rc = ok(1, 'Third test');
21diag("Returned: $rc");
diff --git a/tap/tests/ok/ok-numeric/test.t b/tap/tests/ok/ok-numeric/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/ok/ok/Makefile.am b/tap/tests/ok/ok/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/ok/ok/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/ok/ok/test.c b/tap/tests/ok/ok/test.c
new file mode 100644
index 0000000..ae04f2e
--- /dev/null
+++ b/tap/tests/ok/ok/test.c
@@ -0,0 +1,55 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(5);
37 diag("Returned: %d", rc);
38
39 rc = ok(1 == 1, "1 equals 1");
40 diag("Returned: %d", rc);
41
42 rc = ok(1 == 1, "1 equals %d", 1);
43 diag("Returned: %d", rc);
44
45 rc = ok1(1 == 1);
46 diag("Returned: %d", rc);
47
48 rc = ok(1 == 2, "1 equals 2");
49 diag("Returned: %d", rc);
50
51 rc = ok1(1 == 2);
52 diag("Returned: %d", rc);
53
54 return exit_status();
55}
diff --git a/tap/tests/ok/ok/test.pl b/tap/tests/ok/ok/test.pl
new file mode 100644
index 0000000..59f4181
--- /dev/null
+++ b/tap/tests/ok/ok/test.pl
@@ -0,0 +1,27 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 5;
11diag("Returned: " . sprintf("%d", $rc));
12
13
14$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
15diag("Returned: $rc");
16
17$rc = ok(1 == 1, '1 equals 1'); # Used for %d testing in test.c
18diag("Returned: $rc");
19
20$rc = ok(1 == 1, '1 == 1'); # Test ok1() passes when it should
21diag("Returned: $rc");
22
23$rc = ok(1 == 2, '1 equals 2'); # Test ok() fails when it should
24diag("Returned: $rc");
25
26$rc = ok(1 == 2, '1 == 2'); # Test ok1() fails when it should
27diag("Returned: $rc");
diff --git a/tap/tests/ok/ok/test.t b/tap/tests/ok/ok/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/ok/ok/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/pass/Makefile.am b/tap/tests/pass/Makefile.am
new file mode 100644
index 0000000..c1ccb75
--- /dev/null
+++ b/tap/tests/pass/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../src
10test_LDFLAGS = -L../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/pass/test.c b/tap/tests/pass/test.c
new file mode 100644
index 0000000..39d8a7c
--- /dev/null
+++ b/tap/tests/pass/test.c
@@ -0,0 +1,46 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(2);
37 diag("Returned: %d", rc);
38
39 rc = pass("test to pass");
40 diag("Returned: %d", rc);
41
42 rc = pass("test to pass %s", "with extra string");
43 diag("Returned: %d", rc);
44
45 return exit_status();
46}
diff --git a/tap/tests/pass/test.pl b/tap/tests/pass/test.pl
new file mode 100644
index 0000000..8abc92e
--- /dev/null
+++ b/tap/tests/pass/test.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 2;
11diag("Returned: " . sprintf('%d', $rc));
12
13$rc = pass('test to pass');
14diag("Returned: $rc");
15
16$rc = pass('test to pass with extra string');
17diag("Returned: $rc");
diff --git a/tap/tests/pass/test.t b/tap/tests/pass/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/pass/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/Makefile.am b/tap/tests/plan/Makefile.am
new file mode 100644
index 0000000..0724931
--- /dev/null
+++ b/tap/tests/plan/Makefile.am
@@ -0,0 +1,7 @@
1SUBDIRS = no-tests
2SUBDIRS += no_plan
3SUBDIRS += not-enough-tests
4SUBDIRS += too-many-plans
5SUBDIRS += too-many-tests
6SUBDIRS += sane
7SUBDIRS += skip_all
diff --git a/tap/tests/plan/no-tests/Makefile.am b/tap/tests/plan/no-tests/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/no-tests/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/no-tests/test.c b/tap/tests/plan/no-tests/test.c
new file mode 100644
index 0000000..78c5d37
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.c
@@ -0,0 +1,43 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(0);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 return exit_status();
43}
diff --git a/tap/tests/plan/no-tests/test.pl b/tap/tests/plan/no-tests/test.pl
new file mode 100644
index 0000000..93d2b3b
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.pl
@@ -0,0 +1,14 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 0;
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
diff --git a/tap/tests/plan/no-tests/test.t b/tap/tests/plan/no-tests/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/no_plan/Makefile.am b/tap/tests/plan/no_plan/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/no_plan/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/no_plan/test.c b/tap/tests/plan/no_plan/test.c
new file mode 100644
index 0000000..5cffbdc
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.c
@@ -0,0 +1,43 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_no_plan();
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 return exit_status();
43}
diff --git a/tap/tests/plan/no_plan/test.pl b/tap/tests/plan/no_plan/test.pl
new file mode 100644
index 0000000..19e42b5
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.pl
@@ -0,0 +1,14 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6my $rc = 0;
7
8use Test::More;
9
10$rc = plan qw(no_plan);
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
diff --git a/tap/tests/plan/no_plan/test.t b/tap/tests/plan/no_plan/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/not-enough-tests/Makefile.am b/tap/tests/plan/not-enough-tests/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/not-enough-tests/test.c b/tap/tests/plan/not-enough-tests/test.c
new file mode 100644
index 0000000..a9ec64f
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.c
@@ -0,0 +1,49 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(1);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 rc = ok(1, NULL);
43 diag("Returned: %d", rc);
44
45 rc = ok(1, NULL);
46 diag("Returned: %d", rc);
47
48 return exit_status();
49}
diff --git a/tap/tests/plan/not-enough-tests/test.pl b/tap/tests/plan/not-enough-tests/test.pl
new file mode 100644
index 0000000..73787a7
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.pl
@@ -0,0 +1,20 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 1;
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
15
16$rc = ok(1);
17diag("Returned: $rc");
18
19$rc = ok(1);
20diag("Returned: $rc");
diff --git a/tap/tests/plan/not-enough-tests/test.t b/tap/tests/plan/not-enough-tests/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/sane/Makefile.am b/tap/tests/plan/sane/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/sane/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/sane/test.c b/tap/tests/plan/sane/test.c
new file mode 100644
index 0000000..0843d3a
--- /dev/null
+++ b/tap/tests/plan/sane/test.c
@@ -0,0 +1,43 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(1);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 return exit_status();
43}
diff --git a/tap/tests/plan/sane/test.pl b/tap/tests/plan/sane/test.pl
new file mode 100644
index 0000000..35c4ef2
--- /dev/null
+++ b/tap/tests/plan/sane/test.pl
@@ -0,0 +1,14 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 1;
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
diff --git a/tap/tests/plan/sane/test.t b/tap/tests/plan/sane/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/sane/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/skip_all/Makefile.am b/tap/tests/plan/skip_all/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/skip_all/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/skip_all/test.c b/tap/tests/plan/skip_all/test.c
new file mode 100644
index 0000000..31722da
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.c
@@ -0,0 +1,38 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include "tap.h"
28
29int
30main(int argc, char *argv[])
31{
32 unsigned int rc = 0;
33
34 rc = plan_skip_all("No good reason");
35 diag("Returned: %d", rc);
36
37 return exit_status();
38}
diff --git a/tap/tests/plan/skip_all/test.pl b/tap/tests/plan/skip_all/test.pl
new file mode 100644
index 0000000..3255572
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.pl
@@ -0,0 +1,11 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan skip_all => "No good reason";
11diag("Returned: " . sprintf("%d", $rc));
diff --git a/tap/tests/plan/skip_all/test.t b/tap/tests/plan/skip_all/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/too-many-plans/Makefile.am b/tap/tests/plan/too-many-plans/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/too-many-plans/test.c b/tap/tests/plan/too-many-plans/test.c
new file mode 100644
index 0000000..b189cb7
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.c
@@ -0,0 +1,49 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(1);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 rc = plan_tests(1);
43 diag("Returned: %d", rc);
44
45 rc = ok(0, NULL);
46 diag("Returned: %d", rc);
47
48 return exit_status();
49}
diff --git a/tap/tests/plan/too-many-plans/test.pl b/tap/tests/plan/too-many-plans/test.pl
new file mode 100644
index 0000000..893e5fc
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.pl
@@ -0,0 +1,20 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 1;
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
15
16$rc = plan tests => 1;
17diag("Returned: $rc");
18
19$rc = ok(0);
20diag("Returned: $rc");
diff --git a/tap/tests/plan/too-many-plans/test.t b/tap/tests/plan/too-many-plans/test.t
new file mode 100644
index 0000000..cd2acf7
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/twice!.*$/twice!/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/twice!.*$/twice!/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/plan/too-many-tests/Makefile.am b/tap/tests/plan/too-many-tests/Makefile.am
new file mode 100644
index 0000000..91d880e
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../../src
10test_LDFLAGS = -L../../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/plan/too-many-tests/test.c b/tap/tests/plan/too-many-tests/test.c
new file mode 100644
index 0000000..0f72410
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.c
@@ -0,0 +1,46 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35
36 rc = plan_tests(5);
37 diag("Returned: %d", rc);
38
39 rc = ok(1, NULL);
40 diag("Returned: %d", rc);
41
42 rc = ok(0, NULL);
43 diag("Returned: %d", rc);
44
45 return exit_status();
46}
diff --git a/tap/tests/plan/too-many-tests/test.pl b/tap/tests/plan/too-many-tests/test.pl
new file mode 100644
index 0000000..0a1666b
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.pl
@@ -0,0 +1,17 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 5;
11diag("Returned: " . sprintf("%d", $rc));
12
13$rc = ok(1);
14diag("Returned: $rc");
15
16$rc = ok(0);
17diag("Returned: $rc");
diff --git a/tap/tests/plan/too-many-tests/test.t b/tap/tests/plan/too-many-tests/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/skip/Makefile.am b/tap/tests/skip/Makefile.am
new file mode 100644
index 0000000..c1ccb75
--- /dev/null
+++ b/tap/tests/skip/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../src
10test_LDFLAGS = -L../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/skip/test.c b/tap/tests/skip/test.c
new file mode 100644
index 0000000..d8f3eaf
--- /dev/null
+++ b/tap/tests/skip/test.c
@@ -0,0 +1,69 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35 unsigned int side_effect = 0;
36
37 rc = plan_tests(4);
38 diag("Returned: %d", rc);
39
40 rc = ok(1 == 1, "1 equals 1"); /* Should always work */
41 diag("Returned: %d", rc);
42
43 do {
44 if(1) {
45 rc = skip(1, "Testing skipping");
46 continue;
47 }
48
49 side_effect++;
50
51 ok(side_effect == 1, "side_effect checked out");
52
53 } while(0);
54
55 diag("Returned: %d", rc);
56
57 skip_start(1 == 1, 1, "Testing skipping #2");
58
59 side_effect++;
60 rc = ok(side_effect == 1, "side_effect checked out");
61 diag("Returned: %d", rc);
62
63 skip_end;
64
65 rc = ok(side_effect == 0, "side_effect is %d", side_effect);
66 diag("Returned: %d", rc);
67
68 return exit_status();
69}
diff --git a/tap/tests/skip/test.pl b/tap/tests/skip/test.pl
new file mode 100644
index 0000000..dc29471
--- /dev/null
+++ b/tap/tests/skip/test.pl
@@ -0,0 +1,40 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 4;
11diag("Returned: " . sprintf("%d", $rc));
12
13my $side_effect = 0; # Check whether skipping has side effects
14
15$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
16diag("Returned: $rc");
17
18# Start skipping
19SKIP: {
20 $rc = skip "Testing skipping", 1;
21
22 $side_effect++;
23
24 $rc = ok($side_effect == 1, '$side_effect checked out');
25}
26
27diag("Returned: $rc");
28
29SKIP: {
30 $rc = skip "Testing skipping #2", 1;
31 diag("Returned: $rc");
32
33 $side_effect++;
34
35 $rc = ok($side_effect == 1, '$side_effect checked out');
36 diag("Returned: $rc");
37}
38
39$rc = ok($side_effect == 0, "side_effect is $side_effect");
40diag("Returned: $rc");
diff --git a/tap/tests/skip/test.t b/tap/tests/skip/test.t
new file mode 100644
index 0000000..bf0fe8f
--- /dev/null
+++ b/tap/tests/skip/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi
diff --git a/tap/tests/todo/Makefile.am b/tap/tests/todo/Makefile.am
new file mode 100644
index 0000000..c1ccb75
--- /dev/null
+++ b/tap/tests/todo/Makefile.am
@@ -0,0 +1,13 @@
1
2TESTS = test.t
3TESTS_ENVIRONMENT = $(SHELL)
4
5EXTRA_DIST = $(TESTS) test.pl
6
7check_PROGRAMS = test
8
9test_CFLAGS = -g -I../../src
10test_LDFLAGS = -L../../src
11test_LDADD = -ltap
12
13CLEANFILES = test.o test.c.out test.pl.out
diff --git a/tap/tests/todo/test.c b/tap/tests/todo/test.c
new file mode 100644
index 0000000..ac6339a
--- /dev/null
+++ b/tap/tests/todo/test.c
@@ -0,0 +1,68 @@
1/*-
2 * Copyright (c) 2004 Nik Clayton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <stdio.h>
28
29#include "tap.h"
30
31int
32main(int argc, char *argv[])
33{
34 unsigned int rc = 0;
35 unsigned int side_effect = 0;
36
37 rc = plan_tests(5);
38 diag("Returned: %d", rc);
39
40 rc = ok(1 == 1, "1 equals 1"); /* Should always work */
41 diag("Returned: %d", rc);
42
43 todo_start("For testing purposes");
44
45 side_effect++;
46
47 /* This test should fail */
48 rc = ok(side_effect == 0, "side_effect checked out");
49 diag("Returned: %d", rc);
50
51 /* This test should unexpectedly succeed */
52 rc = ok(side_effect == 1, "side_effect checked out");
53 diag("Returned: %d", rc);
54
55 todo_end();
56
57 todo_start("Testing printf() %s in todo_start()", "expansion");
58
59 rc = ok(0, "dummy test");
60 diag("Returned: %d", rc);
61
62 todo_end();
63
64 rc = ok(side_effect == 1, "side_effect is %d", side_effect);
65 diag("Returned: %d", rc);
66
67 return exit_status();
68}
diff --git a/tap/tests/todo/test.pl b/tap/tests/todo/test.pl
new file mode 100644
index 0000000..2621e12
--- /dev/null
+++ b/tap/tests/todo/test.pl
@@ -0,0 +1,41 @@
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6use Test::More;
7
8my $rc = 0;
9
10$rc = plan tests => 5;
11diag("Returned: " . sprintf("%d", $rc));
12
13my $side_effect = 0; # Check whether TODO has side effects
14
15$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
16diag("Returned: $rc");
17
18# Start TODO tests
19TODO: {
20 local $TODO = 'For testing purposes';
21
22 $side_effect++;
23
24 # This test should fail
25 $rc = ok($side_effect == 0, 'side_effect checked out');
26 diag("Returned: $rc");
27
28 # This test should unexpectedly succeed
29 $rc = ok($side_effect == 1, 'side_effect checked out');
30 diag("Returned: $rc");
31}
32
33TODO: {
34 local $TODO = 'Testing printf() expansion in todo_start()';
35
36 $rc = ok(0, 'dummy test');
37 diag("Returned: $rc");
38}
39
40$rc = ok($side_effect == 1, "side_effect is $side_effect");
41diag("Returned: $rc");
diff --git a/tap/tests/todo/test.t b/tap/tests/todo/test.t
new file mode 100644
index 0000000..7dbb17b
--- /dev/null
+++ b/tap/tests/todo/test.t
@@ -0,0 +1,29 @@
1#!/bin/sh
2
3cd `dirname $0`
4
5echo '1..2'
6
7make 2>&1 > /dev/null
8
9perl ./test.pl 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.pl.out
10perlstatus=$?
11
12./test 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.c.out
13cstatus=$?
14
15diff -u test.pl.out test.c.out
16
17if [ $? -eq 0 ]; then
18 echo 'ok 1 - output is identical'
19else
20 echo 'not ok 1 - output is identical'
21fi
22
23if [ $perlstatus -eq $cstatus ]; then
24 echo 'ok 2 - status code'
25else
26 echo 'not ok 2 - status code'
27 echo "# perlstatus = $perlstatus"
28 echo "# cstatus = $cstatus"
29fi