aboutsummaryrefslogtreecommitdiff
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 00000000..86147c5c
--- /dev/null
+++ b/tap/Makefile.am
@@ -0,0 +1,13 @@
+# Tap self-tests are not implemented (yet?)
+# SUBDIRS = tests
+
+if USE_LIBTAP_LOCAL
+noinst_LTLIBRARIES = libtap.la
+libtap_la_SOURCES = tap.c tap.h
+include_HEADERS = tap.h
+endif USE_LIBTAP_LOCAL
+
+# see top comment
+#prove:
+# prove -v -r
+
diff --git a/tap/README b/tap/README
new file mode 100644
index 00000000..6c15be0a
--- /dev/null
+++ b/tap/README
@@ -0,0 +1,11 @@
+NAME
+ tap -- write tests that implement the Test Anything Protocol
+
+SYNOPSIS
+ #include <tap.h>
+
+DESCRIPTION
+ The tap library provides functions for writing test scripts that produce
+ output consistent with the Test Anything Protocol. A test harness that
+ parses this protocol can run these tests and produce useful reports indi-
+ cating their success or failure.
diff --git a/tap/tap.3 b/tap/tap.3
new file mode 100644
index 00000000..4b23c24a
--- /dev/null
+++ b/tap/tap.3
@@ -0,0 +1,368 @@
+.Dd December 20, 2004
+.Os
+.Dt TAP 3
+.Sh NAME
+.Nm tap
+.Nd write tests that implement the Test Anything Protocol
+.Sh SYNOPSIS
+.In tap.h
+.Sh DESCRIPTION
+The
+.Nm
+library provides functions for writing test scripts that produce output
+consistent with the Test Anything Protocol. A test harness that parses
+this protocol can run these tests and produce useful reports indicating
+their success or failure.
+.Ss PRINTF STRINGS
+In the descriptions that follow, for any function that takes as the
+last two parameters
+.Dq Fa char * , Fa ...
+it can be assumed that the
+.Fa char *
+is a
+.Fn printf
+-like format string, and the optional arguments are values to be placed
+in that string.
+.Ss TEST PLANS
+.Bl -tag -width indent
+.It Xo
+.Ft int
+.Fn plan_tests "unsigned int"
+.Xc
+.It Xo
+.Ft int
+.Fn plan_no_plan "void"
+.Xc
+.It Xo
+.Ft int
+.Fn plan_skip_all "char *" "..."
+.Xc
+.El
+.Pp
+You must first specify a test plan. This indicates how many tests you
+intend to run, and allows the test harness to notice if any tests were
+missed, or if the test program exited prematurely.
+.Pp
+To do this, use
+.Fn plan_tests ,
+which always returns 0. The function will cause your program to exit
+prematurely if you specify 0 tests.
+.Pp
+In some situations you may not know how many tests you will be running, or
+you are developing your test program, and do not want to update the
+.Fn plan_tests
+parameter every time you make a change. For those situations use
+.Fn plan_no_plan .
+It returns 0, and indicates to the test harness that an indeterminate number
+of tests will be run.
+.Pp
+Both
+.Fn plan_tests
+and
+.Fn plan_no_plan
+will cause your test program to exit prematurely with a diagnostic
+message if they are called more than once.
+.Pp
+If your test program detects at run time that some required functionality
+is missing (for example, it relies on a database connection which is not
+present, or a particular configuration option that has not been included
+in the running kernel) use
+.Fn plan_skip_all ,
+passing as parameters a string to display indicating the reason for skipping
+the tests.
+.Ss SIMPLE TESTS
+.Bl -tag -width indent
+.It Xo
+.Ft unsigned int
+.Fn ok "expression" "char *" "..."
+.Xc
+.It Xo
+.Ft unsigned int
+.Fn ok1 "expression"
+.Xc
+.It Xo
+.Ft unsigned int
+.Fn pass "char *" "..."
+.Xc
+.It Xo
+.Ft unsigned int
+.Fn fail "char *" "..."
+.Xc
+.El
+.Pp
+Tests are implemented as expressions checked by calls to the
+.Fn ok
+and
+.Fn ok1
+macros. In both cases
+.Fa expression
+should evaluate to true if the test succeeded.
+.Pp
+.Fn ok
+allows you to specify a name, or comment, describing the test which will
+be included in the output.
+.Fn ok1
+is for those times when the expression to be tested is self
+explanatory and does not need an associated comment. In those cases
+the test expression becomes the comment.
+.Pp
+These four calls are equivalent:
+.Bd -literal -offset indent
+int i = 5;
+
+ok(i == 5, "i equals 5"); /* Overly verbose */
+ok(i == 5, "i equals %d", i); /* Just to demonstrate printf-like
+ behaviour of the test name */
+ok(i == 5, "i == 5"); /* Needless repetition */
+ok1(i == 5); /* Just right */
+.Ed
+.Pp
+It is good practice to ensure that the test name describes the meaning
+behind the test rather than what you are testing. Viz
+.Bd -literal -offset indent
+ok(db != NULL, "db is not NULL"); /* Not bad, but */
+ok(db != NULL, "Database conn. succeeded"); /* this is better */
+.Ed
+.Pp
+.Fn ok
+and
+.Fn ok1
+return 1 if the expression evaluated to true, and 0 if it evaluated to
+false. This lets you chain calls from
+.Fn ok
+to
+.Fn diag
+to only produce diagnostic output if the test failed. For example, this
+code will include diagnostic information about why the database connection
+failed, but only if the test failed.
+.Bd -literal -offset indent
+ok(db != NULL, "Database conn. succeeded") ||
+ diag("Database error code: %d", dberrno);
+.Ed
+.Pp
+You also have
+.Fn pass
+and
+.Fn fail .
+From the Test::More documentation:
+.Bd -literal -offset indent
+Sometimes you just want to say that the tests have passed.
+Usually the case is you've got some complicated condition
+that is difficult to wedge into an ok(). In this case,
+you can simply use pass() (to declare the test ok) or fail
+(for not ok).
+
+Use these very, very, very sparingly.
+.Ed
+.Pp
+These are synonyms for ok(1, ...) and ok(0, ...).
+.Ss SKIPPING TESTS
+.Bl -tag -width indent
+.It Xo
+.Ft int
+.Fn skip "unsigned int" "char *" "..."
+.Xc
+.It Xo
+.Fn skip_start "expression" "unsigned int" "char *" "..."
+.Xc
+.It Xo
+.Sy skip_end
+.Xc
+.El
+.Pp
+Sets of tests can be skipped. Ordinarily you would do this because
+the test can't be run in this particular testing environment.
+.Pp
+For example, suppose some tests should be run as root. If the test is
+not being run as root then the tests should be skipped. In this
+implementation, skipped tests are flagged as being ok, with a special
+message indicating that they were skipped. It is your responsibility
+to ensure that the number of tests skipped (the first parameter to
+.Fn skip )
+is correct for the number of tests to skip.
+.Pp
+One way of implementing this is with a
+.Dq do { } while(0);
+loop, or an
+.Dq if( ) { } else { }
+construct, to ensure that there are no additional side effects from the
+skipped tests.
+.Bd -literal -offset indent
+if(getuid() != 0) {
+ skip(1, "because test only works as root");
+} else {
+ ok(do_something_as_root() == 0, "Did something as root");
+}
+.Ed
+.Pp
+Two macros are provided to assist with this. The previous example could
+be re-written as follows.
+.Bd -literal -offset indent
+skip_start(getuid() != 0, 1, "because test only works as root");
+
+ok(do_something_as_root() == 0, "Did something as root");
+
+skip_end; /* It's a macro, no parentheses */
+.Ed
+.Ss MARKING TESTS AS Dq TODO
+.Bl -tag -width indent
+.It Xo
+.Ft void
+.Fn todo_start "char *" "..."
+.Xc
+.It Xo
+.Ft void
+.Fn todo_end "void"
+.Xc
+.El
+.Pp
+Sets of tests can be flagged as being
+.Dq TODO .
+These are tests that you expect to fail, probably because you haven't
+fixed a bug, or finished a new feature yet. These tests will still be
+run, but with additional output that indicates that they are expected
+to fail. Should a test start to succeed unexpectedly, tools like
+.Xr prove 1
+will indicate this, and you can move the test out of the todo
+block. This is much more useful than simply commenting out (or
+.Dq #ifdef 0 ... #endif )
+the tests.
+.Bd -literal -offset indent
+todo_start("dwim() not returning true yet");
+
+ok(dwim(), "Did what the user wanted");
+
+todo_end();
+.Ed
+.Pp
+Should
+.Fn dwim
+ever start succeeding you will know about it as soon as you run the
+tests. Note that
+.Em unlike
+the
+.Fn skip_*
+family, additional code between
+.Fn todo_start
+and
+.Fn todo_end
+.Em is
+executed.
+.Ss SKIP vs. TODO
+From the Test::More documentation;
+.Bd -literal -offset indent
+If it's something the user might not be able to do, use SKIP.
+This includes optional modules that aren't installed, running
+under an OS that doesn't have some feature (like fork() or
+symlinks), or maybe you need an Internet connection and one
+isn't available.
+
+If it's something the programmer hasn't done yet, use TODO.
+This is for any code you haven't written yet, or bugs you have
+yet to fix, but want to put tests in your testing script
+(always a good idea).
+.Ed
+.Ss DIAGNOSTIC OUTPUT
+.Bl -tag -width indent
+.It Xo
+.Fr unsigned int
+.Fn diag "char *" "..."
+.Xc
+.El
+.Pp
+If your tests need to produce diagnostic output, use
+.Fn diag .
+It ensures that the output will not be considered by the TAP test harness.
+.Fn diag
+adds the necessary trailing
+.Dq \en
+for you.
+.Bd -literal -offset indent
+diag("Expected return code 0, got return code %d", rcode);
+.Ed
+.Pp
+.Fn diag
+always returns 0.
+.Ss EXIT STATUS
+.Bl -tag -width indent
+.It Xo
+.Fr int
+.Fn exit_status void
+.Xc
+.El
+.Pp
+For maximum compatability your test program should return a particular
+exit code. This is calculated by
+.Fn exit_status
+so it is sufficient to always return from
+.Fn main
+with either
+.Dq return exit_status();
+or
+.Dq exit(exit_status());
+as appropriate.
+.Sh EXAMPLES
+The
+.Pa tests
+directory in the source distribution contains numerous tests of
+.Nm
+functionality, written using
+.Nm .
+Examine them for examples of how to construct test suites.
+.Sh COMPATABILITY
+.Nm
+strives to be compatible with the Perl Test::More and Test::Harness
+modules. The test suite verifies that
+.Nm
+is bug-for-bug compatible with their behaviour. This is why some
+functions which would more naturally return nothing return constant
+values.
+.Pp
+If the
+.Lb libpthread
+is found at compile time,
+.Nm
+.Em should
+be thread safe. Indications to the contrary (and test cases that expose
+incorrect behaviour) are very welcome.
+.Sh SEE ALSO
+.Xr Test::More 1 ,
+.Xr Test::Harness 1 ,
+.Xr prove 1
+.Sh STANDARDS
+.Nm
+requires a
+.St -isoC-99
+compiler. Some of the
+.Nm
+functionality is implemented as variadic macros, and that functionality
+was not formally codified until C99. Patches to use
+.Nm
+with earlier compilers that have their own implementation of variadic
+macros will be gratefully received.
+.Sh HISTORY
+.Nm
+was written to help improve the quality and coverage of the FreeBSD
+regression test suite, and released in the hope that others find it
+a useful tool to help improve the quality of their code.
+.Sh AUTHORS
+.An "Nik Clayton" Aq nik@ngo.org.uk ,
+.Aq nik@FreeBSD.org
+.Pp
+.Nm
+would not exist without the efforts of
+.An "Michael G Schwern" Aq schqern@pobox.com ,
+.An "Andy Lester" Aq andy@petdance.com ,
+and the countless others who have worked on the Perl QA programme.
+.Sh BUGS
+Ideally, running the tests would have no side effects on the behaviour
+of the application you are testing. However, it is not always possible
+to avoid them. The following side effects of using
+.Nm
+are known.
+.Bl -bullet -offset indent
+.It
+stdout is set to unbuffered mode after calling any of the
+.Fn plan_*
+functions.
+.El
diff --git a/tap/tap.c b/tap/tap.c
new file mode 100644
index 00000000..97c20e96
--- /dev/null
+++ b/tap/tap.c
@@ -0,0 +1,435 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tap.h"
+
+static int no_plan = 0;
+static int skip_all = 0;
+static int have_plan = 0;
+static unsigned int test_count = 0; /* Number of tests that have been run */
+static unsigned int e_tests = 0; /* Expected number of tests to run */
+static unsigned int failures = 0; /* Number of tests that failed */
+static char *todo_msg = NULL;
+static char *todo_msg_fixed = "libtap malloc issue";
+static int todo = 0;
+static int test_died = 0;
+
+/* Encapsulate the pthread code in a conditional. In the absence of
+ libpthread the code does nothing */
+#ifdef HAVE_LIBPTHREAD
+#include <pthread.h>
+static pthread_mutex_t M = PTHREAD_MUTEX_INITIALIZER;
+# define LOCK pthread_mutex_lock(&M);
+# define UNLOCK pthread_mutex_unlock(&M);
+#else
+# define LOCK
+# define UNLOCK
+#endif
+
+static void _expected_tests(unsigned int);
+static void _tap_init(void);
+static void _cleanup(void);
+
+/*
+ * Generate a test result.
+ *
+ * ok -- boolean, indicates whether or not the test passed.
+ * test_name -- the name of the test, may be NULL
+ * test_comment -- a comment to print afterwards, may be NULL
+ */
+unsigned int
+_gen_result(int ok, const char *func, char *file, unsigned int line,
+ char *test_name, ...)
+{
+ va_list ap;
+ char *local_test_name = NULL;
+ char *c;
+ int name_is_digits;
+
+ LOCK;
+
+ test_count++;
+
+ /* Start by taking the test name and performing any printf()
+ expansions on it */
+ if(test_name != NULL) {
+ va_start(ap, test_name);
+ vasprintf(&local_test_name, test_name, ap);
+ va_end(ap);
+
+ /* Make sure the test name contains more than digits
+ and spaces. Emit an error message and exit if it
+ does */
+ if(local_test_name) {
+ name_is_digits = 1;
+ for(c = local_test_name; *c != '\0'; c++) {
+ if(!isdigit(*c) && !isspace(*c)) {
+ name_is_digits = 0;
+ break;
+ }
+ }
+
+ if(name_is_digits) {
+ diag(" You named your test '%s'. You shouldn't use numbers for your test names.", local_test_name);
+ diag(" Very confusing.");
+ }
+ }
+ }
+
+ if(!ok) {
+ printf("not ");
+ failures++;
+ }
+
+ printf("ok %d", test_count);
+
+ if(test_name != NULL) {
+ printf(" - ");
+
+ /* Print the test name, escaping any '#' characters it
+ might contain */
+ if(local_test_name != NULL) {
+ flockfile(stdout);
+ for(c = local_test_name; *c != '\0'; c++) {
+ if(*c == '#')
+ fputc('\\', stdout);
+ fputc((int)*c, stdout);
+ }
+ funlockfile(stdout);
+ } else { /* vasprintf() failed, use a fixed message */
+ printf("%s", todo_msg_fixed);
+ }
+ }
+
+ /* If we're in a todo_start() block then flag the test as being
+ TODO. todo_msg should contain the message to print at this
+ point. If it's NULL then asprintf() failed, and we should
+ use the fixed message.
+
+ This is not counted as a failure, so decrement the counter if
+ the test failed. */
+ if(todo) {
+ printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
+ if(!ok)
+ failures--;
+ }
+
+ printf("\n");
+
+ if(!ok)
+ diag(" Failed %stest (%s:%s() at line %d)",
+ todo ? "(TODO) " : "", file, func, line);
+
+ free(local_test_name);
+
+ UNLOCK;
+
+ /* We only care (when testing) that ok is positive, but here we
+ specifically only want to return 1 or 0 */
+ return ok ? 1 : 0;
+}
+
+/*
+ * Initialise the TAP library. Will only do so once, however many times it's
+ * called.
+ */
+void
+_tap_init(void)
+{
+ static int run_once = 0;
+
+ LOCK;
+
+ if(!run_once) {
+ atexit(_cleanup);
+
+ /* stdout needs to be unbuffered so that the output appears
+ in the same place relative to stderr output as it does
+ with Test::Harness */
+ setbuf(stdout, 0);
+ run_once = 1;
+ }
+
+ UNLOCK;
+}
+
+/*
+ * Note that there's no plan.
+ */
+int
+plan_no_plan(void)
+{
+
+ LOCK;
+
+ _tap_init();
+
+ if(have_plan != 0) {
+ fprintf(stderr, "You tried to plan twice!\n");
+ test_died = 1;
+ UNLOCK;
+ exit(255);
+ }
+
+ have_plan = 1;
+ no_plan = 1;
+
+ UNLOCK;
+
+ return 0;
+}
+
+/*
+ * Note that the plan is to skip all tests
+ */
+int
+plan_skip_all(char *reason)
+{
+
+ LOCK;
+
+ _tap_init();
+
+ skip_all = 1;
+
+ printf("1..0");
+
+ if(reason != NULL)
+ printf(" # Skip %s", reason);
+
+ printf("\n");
+
+ UNLOCK;
+
+ exit(0);
+}
+
+/*
+ * Note the number of tests that will be run.
+ */
+int
+plan_tests(unsigned int tests)
+{
+
+ LOCK;
+
+ _tap_init();
+
+ if(have_plan != 0) {
+ fprintf(stderr, "You tried to plan twice!\n");
+ test_died = 1;
+ UNLOCK;
+ exit(255);
+ }
+
+ if(tests == 0) {
+ fprintf(stderr, "You said to run 0 tests! You've got to run something.\n");
+ test_died = 1;
+ UNLOCK;
+ exit(255);
+ }
+
+ have_plan = 1;
+
+ _expected_tests(tests);
+
+ UNLOCK;
+
+ return 0;
+}
+
+unsigned int
+diag(char *fmt, ...)
+{
+ va_list ap;
+
+ LOCK;
+
+ fputs("# ", stderr);
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ fputs("\n", stderr);
+
+ UNLOCK;
+
+ return 0;
+}
+
+void
+_expected_tests(unsigned int tests)
+{
+
+ LOCK;
+
+ printf("1..%d\n", tests);
+ e_tests = tests;
+
+ UNLOCK;
+}
+
+int
+skip(unsigned int n, char *fmt, ...)
+{
+ va_list ap;
+ char *skip_msg;
+
+ LOCK;
+
+ va_start(ap, fmt);
+ asprintf(&skip_msg, fmt, ap);
+ va_end(ap);
+
+ while(n-- > 0) {
+ test_count++;
+ printf("ok %d # skip %s\n", test_count,
+ skip_msg != NULL ?
+ skip_msg : "libtap():malloc() failed");
+ }
+
+ free(skip_msg);
+
+ UNLOCK;
+
+ return 1;
+}
+
+void
+todo_start(char *fmt, ...)
+{
+ va_list ap;
+
+ LOCK;
+
+ va_start(ap, fmt);
+ vasprintf(&todo_msg, fmt, ap);
+ va_end(ap);
+
+ todo = 1;
+
+ UNLOCK;
+}
+
+void
+todo_end(void)
+{
+
+ LOCK;
+
+ todo = 0;
+ free(todo_msg);
+
+ UNLOCK;
+}
+
+int
+exit_status(void)
+{
+ int r;
+
+ LOCK;
+
+ /* If there's no plan, just return the number of failures */
+ if(no_plan || !have_plan) {
+ UNLOCK;
+ return failures;
+ }
+
+ /* Ran too many tests? Return the number of tests that were run
+ that shouldn't have been */
+ if(e_tests < test_count) {
+ r = test_count - e_tests;
+ UNLOCK;
+ return r;
+ }
+
+ /* Return the number of tests that failed + the number of tests
+ that weren't run */
+ r = failures + e_tests - test_count;
+ UNLOCK;
+
+ return r;
+}
+
+/*
+ * Cleanup at the end of the run, produce any final output that might be
+ * required.
+ */
+void
+_cleanup(void)
+{
+
+ LOCK;
+
+ /* If plan_no_plan() wasn't called, and we don't have a plan,
+ and we're not skipping everything, then something happened
+ before we could produce any output */
+ if(!no_plan && !have_plan && !skip_all) {
+ diag("Looks like your test died before it could output anything.");
+ UNLOCK;
+ return;
+ }
+
+ if(test_died) {
+ diag("Looks like your test died just after %d.", test_count);
+ UNLOCK;
+ return;
+ }
+
+
+ /* No plan provided, but now we know how many tests were run, and can
+ print the header at the end */
+ if(!skip_all && (no_plan || !have_plan)) {
+ printf("1..%d\n", test_count);
+ }
+
+ if((have_plan && !no_plan) && e_tests < test_count) {
+ diag("Looks like you planned %d tests but ran %d extra.",
+ e_tests, test_count - e_tests);
+ UNLOCK;
+ return;
+ }
+
+ if((have_plan || !no_plan) && e_tests > test_count) {
+ diag("Looks like you planned %d tests but only ran %d.",
+ e_tests, test_count);
+ UNLOCK;
+ return;
+ }
+
+ if(failures)
+ diag("Looks like you failed %d tests of %d.",
+ failures, test_count);
+
+ UNLOCK;
+}
diff --git a/tap/tap.h b/tap/tap.h
new file mode 100644
index 00000000..e64f9d5f
--- /dev/null
+++ b/tap/tap.h
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* '## __VA_ARGS__' is a gcc'ism. C99 doesn't allow the token pasting
+ and requires the caller to add the final comma if they've ommitted
+ the optional arguments */
+#ifdef __GNUC__
+# define ok(e, test, ...) ((e) ? \
+ _gen_result(1, __func__, __FILE__, __LINE__, \
+ test, ## __VA_ARGS__) : \
+ _gen_result(0, __func__, __FILE__, __LINE__, \
+ test, ## __VA_ARGS__))
+
+# define ok1(e) ((e) ? \
+ _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
+ _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
+
+# define pass(test, ...) ok(1, test, ## __VA_ARGS__);
+# define fail(test, ...) ok(0, test, ## __VA_ARGS__);
+
+# define skip_start(test, n, fmt, ...) \
+ do { \
+ if((test)) { \
+ skip(n, fmt, ## __VA_ARGS__); \
+ continue; \
+ }
+#elif __STDC_VERSION__ >= 199901L /* __GNUC__ */
+# define ok(e, ...) ((e) ? \
+ _gen_result(1, __func__, __FILE__, __LINE__, \
+ __VA_ARGS__) : \
+ _gen_result(0, __func__, __FILE__, __LINE__, \
+ __VA_ARGS__))
+
+# define ok1(e) ((e) ? \
+ _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
+ _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
+
+# define pass(...) ok(1, __VA_ARGS__);
+# define fail(...) ok(0, __VA_ARGS__);
+
+# define skip_start(test, n, ...) \
+ do { \
+ if((test)) { \
+ skip(n, __VA_ARGS__); \
+ continue; \
+ }
+#else /* __STDC_VERSION__ */
+# error "Needs gcc or C99 compiler for variadic macros."
+#endif /* __STDC_VERSION__ */
+
+# define skip_end } while(0);
+
+unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...);
+
+int plan_no_plan(void);
+int plan_skip_all(char *);
+int plan_tests(unsigned int);
+
+unsigned int diag(char *, ...);
+
+int skip(unsigned int, char *, ...);
+
+void todo_start(char *, ...);
+void todo_end(void);
+
+int exit_status(void);
diff --git a/tap/tests/Makefile.am b/tap/tests/Makefile.am
new file mode 100644
index 00000000..481a9672
--- /dev/null
+++ b/tap/tests/Makefile.am
@@ -0,0 +1,7 @@
+SUBDIRS= diag
+SUBDIRS+= fail
+SUBDIRS+= ok
+SUBDIRS+= pass
+SUBDIRS+= plan
+SUBDIRS+= skip
+SUBDIRS+= todo
diff --git a/tap/tests/README b/tap/tests/README
new file mode 100644
index 00000000..a15fec28
--- /dev/null
+++ b/tap/tests/README
@@ -0,0 +1,12 @@
+Most of the tests follow the same pattern.
+
+ * test.pl that uses Test::More, and demonstrates whatever functionality
+ that we're trying to test. This is the reference code.
+
+ * test.c, which tests the libtap reimplementation of the same functionality.
+
+ * test.t, which compiles the .c program, runs both test scripts, and then
+ diffs their output to make sure it's identical.
+
+ Right now, test.t is identical in every directory. This sucks somewhat.
+ 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 00000000..c1ccb751
--- /dev/null
+++ b/tap/tests/diag/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../src
+test_LDFLAGS = -L../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..401db647
--- /dev/null
+++ b/tap/tests/diag/test.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ plan_tests(2);
+
+ rc = diag("A diagnostic message");
+ diag("Returned: %d", rc);
+
+ /* Make sure the failure is passed through */
+ ok(1, "test 1") || diag("ok() failed, and shouldn't");
+ ok(0, "test 2") || diag("ok() passed, and shouldn't");
+
+ return exit_status();
+}
diff --git a/tap/tests/diag/test.pl b/tap/tests/diag/test.pl
new file mode 100644
index 00000000..621dc27d
--- /dev/null
+++ b/tap/tests/diag/test.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+plan tests => 2;
+
+$rc = diag("A diagnostic message");
+diag("Returned: $rc");
+
+ok(1, 'test 1') or diag "ok() failed, and shouldn't";
+ok(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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/diag/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/fail/Makefile.am b/tap/tests/fail/Makefile.am
new file mode 100644
index 00000000..c1ccb751
--- /dev/null
+++ b/tap/tests/fail/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../src
+test_LDFLAGS = -L../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..621b6c29
--- /dev/null
+++ b/tap/tests/fail/test.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(2);
+ diag("Returned: %d", rc);
+
+ rc = fail("test to fail");
+ diag("Returned: %d", rc);
+
+ rc = fail("test to fail %s", "with extra string");
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/fail/test.pl b/tap/tests/fail/test.pl
new file mode 100644
index 00000000..73de1a7b
--- /dev/null
+++ b/tap/tests/fail/test.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 2;
+diag("Returned: " . sprintf('%d', $rc));
+
+$rc = fail('test to fail');
+diag("Returned: $rc");
+
+$rc = fail('test to fail with extra string');
+diag("Returned: $rc");
diff --git a/tap/tests/fail/test.t b/tap/tests/fail/test.t
new file mode 100644
index 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/fail/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/ok/Makefile.am b/tap/tests/ok/Makefile.am
new file mode 100644
index 00000000..c9497480
--- /dev/null
+++ b/tap/tests/ok/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = ok
+SUBDIRS += ok-hash
+SUBDIRS += 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 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/ok/ok-hash/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..16be137a
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.c
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(4);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "Test with no hash");
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "Test with one # hash");
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "Test with # two # hashes");
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "Test with ## back to back hashes");
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/ok/ok-hash/test.pl b/tap/tests/ok/ok-hash/test.pl
new file mode 100644
index 00000000..306ddca0
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 4;
+diag("Returned: " . sprintf("%d", $rc));
+
+
+$rc = ok(1, 'Test with no hash');
+diag("Returned: $rc");
+
+$rc = ok(1, 'Test with one # hash');
+diag("Returned: $rc");
+
+$rc = ok(1, 'Test with # two # hashes');
+diag("Returned: $rc");
+
+$rc = ok(1, 'Test with ## back to back hashes');
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/ok/ok-hash/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/ok/ok-numeric/Makefile.am b/tap/tests/ok/ok-numeric/Makefile.am
new file mode 100644
index 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..0e33a748
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(3);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "First test");
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "1");
+ diag("Returned: %d", rc);
+
+ rc = ok(1, "Third test");
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/ok/ok-numeric/test.pl b/tap/tests/ok/ok-numeric/test.pl
new file mode 100644
index 00000000..86f165f2
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 3;
+diag("Returned: " . sprintf("%d", $rc));
+
+
+$rc = ok(1, 'First test');
+diag("Returned: $rc");
+
+$rc = ok(1, '1');
+diag("Returned: $rc");
+
+$rc = ok(1, 'Third test');
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/ok/ok-numeric/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/ok/ok/Makefile.am b/tap/tests/ok/ok/Makefile.am
new file mode 100644
index 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/ok/ok/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..ae04f2e4
--- /dev/null
+++ b/tap/tests/ok/ok/test.c
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(5);
+ diag("Returned: %d", rc);
+
+ rc = ok(1 == 1, "1 equals 1");
+ diag("Returned: %d", rc);
+
+ rc = ok(1 == 1, "1 equals %d", 1);
+ diag("Returned: %d", rc);
+
+ rc = ok1(1 == 1);
+ diag("Returned: %d", rc);
+
+ rc = ok(1 == 2, "1 equals 2");
+ diag("Returned: %d", rc);
+
+ rc = ok1(1 == 2);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/ok/ok/test.pl b/tap/tests/ok/ok/test.pl
new file mode 100644
index 00000000..59f41819
--- /dev/null
+++ b/tap/tests/ok/ok/test.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 5;
+diag("Returned: " . sprintf("%d", $rc));
+
+
+$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
+diag("Returned: $rc");
+
+$rc = ok(1 == 1, '1 equals 1'); # Used for %d testing in test.c
+diag("Returned: $rc");
+
+$rc = ok(1 == 1, '1 == 1'); # Test ok1() passes when it should
+diag("Returned: $rc");
+
+$rc = ok(1 == 2, '1 equals 2'); # Test ok() fails when it should
+diag("Returned: $rc");
+
+$rc = ok(1 == 2, '1 == 2'); # Test ok1() fails when it should
+diag("Returned: $rc");
diff --git a/tap/tests/ok/ok/test.t b/tap/tests/ok/ok/test.t
new file mode 100644
index 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/ok/ok/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/pass/Makefile.am b/tap/tests/pass/Makefile.am
new file mode 100644
index 00000000..c1ccb751
--- /dev/null
+++ b/tap/tests/pass/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../src
+test_LDFLAGS = -L../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..39d8a7c1
--- /dev/null
+++ b/tap/tests/pass/test.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(2);
+ diag("Returned: %d", rc);
+
+ rc = pass("test to pass");
+ diag("Returned: %d", rc);
+
+ rc = pass("test to pass %s", "with extra string");
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/pass/test.pl b/tap/tests/pass/test.pl
new file mode 100644
index 00000000..8abc92e7
--- /dev/null
+++ b/tap/tests/pass/test.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 2;
+diag("Returned: " . sprintf('%d', $rc));
+
+$rc = pass('test to pass');
+diag("Returned: $rc");
+
+$rc = pass('test to pass with extra string');
+diag("Returned: $rc");
diff --git a/tap/tests/pass/test.t b/tap/tests/pass/test.t
new file mode 100644
index 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/pass/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/plan/Makefile.am b/tap/tests/plan/Makefile.am
new file mode 100644
index 00000000..0724931a
--- /dev/null
+++ b/tap/tests/plan/Makefile.am
@@ -0,0 +1,7 @@
+SUBDIRS = no-tests
+SUBDIRS += no_plan
+SUBDIRS += not-enough-tests
+SUBDIRS += too-many-plans
+SUBDIRS += too-many-tests
+SUBDIRS += sane
+SUBDIRS += 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 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/no-tests/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..78c5d371
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(0);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/plan/no-tests/test.pl b/tap/tests/plan/no-tests/test.pl
new file mode 100644
index 00000000..93d2b3b8
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 0;
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/no-tests/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/plan/no_plan/Makefile.am b/tap/tests/plan/no_plan/Makefile.am
new file mode 100644
index 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/no_plan/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..5cffbdc2
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_no_plan();
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/plan/no_plan/test.pl b/tap/tests/plan/no_plan/test.pl
new file mode 100644
index 00000000..19e42b57
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+my $rc = 0;
+
+use Test::More;
+
+$rc = plan qw(no_plan);
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/no_plan/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
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 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..a9ec64f2
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(1);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
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 00000000..73787a7c
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 1;
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("Returned: $rc");
+
+$rc = ok(1);
+diag("Returned: $rc");
+
+$rc = ok(1);
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/not-enough-tests/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/plan/sane/Makefile.am b/tap/tests/plan/sane/Makefile.am
new file mode 100644
index 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/sane/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..0843d3af
--- /dev/null
+++ b/tap/tests/plan/sane/test.c
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(1);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/plan/sane/test.pl b/tap/tests/plan/sane/test.pl
new file mode 100644
index 00000000..35c4ef2f
--- /dev/null
+++ b/tap/tests/plan/sane/test.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 1;
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("Returned: $rc");
diff --git a/tap/tests/plan/sane/test.t b/tap/tests/plan/sane/test.t
new file mode 100644
index 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/sane/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/plan/skip_all/Makefile.am b/tap/tests/plan/skip_all/Makefile.am
new file mode 100644
index 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/skip_all/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..31722da9
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.c
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_skip_all("No good reason");
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/plan/skip_all/test.pl b/tap/tests/plan/skip_all/test.pl
new file mode 100644
index 00000000..32555724
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan skip_all => "No good reason";
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/skip_all/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
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 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..b189cb72
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(1);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ rc = plan_tests(1);
+ diag("Returned: %d", rc);
+
+ rc = ok(0, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
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 00000000..893e5fc0
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 1;
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("Returned: $rc");
+
+$rc = plan tests => 1;
+diag("Returned: $rc");
+
+$rc = ok(0);
+diag("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 00000000..cd2acf74
--- /dev/null
+++ b/tap/tests/plan/too-many-plans/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/twice!.*$/twice!/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/twice!.*$/twice!/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
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 00000000..91d880e7
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../../src
+test_LDFLAGS = -L../../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..0f724104
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+
+ rc = plan_tests(5);
+ diag("Returned: %d", rc);
+
+ rc = ok(1, NULL);
+ diag("Returned: %d", rc);
+
+ rc = ok(0, NULL);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
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 00000000..0a1666ba
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 5;
+diag("Returned: " . sprintf("%d", $rc));
+
+$rc = ok(1);
+diag("Returned: $rc");
+
+$rc = ok(0);
+diag("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 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/plan/too-many-tests/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/skip/Makefile.am b/tap/tests/skip/Makefile.am
new file mode 100644
index 00000000..c1ccb751
--- /dev/null
+++ b/tap/tests/skip/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../src
+test_LDFLAGS = -L../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..d8f3eafd
--- /dev/null
+++ b/tap/tests/skip/test.c
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+ unsigned int side_effect = 0;
+
+ rc = plan_tests(4);
+ diag("Returned: %d", rc);
+
+ rc = ok(1 == 1, "1 equals 1"); /* Should always work */
+ diag("Returned: %d", rc);
+
+ do {
+ if(1) {
+ rc = skip(1, "Testing skipping");
+ continue;
+ }
+
+ side_effect++;
+
+ ok(side_effect == 1, "side_effect checked out");
+
+ } while(0);
+
+ diag("Returned: %d", rc);
+
+ skip_start(1 == 1, 1, "Testing skipping #2");
+
+ side_effect++;
+ rc = ok(side_effect == 1, "side_effect checked out");
+ diag("Returned: %d", rc);
+
+ skip_end;
+
+ rc = ok(side_effect == 0, "side_effect is %d", side_effect);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/skip/test.pl b/tap/tests/skip/test.pl
new file mode 100644
index 00000000..dc294717
--- /dev/null
+++ b/tap/tests/skip/test.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 4;
+diag("Returned: " . sprintf("%d", $rc));
+
+my $side_effect = 0; # Check whether skipping has side effects
+
+$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
+diag("Returned: $rc");
+
+# Start skipping
+SKIP: {
+ $rc = skip "Testing skipping", 1;
+
+ $side_effect++;
+
+ $rc = ok($side_effect == 1, '$side_effect checked out');
+}
+
+diag("Returned: $rc");
+
+SKIP: {
+ $rc = skip "Testing skipping #2", 1;
+ diag("Returned: $rc");
+
+ $side_effect++;
+
+ $rc = ok($side_effect == 1, '$side_effect checked out');
+ diag("Returned: $rc");
+}
+
+$rc = ok($side_effect == 0, "side_effect is $side_effect");
+diag("Returned: $rc");
diff --git a/tap/tests/skip/test.t b/tap/tests/skip/test.t
new file mode 100644
index 00000000..bf0fe8f1
--- /dev/null
+++ b/tap/tests/skip/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi
diff --git a/tap/tests/todo/Makefile.am b/tap/tests/todo/Makefile.am
new file mode 100644
index 00000000..c1ccb751
--- /dev/null
+++ b/tap/tests/todo/Makefile.am
@@ -0,0 +1,13 @@
+
+TESTS = test.t
+TESTS_ENVIRONMENT = $(SHELL)
+
+EXTRA_DIST = $(TESTS) test.pl
+
+check_PROGRAMS = test
+
+test_CFLAGS = -g -I../../src
+test_LDFLAGS = -L../../src
+test_LDADD = -ltap
+
+CLEANFILES = 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 00000000..ac6339a7
--- /dev/null
+++ b/tap/tests/todo/test.c
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 2004 Nik Clayton
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "tap.h"
+
+int
+main(int argc, char *argv[])
+{
+ unsigned int rc = 0;
+ unsigned int side_effect = 0;
+
+ rc = plan_tests(5);
+ diag("Returned: %d", rc);
+
+ rc = ok(1 == 1, "1 equals 1"); /* Should always work */
+ diag("Returned: %d", rc);
+
+ todo_start("For testing purposes");
+
+ side_effect++;
+
+ /* This test should fail */
+ rc = ok(side_effect == 0, "side_effect checked out");
+ diag("Returned: %d", rc);
+
+ /* This test should unexpectedly succeed */
+ rc = ok(side_effect == 1, "side_effect checked out");
+ diag("Returned: %d", rc);
+
+ todo_end();
+
+ todo_start("Testing printf() %s in todo_start()", "expansion");
+
+ rc = ok(0, "dummy test");
+ diag("Returned: %d", rc);
+
+ todo_end();
+
+ rc = ok(side_effect == 1, "side_effect is %d", side_effect);
+ diag("Returned: %d", rc);
+
+ return exit_status();
+}
diff --git a/tap/tests/todo/test.pl b/tap/tests/todo/test.pl
new file mode 100644
index 00000000..2621e12f
--- /dev/null
+++ b/tap/tests/todo/test.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More;
+
+my $rc = 0;
+
+$rc = plan tests => 5;
+diag("Returned: " . sprintf("%d", $rc));
+
+my $side_effect = 0; # Check whether TODO has side effects
+
+$rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should
+diag("Returned: $rc");
+
+# Start TODO tests
+TODO: {
+ local $TODO = 'For testing purposes';
+
+ $side_effect++;
+
+ # This test should fail
+ $rc = ok($side_effect == 0, 'side_effect checked out');
+ diag("Returned: $rc");
+
+ # This test should unexpectedly succeed
+ $rc = ok($side_effect == 1, 'side_effect checked out');
+ diag("Returned: $rc");
+}
+
+TODO: {
+ local $TODO = 'Testing printf() expansion in todo_start()';
+
+ $rc = ok(0, 'dummy test');
+ diag("Returned: $rc");
+}
+
+$rc = ok($side_effect == 1, "side_effect is $side_effect");
+diag("Returned: $rc");
diff --git a/tap/tests/todo/test.t b/tap/tests/todo/test.t
new file mode 100644
index 00000000..7dbb17b6
--- /dev/null
+++ b/tap/tests/todo/test.t
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+cd `dirname $0`
+
+echo '1..2'
+
+make 2>&1 > /dev/null
+
+perl ./test.pl 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.pl.out
+perlstatus=$?
+
+./test 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.c.out
+cstatus=$?
+
+diff -u test.pl.out test.c.out
+
+if [ $? -eq 0 ]; then
+ echo 'ok 1 - output is identical'
+else
+ echo 'not ok 1 - output is identical'
+fi
+
+if [ $perlstatus -eq $cstatus ]; then
+ echo 'ok 2 - status code'
+else
+ echo 'not ok 2 - status code'
+ echo "# perlstatus = $perlstatus"
+ echo "# cstatus = $cstatus"
+fi