diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2008-11-28 05:01:53 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2008-11-29 04:38:54 -0500 |
commit | 2bbf2e6967daa0a9f86874aac409fde245a3bc85 (patch) | |
tree | 7fc7a9e96f3bc0e1b6749cbd999c93a292e0d12b | |
parent | 538b97cea63d68efbd9c9c67d9c41278cfd1ebad (diff) | |
download | monitoring-plugins-2bbf2e6967daa0a9f86874aac409fde245a3bc85.tar.gz |
Add Libtap as a bundled library (does not change any behaviour without --enable-libtap)
Detects system library as pre-1.4.13 and does not install the built-in library anymore
Tested on:
- Linux x86_64, with and without local libtap (System libtap installed)
- Linux x86, with and without local libtap (System libtap NOT installed)
- Solaris SPARC, with and without local libtap, with and without system libtap installed
74 files changed, 2743 insertions, 64 deletions
@@ -96,6 +96,14 @@ NP-VERSION-FILE | |||
96 | /intl/ref-del.sin | 96 | /intl/ref-del.sin |
97 | /intl/textdomain.c | 97 | /intl/textdomain.c |
98 | 98 | ||
99 | # /tap/ | ||
100 | /tap/.deps | ||
101 | /tap/.libs | ||
102 | /tap/Makefile | ||
103 | /tap/Makefile.in | ||
104 | /tap/libtap.la | ||
105 | /tap/tap.lo | ||
106 | |||
99 | # /lib/ | 107 | # /lib/ |
100 | /lib/.deps | 108 | /lib/.deps |
101 | /lib/getopt.h | 109 | /lib/getopt.h |
diff --git a/Makefile.am b/Makefile.am index a0bc561e..b6e5f2ec 100644 --- a/Makefile.am +++ b/Makefile.am | |||
@@ -1,6 +1,6 @@ | |||
1 | ## Process this file with automake to produce Makefile.in | 1 | ## Process this file with automake to produce Makefile.in |
2 | 2 | ||
3 | SUBDIRS = gl lib plugins plugins-scripts plugins-root po @PERLMODS_DIR@ | 3 | SUBDIRS = gl tap lib plugins plugins-scripts plugins-root po @PERLMODS_DIR@ |
4 | 4 | ||
5 | EXTRA_DIST = config.rpath \ | 5 | EXTRA_DIST = config.rpath \ |
6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CODING FAQ LEGAL NEWS \ | 6 | ABOUT-NLS ACKNOWLEDGEMENTS AUTHORS BUGS CODING FAQ LEGAL NEWS \ |
@@ -17,6 +17,7 @@ This file documents the major additions and syntax changes between releases. | |||
17 | Fixed bug where additional headers with redirection caused a segfault (Dieter Van de Walle - 2089159) | 17 | Fixed bug where additional headers with redirection caused a segfault (Dieter Van de Walle - 2089159) |
18 | check_disk: make autofs mount paths specified with -p before we determing the mount list (Erik Welch) | 18 | check_disk: make autofs mount paths specified with -p before we determing the mount list (Erik Welch) |
19 | Fixed buffer overflow in check_ntp/check_ntp_peer (#1999319, Ubuntu #291265) | 19 | Fixed buffer overflow in check_ntp/check_ntp_peer (#1999319, Ubuntu #291265) |
20 | Re-bundled libtap as a built-in library (--enable-libtap): detects system library as pre-1.4.13 and does not install the built-in library anymore | ||
20 | 21 | ||
21 | 1.4.13 25th Sept 2008 | 22 | 1.4.13 25th Sept 2008 |
22 | Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen) | 23 | Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen) |
diff --git a/configure.in b/configure.in index 39cd6b71..3ff06366 100644 --- a/configure.in +++ b/configure.in | |||
@@ -118,7 +118,7 @@ AC_SUBST(PERL, $with_perl) | |||
118 | 118 | ||
119 | dnl openssl/gnutls | 119 | dnl openssl/gnutls |
120 | AC_ARG_WITH(openssl, | 120 | AC_ARG_WITH(openssl, |
121 | AC_HELP_STRING([--with-openssl=DIR], | 121 | AC_HELP_STRING([--with-openssl=DIR], |
122 | [path to openssl installation]),) | 122 | [path to openssl installation]),) |
123 | 123 | ||
124 | AC_ARG_WITH(gnutls, | 124 | AC_ARG_WITH(gnutls, |
@@ -156,23 +156,41 @@ AC_CHECK_HEADERS(math.h) | |||
156 | AC_CHECK_LIB(m,floor,MATHLIBS="-lm") | 156 | AC_CHECK_LIB(m,floor,MATHLIBS="-lm") |
157 | AC_SUBST(MATHLIBS) | 157 | AC_SUBST(MATHLIBS) |
158 | 158 | ||
159 | dnl Check for libtap, to run perl-like tests | 159 | dnl Check if we buils local libtap |
160 | AC_CHECK_LIB(tap, plan_tests, | 160 | AC_ARG_ENABLE(libtap, |
161 | AC_HELP_STRING([--enable-libtap], | ||
162 | [Enable built-in libtap for unit-testing (default: autodetect system library).]), | ||
163 | [enable_libtap=$enableval], | ||
164 | [enable_libtap=no]) | ||
165 | AM_CONDITIONAL([USE_LIBTAP_LOCAL],[test "$enable_libtap" = "yes"]) | ||
166 | |||
167 | # If not local, check if we can use the system one | ||
168 | if test "$enable_libtap" != "yes" ; then | ||
169 | dnl Check for libtap, to run perl-like tests | ||
170 | AC_CHECK_LIB(tap, plan_tests, | ||
171 | enable_libtap="yes" | ||
172 | ) | ||
173 | fi | ||
174 | |||
175 | # Finally, define tests if we use libtap | ||
176 | if test "$enable_libtap" = "yes" ; then | ||
161 | EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64" | 177 | EXTRA_TEST="test_utils test_disk test_tcp test_cmd test_base64" |
162 | AC_SUBST(EXTRA_TEST) | 178 | AC_SUBST(EXTRA_TEST) |
163 | ) | 179 | fi |
164 | 180 | ||
165 | dnl INI Parsing | 181 | dnl INI Parsing |
166 | AC_ARG_ENABLE(extra-opts, | 182 | AC_ARG_ENABLE(extra-opts, |
167 | AC_HELP_STRING([--enable-extra-opts], | 183 | AC_HELP_STRING([--enable-extra-opts], |
168 | [Enables parsing of plugins ini config files for extra options (default: no)]), | 184 | [Enables parsing of plugins ini config files for extra options (default: no)]), |
169 | [enable_extra_opts=$enableval], | 185 | [enable_extra_opts=$enableval], |
170 | [enable_extra_opts=no]) | 186 | [enable_extra_opts=no]) |
171 | AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"]) | 187 | AM_CONDITIONAL([USE_PARSE_INI],[test "$enable_extra_opts" = "yes"]) |
172 | if test "$enable_extra_opts" = "yes" ; then | 188 | if test "$enable_extra_opts" = "yes" ; then |
173 | EXTRA_TEST="$EXTRA_TEST test_ini test_opts" | ||
174 | AC_SUBST(EXTRA_TEST) | ||
175 | AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.]) | 189 | AC_DEFINE(NP_EXTRA_OPTS,[1],[Enable INI file parsing.]) |
190 | if test "$enable_libtap" = "yes"; then | ||
191 | EXTRA_TEST="$EXTRA_TEST test_ini test_opts" | ||
192 | AC_SUBST(EXTRA_TEST) | ||
193 | fi | ||
176 | fi | 194 | fi |
177 | 195 | ||
178 | dnl Check for PostgreSQL libraries | 196 | dnl Check for PostgreSQL libraries |
@@ -272,8 +290,8 @@ fi | |||
272 | if test "$FOUNDINCLUDE" = "yes" ; then | 290 | if test "$FOUNDINCLUDE" = "yes" ; then |
273 | EXTRAS="$EXTRAS check_ide_smart" | 291 | EXTRAS="$EXTRAS check_ide_smart" |
274 | else | 292 | else |
275 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) | 293 | AC_MSG_WARN([Skipping check_ide_smart plugin.]) |
276 | AC_MSG_WARN([check_ide_smart is linux specific. It requires linux/hdreg.h and linux/types.h.]) | 294 | AC_MSG_WARN([check_ide_smart is linux specific. It requires linux/hdreg.h and linux/types.h.]) |
277 | fi | 295 | fi |
278 | 296 | ||
279 | dnl Check for mysql libraries | 297 | dnl Check for mysql libraries |
@@ -467,7 +485,7 @@ ac_cv_HAVE_VA_COPY=yes, | |||
467 | ac_cv_HAVE_VA_COPY=no)]) | 485 | ac_cv_HAVE_VA_COPY=no)]) |
468 | if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then | 486 | if test x"$ac_cv_HAVE_VA_COPY" = x"yes"; then |
469 | AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) | 487 | AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) |
470 | else | 488 | else |
471 | AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE___VA_COPY,[ | 489 | AC_CACHE_CHECK([for __va_copy],ac_cv_HAVE___VA_COPY,[ |
472 | AC_TRY_LINK([#include <stdarg.h> | 490 | AC_TRY_LINK([#include <stdarg.h> |
473 | va_list ap1,ap2;], [__va_copy(ap1,ap2);], | 491 | va_list ap1,ap2;], [__va_copy(ap1,ap2);], |
@@ -513,7 +531,7 @@ AC_PATH_PROG(PATH_TO_PS,ps) | |||
513 | 531 | ||
514 | AC_MSG_CHECKING(for ps syntax) | 532 | AC_MSG_CHECKING(for ps syntax) |
515 | AC_ARG_WITH(ps_command, | 533 | AC_ARG_WITH(ps_command, |
516 | ACX_HELP_STRING([--with-ps-command=PATH], | 534 | ACX_HELP_STRING([--with-ps-command=PATH], |
517 | [Verbatim command to execute for ps]), | 535 | [Verbatim command to execute for ps]), |
518 | PS_COMMAND=$withval) | 536 | PS_COMMAND=$withval) |
519 | AC_ARG_WITH(ps_format, | 537 | AC_ARG_WITH(ps_format, |
@@ -521,7 +539,7 @@ AC_ARG_WITH(ps_format, | |||
521 | [Format string for scanning ps output]), | 539 | [Format string for scanning ps output]), |
522 | PS_FORMAT=$withval) | 540 | PS_FORMAT=$withval) |
523 | AC_ARG_WITH(ps_cols, | 541 | AC_ARG_WITH(ps_cols, |
524 | ACX_HELP_STRING([--with-ps-cols=NUM], | 542 | ACX_HELP_STRING([--with-ps-cols=NUM], |
525 | [Number of columns in ps command]), | 543 | [Number of columns in ps command]), |
526 | PS_COLS=$withval) | 544 | PS_COLS=$withval) |
527 | AC_ARG_WITH(ps_varlist, | 545 | AC_ARG_WITH(ps_varlist, |
@@ -529,7 +547,7 @@ AC_ARG_WITH(ps_varlist, | |||
529 | [Variable list for sscanf of 'ps' output]), | 547 | [Variable list for sscanf of 'ps' output]), |
530 | PS_VARLIST=$withval) | 548 | PS_VARLIST=$withval) |
531 | 549 | ||
532 | if test -n "$PS_COMMAND" && test -n "$PS_FORMAT" && test -n "$PS_COLS" && test -n "$PS_VARLIST"; then | 550 | if test -n "$PS_COMMAND" && test -n "$PS_FORMAT" && test -n "$PS_COLS" && test -n "$PS_VARLIST"; then |
533 | ac_cv_ps_command="$PS_COMMAND" | 551 | ac_cv_ps_command="$PS_COMMAND" |
534 | ac_cv_ps_format="$PS_FORMAT" | 552 | ac_cv_ps_format="$PS_FORMAT" |
535 | ac_cv_ps_varlist="$PS_VARLIST" | 553 | ac_cv_ps_varlist="$PS_VARLIST" |
@@ -603,7 +621,7 @@ then | |||
603 | ac_cv_ps_cols=9 | 621 | ac_cv_ps_cols=9 |
604 | AC_MSG_RESULT([$ac_cv_ps_command]) | 622 | AC_MSG_RESULT([$ac_cv_ps_command]) |
605 | 623 | ||
606 | dnl Some *BSDs have different format for ps. This is mainly to catch FreeBSD 4. | 624 | dnl Some *BSDs have different format for ps. This is mainly to catch FreeBSD 4. |
607 | dnl Limitation: Only first 16 chars returned for ucomm field | 625 | dnl Limitation: Only first 16 chars returned for ucomm field |
608 | dnl Must come before ps -weo | 626 | dnl Must come before ps -weo |
609 | elif ps -axwo 'stat uid pid ppid vsz rss pcpu ucomm command' 2>/dev/null | \ | 627 | elif ps -axwo 'stat uid pid ppid vsz rss pcpu ucomm command' 2>/dev/null | \ |
@@ -680,9 +698,9 @@ then | |||
680 | ac_cv_ps_cols=9 | 698 | ac_cv_ps_cols=9 |
681 | AC_MSG_RESULT([$ac_cv_ps_command]) | 699 | AC_MSG_RESULT([$ac_cv_ps_command]) |
682 | 700 | ||
683 | dnl Tru64 - needs %*[ +<>] in PS_FORMAT. | 701 | dnl Tru64 - needs %*[ +<>] in PS_FORMAT. |
684 | dnl Has /usr/bin/ps and /sbin/ps - force sbin version | 702 | dnl Has /usr/bin/ps and /sbin/ps - force sbin version |
685 | dnl Can't use vsize and rssize because comes back with text (eg, 1.5M instead | 703 | dnl Can't use vsize and rssize because comes back with text (eg, 1.5M instead |
686 | dnl of 1500). Will need big changes to check_procs to support | 704 | dnl of 1500). Will need big changes to check_procs to support |
687 | elif /sbin/ps -eo 'stat uid pid ppid pcpu etime comm args' 2>/dev/null | \ | 705 | elif /sbin/ps -eo 'stat uid pid ppid pcpu etime comm args' 2>/dev/null | \ |
688 | egrep -i ["^ *S +[UID]+ +[PID]+ +[PID]+ +[%CPU]+ +[ELAPSD]+ +[COMMAND]+ +[COMMAND]+"] > /dev/null | 706 | egrep -i ["^ *S +[UID]+ +[PID]+ +[PID]+ +[%CPU]+ +[ELAPSD]+ +[COMMAND]+ +[COMMAND]+"] > /dev/null |
@@ -808,7 +826,7 @@ then | |||
808 | ac_cv_ps_cols=8 | 826 | ac_cv_ps_cols=8 |
809 | AC_MSG_RESULT([$ac_cv_ps_command]) | 827 | AC_MSG_RESULT([$ac_cv_ps_command]) |
810 | 828 | ||
811 | dnl UnixWare | 829 | dnl UnixWare |
812 | elif ps -Al 2>/dev/null | \ | 830 | elif ps -Al 2>/dev/null | \ |
813 | egrep -i ["^ *F +S +UID +PID +PPID +CLS +PRI +NI +C +ADDR +SZ +WCHAN +TTY +TIME +COMD"] >/dev/null | 831 | egrep -i ["^ *F +S +UID +PID +PPID +CLS +PRI +NI +C +ADDR +SZ +WCHAN +TTY +TIME +COMD"] >/dev/null |
814 | then | 832 | then |
@@ -1173,7 +1191,7 @@ fi | |||
1173 | AC_PATH_PROG(PATH_TO_SMBCLIENT,smbclient) | 1191 | AC_PATH_PROG(PATH_TO_SMBCLIENT,smbclient) |
1174 | AC_ARG_WITH(smbclient_command, | 1192 | AC_ARG_WITH(smbclient_command, |
1175 | ACX_HELP_STRING([--with-smbclient-command=PATH], | 1193 | ACX_HELP_STRING([--with-smbclient-command=PATH], |
1176 | [sets path to smbclient]), | 1194 | [sets path to smbclient]), |
1177 | PATH_TO_SMBCLIENT=$withval) | 1195 | PATH_TO_SMBCLIENT=$withval) |
1178 | if test -n "$PATH_TO_SMBCLIENT" | 1196 | if test -n "$PATH_TO_SMBCLIENT" |
1179 | then | 1197 | then |
@@ -1229,7 +1247,7 @@ fi | |||
1229 | AC_PATH_PROG(PATH_TO_QUAKESTAT,quakestat) | 1247 | AC_PATH_PROG(PATH_TO_QUAKESTAT,quakestat) |
1230 | AC_PATH_PROG(PATH_TO_QSTAT,qstat) | 1248 | AC_PATH_PROG(PATH_TO_QSTAT,qstat) |
1231 | AC_ARG_WITH(qstat_command, | 1249 | AC_ARG_WITH(qstat_command, |
1232 | ACX_HELP_STRING([--with-qstat-command=PATH], | 1250 | ACX_HELP_STRING([--with-qstat-command=PATH], |
1233 | [Path to qstat command]), PATH_TO_QSTAT=$withval) | 1251 | [Path to qstat command]), PATH_TO_QSTAT=$withval) |
1234 | 1252 | ||
1235 | if test -x "$PATH_TO_QUAKESTAT" | 1253 | if test -x "$PATH_TO_QUAKESTAT" |
@@ -1245,7 +1263,7 @@ else | |||
1245 | AC_MSG_WARN([Get qstat from http://www.activesw.com/people/steve/qstat.html in order to make check_game plugin]) | 1263 | AC_MSG_WARN([Get qstat from http://www.activesw.com/people/steve/qstat.html in order to make check_game plugin]) |
1246 | fi | 1264 | fi |
1247 | 1265 | ||
1248 | if test $ac_cv_path_to_qstat | 1266 | if test $ac_cv_path_to_qstat |
1249 | then | 1267 | then |
1250 | AC_DEFINE_UNQUOTED(PATH_TO_QSTAT,"$ac_cv_path_to_qstat", | 1268 | AC_DEFINE_UNQUOTED(PATH_TO_QSTAT,"$ac_cv_path_to_qstat", |
1251 | [path to qstat/quakestat]) | 1269 | [path to qstat/quakestat]) |
@@ -1404,12 +1422,12 @@ AC_CHECK_MEMBERS([struct swapent.se_nblks],,,[ | |||
1404 | #include <sys/swap.h> | 1422 | #include <sys/swap.h> |
1405 | ]) | 1423 | ]) |
1406 | 1424 | ||
1407 | if test "$ac_cv_have_decl_swapctl" = "yes"; | 1425 | if test "$ac_cv_have_decl_swapctl" = "yes"; |
1408 | then | 1426 | then |
1409 | EXTRAS="$EXTRAS check_swap" | 1427 | EXTRAS="$EXTRAS check_swap" |
1410 | AC_MSG_CHECKING([for 2-arg (SVR4) swapctl]) | 1428 | AC_MSG_CHECKING([for 2-arg (SVR4) swapctl]) |
1411 | if test "$ac_cv_type_swaptbl_t" = "yes" -a \ | 1429 | if test "$ac_cv_type_swaptbl_t" = "yes" -a \ |
1412 | "$ac_cv_type_swapent_t" = "yes"; | 1430 | "$ac_cv_type_swapent_t" = "yes"; |
1413 | then | 1431 | then |
1414 | AC_MSG_RESULT([yes]) | 1432 | AC_MSG_RESULT([yes]) |
1415 | ac_cv_check_swap_swapctl_svr4="1"; | 1433 | ac_cv_check_swap_swapctl_svr4="1"; |
@@ -1418,7 +1436,7 @@ then | |||
1418 | else | 1436 | else |
1419 | AC_MSG_RESULT([no]) | 1437 | AC_MSG_RESULT([no]) |
1420 | AC_MSG_CHECKING([for 3-arg (*BSD) swapctl]) | 1438 | AC_MSG_CHECKING([for 3-arg (*BSD) swapctl]) |
1421 | if test "$ac_cv_member_struct_swapent_se_nblks" = "yes"; | 1439 | if test "$ac_cv_member_struct_swapent_se_nblks" = "yes"; |
1422 | then | 1440 | then |
1423 | AC_MSG_RESULT([yes]) | 1441 | AC_MSG_RESULT([yes]) |
1424 | AC_DEFINE([CHECK_SWAP_SWAPCTL_BSD],1, | 1442 | AC_DEFINE([CHECK_SWAP_SWAPCTL_BSD],1, |
@@ -1459,12 +1477,12 @@ dnl end tests for the swapctl system calls | |||
1459 | dnl | 1477 | dnl |
1460 | 1478 | ||
1461 | 1479 | ||
1462 | if test "x$ac_cv_have_swap" != "x" | 1480 | if test "x$ac_cv_have_swap" != "x" |
1463 | then | 1481 | then |
1464 | AC_DEFINE(HAVE_SWAP,1,[Define if swap/swapinfo command is found]) | 1482 | AC_DEFINE(HAVE_SWAP,1,[Define if swap/swapinfo command is found]) |
1465 | EXTRAS="$EXTRAS check_swap" | 1483 | EXTRAS="$EXTRAS check_swap" |
1466 | fi | 1484 | fi |
1467 | if test "x$ac_cv_swap_command" != "x" | 1485 | if test "x$ac_cv_swap_command" != "x" |
1468 | then | 1486 | then |
1469 | AC_DEFINE_UNQUOTED(SWAP_COMMAND,"$ac_cv_swap_command", | 1487 | AC_DEFINE_UNQUOTED(SWAP_COMMAND,"$ac_cv_swap_command", |
1470 | [Path to swap/swapinfo binary, with any args]) | 1488 | [Path to swap/swapinfo binary, with any args]) |
@@ -1509,7 +1527,7 @@ fi | |||
1509 | AC_PATH_PROG(PATH_TO_APTGET,apt-get) | 1527 | AC_PATH_PROG(PATH_TO_APTGET,apt-get) |
1510 | AC_ARG_WITH(apt-get_command, | 1528 | AC_ARG_WITH(apt-get_command, |
1511 | ACX_HELP_STRING([--with-apt-get-command=PATH], | 1529 | ACX_HELP_STRING([--with-apt-get-command=PATH], |
1512 | [Path to apt-get command]), | 1530 | [Path to apt-get command]), |
1513 | with_apt_get_command=$withval, | 1531 | with_apt_get_command=$withval, |
1514 | with_apt_get_command=$PATH_TO_APTGET) | 1532 | with_apt_get_command=$PATH_TO_APTGET) |
1515 | AC_DEFINE_UNQUOTED(PATH_TO_APTGET,"$PATH_TO_APTGET",[Path to apt-get command, if present]) | 1533 | AC_DEFINE_UNQUOTED(PATH_TO_APTGET,"$PATH_TO_APTGET",[Path to apt-get command, if present]) |
@@ -1538,7 +1556,7 @@ case $host in | |||
1538 | *sun* | *solaris*) | 1556 | *sun* | *solaris*) |
1539 | AC_DEFINE(__sun__,1,[sun specific code in check_dhcp.c]) | 1557 | AC_DEFINE(__sun__,1,[sun specific code in check_dhcp.c]) |
1540 | ;; | 1558 | ;; |
1541 | *hpux*) | 1559 | *hpux*) |
1542 | AC_DEFINE(__hpux__,1,[hpux specific code in check_dhcp.c]) | 1560 | AC_DEFINE(__hpux__,1,[hpux specific code in check_dhcp.c]) |
1543 | ;; | 1561 | ;; |
1544 | esac | 1562 | esac |
@@ -1558,8 +1576,8 @@ dnl 2.6.9-11 (okay in 2.6.9-5). Redhat investigating root cause | |||
1558 | dnl We patch plugins/popen.c | 1576 | dnl We patch plugins/popen.c |
1559 | dnl Need to add smp because uname different on those | 1577 | dnl Need to add smp because uname different on those |
1560 | dnl Can force patch to be applied with --enable-redhat-pthread-workaround | 1578 | dnl Can force patch to be applied with --enable-redhat-pthread-workaround |
1561 | AC_ARG_ENABLE(redhat-pthread-workaround, | 1579 | AC_ARG_ENABLE(redhat-pthread-workaround, |
1562 | AC_HELP_STRING([--enable-redhat-pthread-workaround], | 1580 | AC_HELP_STRING([--enable-redhat-pthread-workaround], |
1563 | [force Redhat patch to be applied (default: test system)]), | 1581 | [force Redhat patch to be applied (default: test system)]), |
1564 | [ac_cv_enable_redhat_pthread_workaround=$enableval], | 1582 | [ac_cv_enable_redhat_pthread_workaround=$enableval], |
1565 | [ac_cv_enable_redhat_pthread_workaround=test]) | 1583 | [ac_cv_enable_redhat_pthread_workaround=test]) |
@@ -1581,7 +1599,7 @@ fi | |||
1581 | 1599 | ||
1582 | dnl Perl modules | 1600 | dnl Perl modules |
1583 | AC_ARG_ENABLE(perl-modules, | 1601 | AC_ARG_ENABLE(perl-modules, |
1584 | AC_HELP_STRING([--enable-perl-modules], | 1602 | AC_HELP_STRING([--enable-perl-modules], |
1585 | [Enables installation of Nagios::Plugin and its dependencies (default: no)]), | 1603 | [Enables installation of Nagios::Plugin and its dependencies (default: no)]), |
1586 | [enable_perl_modules=$enableval], | 1604 | [enable_perl_modules=$enableval], |
1587 | [enable_perl_modules=no]) | 1605 | [enable_perl_modules=no]) |
@@ -1589,6 +1607,18 @@ if test "$enable_perl_modules" = "yes" ; then | |||
1589 | AC_SUBST(PERLMODS_DIR,perlmods) | 1607 | AC_SUBST(PERLMODS_DIR,perlmods) |
1590 | fi | 1608 | fi |
1591 | 1609 | ||
1610 | # From Tap configure | ||
1611 | # Checks for libraries | ||
1612 | case "$host" in | ||
1613 | *-*-*freebsd4*) | ||
1614 | LDFLAGS="$LDFLAGS -pthread" | ||
1615 | HAVE_LIBPTHREAD=1 | ||
1616 | ;; | ||
1617 | *) | ||
1618 | AC_CHECK_LIB(pthread, main) | ||
1619 | ;; | ||
1620 | esac | ||
1621 | |||
1592 | dnl External libraries - see ACKNOWLEDGEMENTS | 1622 | dnl External libraries - see ACKNOWLEDGEMENTS |
1593 | gl_INIT | 1623 | gl_INIT |
1594 | 1624 | ||
@@ -1598,24 +1628,25 @@ if test "$ac_cv_uname_s" = 'SunOS' -a \( "x$ac_cv_prog_ac_ct_AR" = "x" -o "$ac_c | |||
1598 | fi | 1628 | fi |
1599 | 1629 | ||
1600 | AC_OUTPUT( | 1630 | AC_OUTPUT( |
1601 | Makefile | 1631 | Makefile |
1602 | lib/Makefile | 1632 | tap/Makefile |
1603 | plugins/Makefile | 1633 | lib/Makefile |
1634 | plugins/Makefile | ||
1604 | lib/tests/Makefile | 1635 | lib/tests/Makefile |
1605 | plugins-root/Makefile | 1636 | plugins-root/Makefile |
1606 | plugins-scripts/Makefile | 1637 | plugins-scripts/Makefile |
1607 | plugins-scripts/subst | 1638 | plugins-scripts/subst |
1608 | plugins-scripts/utils.pm | 1639 | plugins-scripts/utils.pm |
1609 | plugins-scripts/utils.sh | 1640 | plugins-scripts/utils.sh |
1610 | perlmods/Makefile | 1641 | perlmods/Makefile |
1611 | command.cfg | 1642 | command.cfg |
1612 | test.pl | 1643 | test.pl |
1613 | pkg/solaris/pkginfo | 1644 | pkg/solaris/pkginfo |
1614 | po/Makefile.in | 1645 | po/Makefile.in |
1615 | ) | 1646 | ) |
1616 | 1647 | ||
1617 | 1648 | ||
1618 | dnl the ones below that are commented out need to be cleaned up | 1649 | dnl the ones below that are commented out need to be cleaned up |
1619 | dnl in the configure code above to use with_foo instead of ac_cv_foo | 1650 | dnl in the configure code above to use with_foo instead of ac_cv_foo |
1620 | dnl if we want them to show up here. it'd also make the code cleaner. | 1651 | dnl if we want them to show up here. it'd also make the code cleaner. |
1621 | dnl i'll get to that on another rainy day :) -sf | 1652 | dnl i'll get to that on another rainy day :) -sf |
@@ -1649,5 +1680,5 @@ ACX_FEATURE([with],[perl]) | |||
1649 | ACX_FEATURE([enable],[perl-modules]) | 1680 | ACX_FEATURE([enable],[perl-modules]) |
1650 | ACX_FEATURE([with],[cgiurl]) | 1681 | ACX_FEATURE([with],[cgiurl]) |
1651 | ACX_FEATURE([with],[trusted-path]) | 1682 | ACX_FEATURE([with],[trusted-path]) |
1652 | 1683 | ACX_FEATURE([enable],[libtap]) | |
1653 | 1684 | ||
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am index 25e2bed3..596d00fd 100644 --- a/lib/tests/Makefile.am +++ b/lib/tests/Makefile.am | |||
@@ -15,40 +15,49 @@ EXTRA_DIST = $(np_test_scripts) $(np_test_files) | |||
15 | 15 | ||
16 | LIBS = @LIBINTL@ | 16 | LIBS = @LIBINTL@ |
17 | 17 | ||
18 | if USE_LIBTAP_LOCAL | ||
19 | tap_cflags = -I$(top_srcdir)/tap | ||
20 | tap_ldflags = -L$(top_srcdir)/tap | ||
21 | tap_ldadd = $(top_srcdir)/gl/libgnu.a | ||
22 | else | ||
23 | ## Shouldn't we detect that?? | ||
24 | tap_ldflags = -L/usr/local/lib | ||
25 | endif | ||
26 | |||
18 | test_utils_SOURCES = test_utils.c | 27 | test_utils_SOURCES = test_utils.c |
19 | test_utils_CFLAGS = -g -I.. | 28 | test_utils_CFLAGS = -g -I.. $(tap_cflags) |
20 | test_utils_LDFLAGS = -L/usr/local/lib -ltap | 29 | test_utils_LDFLAGS = $(tap_ldflags) -ltap |
21 | test_utils_LDADD = ../utils_base.o | 30 | test_utils_LDADD = ../utils_base.o $(tap_ldadd) |
22 | 31 | ||
23 | test_disk_SOURCES = test_disk.c | 32 | test_disk_SOURCES = test_disk.c |
24 | test_disk_CFLAGS = -g -I.. | 33 | test_disk_CFLAGS = -g -I.. $(tap_cflags) |
25 | test_disk_LDFLAGS = -L/usr/local/lib -ltap | 34 | test_disk_LDFLAGS = $(tap_ldflags) -ltap |
26 | test_disk_LDADD = ../utils_disk.o $(top_srcdir)/gl/libgnu.a | 35 | test_disk_LDADD = ../utils_disk.o $(top_srcdir)/gl/libgnu.a |
27 | 36 | ||
28 | test_tcp_SOURCES = test_tcp.c | 37 | test_tcp_SOURCES = test_tcp.c |
29 | test_tcp_CFLAGS = -g -I.. | 38 | test_tcp_CFLAGS = -g -I.. $(tap_cflags) |
30 | test_tcp_LDFLAGS = -L/usr/local/lib -ltap | 39 | test_tcp_LDFLAGS = $(tap_ldflags) -ltap |
31 | test_tcp_LDADD = ../utils_tcp.o | 40 | test_tcp_LDADD = ../utils_tcp.o $(tap_ldadd) |
32 | 41 | ||
33 | test_cmd_SOURCES = test_cmd.c | 42 | test_cmd_SOURCES = test_cmd.c |
34 | test_cmd_CFLAGS = -g -I.. | 43 | test_cmd_CFLAGS = -g -I.. $(tap_cflags) |
35 | test_cmd_LDFLAGS = -L/usr/local/lib -ltap | 44 | test_cmd_LDFLAGS = $(tap_ldflags) -ltap |
36 | test_cmd_LDADD = ../utils_cmd.o ../utils_base.o | 45 | test_cmd_LDADD = ../utils_cmd.o ../utils_base.o $(tap_ldadd) |
37 | 46 | ||
38 | test_base64_SOURCES = test_base64.c | 47 | test_base64_SOURCES = test_base64.c |
39 | test_base64_CFLAGS = -g -I.. | 48 | test_base64_CFLAGS = -g -I.. $(tap_cflags) |
40 | test_base64_LDFLAGS = -L/usr/local/lib -ltap | 49 | test_base64_LDFLAGS = $(tap_ldflags) -ltap |
41 | test_base64_LDADD = $(top_srcdir)/gl/base64.o | 50 | test_base64_LDADD = $(top_srcdir)/gl/base64.o $(tap_ldadd) |
42 | 51 | ||
43 | test_ini_SOURCES = test_ini.c | 52 | test_ini_SOURCES = test_ini.c |
44 | test_ini_CFLAGS = -g -I.. | 53 | test_ini_CFLAGS = -g -I.. $(tap_cflags) |
45 | test_ini_LDFLAGS = -L/usr/local/lib -ltap | 54 | test_ini_LDFLAGS = $(tap_ldflags) -ltap |
46 | test_ini_LDADD = ../utils_base.o ../parse_ini.o | 55 | test_ini_LDADD = ../utils_base.o ../parse_ini.o $(tap_ldadd) |
47 | 56 | ||
48 | test_opts_SOURCES = test_opts.c | 57 | test_opts_SOURCES = test_opts.c |
49 | test_opts_CFLAGS = -g -I.. | 58 | test_opts_CFLAGS = -g -I.. $(tap_cflags) |
50 | test_opts_LDFLAGS = -L/usr/local/lib -ltap | 59 | test_opts_LDFLAGS = $(tap_ldflags) -ltap |
51 | test_opts_LDADD = ../utils_base.o ../parse_ini.o ../extra_opts.o | 60 | test_opts_LDADD = ../utils_base.o ../parse_ini.o ../extra_opts.o $(tap_ldadd) |
52 | 61 | ||
53 | test: ${noinst_PROGRAMS} | 62 | test: ${noinst_PROGRAMS} |
54 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) | 63 | perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) |
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 @@ | |||
1 | # Tap self-tests are not implemented (yet?) | ||
2 | # SUBDIRS = tests | ||
3 | |||
4 | if USE_LIBTAP_LOCAL | ||
5 | noinst_LTLIBRARIES = libtap.la | ||
6 | libtap_la_SOURCES = tap.c tap.h | ||
7 | include_HEADERS = tap.h | ||
8 | endif 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 00000000..6c15be0a --- /dev/null +++ b/tap/README | |||
@@ -0,0 +1,11 @@ | |||
1 | NAME | ||
2 | tap -- write tests that implement the Test Anything Protocol | ||
3 | |||
4 | SYNOPSIS | ||
5 | #include <tap.h> | ||
6 | |||
7 | DESCRIPTION | ||
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 00000000..4b23c24a --- /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 | ||
10 | The | ||
11 | .Nm | ||
12 | library provides functions for writing test scripts that produce output | ||
13 | consistent with the Test Anything Protocol. A test harness that parses | ||
14 | this protocol can run these tests and produce useful reports indicating | ||
15 | their success or failure. | ||
16 | .Ss PRINTF STRINGS | ||
17 | In the descriptions that follow, for any function that takes as the | ||
18 | last two parameters | ||
19 | .Dq Fa char * , Fa ... | ||
20 | it can be assumed that the | ||
21 | .Fa char * | ||
22 | is a | ||
23 | .Fn printf | ||
24 | -like format string, and the optional arguments are values to be placed | ||
25 | in 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 | ||
42 | You must first specify a test plan. This indicates how many tests you | ||
43 | intend to run, and allows the test harness to notice if any tests were | ||
44 | missed, or if the test program exited prematurely. | ||
45 | .Pp | ||
46 | To do this, use | ||
47 | .Fn plan_tests , | ||
48 | which always returns 0. The function will cause your program to exit | ||
49 | prematurely if you specify 0 tests. | ||
50 | .Pp | ||
51 | In some situations you may not know how many tests you will be running, or | ||
52 | you are developing your test program, and do not want to update the | ||
53 | .Fn plan_tests | ||
54 | parameter every time you make a change. For those situations use | ||
55 | .Fn plan_no_plan . | ||
56 | It returns 0, and indicates to the test harness that an indeterminate number | ||
57 | of tests will be run. | ||
58 | .Pp | ||
59 | Both | ||
60 | .Fn plan_tests | ||
61 | and | ||
62 | .Fn plan_no_plan | ||
63 | will cause your test program to exit prematurely with a diagnostic | ||
64 | message if they are called more than once. | ||
65 | .Pp | ||
66 | If your test program detects at run time that some required functionality | ||
67 | is missing (for example, it relies on a database connection which is not | ||
68 | present, or a particular configuration option that has not been included | ||
69 | in the running kernel) use | ||
70 | .Fn plan_skip_all , | ||
71 | passing as parameters a string to display indicating the reason for skipping | ||
72 | the 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 | ||
93 | Tests are implemented as expressions checked by calls to the | ||
94 | .Fn ok | ||
95 | and | ||
96 | .Fn ok1 | ||
97 | macros. In both cases | ||
98 | .Fa expression | ||
99 | should evaluate to true if the test succeeded. | ||
100 | .Pp | ||
101 | .Fn ok | ||
102 | allows you to specify a name, or comment, describing the test which will | ||
103 | be included in the output. | ||
104 | .Fn ok1 | ||
105 | is for those times when the expression to be tested is self | ||
106 | explanatory and does not need an associated comment. In those cases | ||
107 | the test expression becomes the comment. | ||
108 | .Pp | ||
109 | These four calls are equivalent: | ||
110 | .Bd -literal -offset indent | ||
111 | int i = 5; | ||
112 | |||
113 | ok(i == 5, "i equals 5"); /* Overly verbose */ | ||
114 | ok(i == 5, "i equals %d", i); /* Just to demonstrate printf-like | ||
115 | behaviour of the test name */ | ||
116 | ok(i == 5, "i == 5"); /* Needless repetition */ | ||
117 | ok1(i == 5); /* Just right */ | ||
118 | .Ed | ||
119 | .Pp | ||
120 | It is good practice to ensure that the test name describes the meaning | ||
121 | behind the test rather than what you are testing. Viz | ||
122 | .Bd -literal -offset indent | ||
123 | ok(db != NULL, "db is not NULL"); /* Not bad, but */ | ||
124 | ok(db != NULL, "Database conn. succeeded"); /* this is better */ | ||
125 | .Ed | ||
126 | .Pp | ||
127 | .Fn ok | ||
128 | and | ||
129 | .Fn ok1 | ||
130 | return 1 if the expression evaluated to true, and 0 if it evaluated to | ||
131 | false. This lets you chain calls from | ||
132 | .Fn ok | ||
133 | to | ||
134 | .Fn diag | ||
135 | to only produce diagnostic output if the test failed. For example, this | ||
136 | code will include diagnostic information about why the database connection | ||
137 | failed, but only if the test failed. | ||
138 | .Bd -literal -offset indent | ||
139 | ok(db != NULL, "Database conn. succeeded") || | ||
140 | diag("Database error code: %d", dberrno); | ||
141 | .Ed | ||
142 | .Pp | ||
143 | You also have | ||
144 | .Fn pass | ||
145 | and | ||
146 | .Fn fail . | ||
147 | From the Test::More documentation: | ||
148 | .Bd -literal -offset indent | ||
149 | Sometimes you just want to say that the tests have passed. | ||
150 | Usually the case is you've got some complicated condition | ||
151 | that is difficult to wedge into an ok(). In this case, | ||
152 | you can simply use pass() (to declare the test ok) or fail | ||
153 | (for not ok). | ||
154 | |||
155 | Use these very, very, very sparingly. | ||
156 | .Ed | ||
157 | .Pp | ||
158 | These 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 | ||
173 | Sets of tests can be skipped. Ordinarily you would do this because | ||
174 | the test can't be run in this particular testing environment. | ||
175 | .Pp | ||
176 | For example, suppose some tests should be run as root. If the test is | ||
177 | not being run as root then the tests should be skipped. In this | ||
178 | implementation, skipped tests are flagged as being ok, with a special | ||
179 | message indicating that they were skipped. It is your responsibility | ||
180 | to ensure that the number of tests skipped (the first parameter to | ||
181 | .Fn skip ) | ||
182 | is correct for the number of tests to skip. | ||
183 | .Pp | ||
184 | One way of implementing this is with a | ||
185 | .Dq do { } while(0); | ||
186 | loop, or an | ||
187 | .Dq if( ) { } else { } | ||
188 | construct, to ensure that there are no additional side effects from the | ||
189 | skipped tests. | ||
190 | .Bd -literal -offset indent | ||
191 | if(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 | ||
198 | Two macros are provided to assist with this. The previous example could | ||
199 | be re-written as follows. | ||
200 | .Bd -literal -offset indent | ||
201 | skip_start(getuid() != 0, 1, "because test only works as root"); | ||
202 | |||
203 | ok(do_something_as_root() == 0, "Did something as root"); | ||
204 | |||
205 | skip_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 | ||
219 | Sets of tests can be flagged as being | ||
220 | .Dq TODO . | ||
221 | These are tests that you expect to fail, probably because you haven't | ||
222 | fixed a bug, or finished a new feature yet. These tests will still be | ||
223 | run, but with additional output that indicates that they are expected | ||
224 | to fail. Should a test start to succeed unexpectedly, tools like | ||
225 | .Xr prove 1 | ||
226 | will indicate this, and you can move the test out of the todo | ||
227 | block. This is much more useful than simply commenting out (or | ||
228 | .Dq #ifdef 0 ... #endif ) | ||
229 | the tests. | ||
230 | .Bd -literal -offset indent | ||
231 | todo_start("dwim() not returning true yet"); | ||
232 | |||
233 | ok(dwim(), "Did what the user wanted"); | ||
234 | |||
235 | todo_end(); | ||
236 | .Ed | ||
237 | .Pp | ||
238 | Should | ||
239 | .Fn dwim | ||
240 | ever start succeeding you will know about it as soon as you run the | ||
241 | tests. Note that | ||
242 | .Em unlike | ||
243 | the | ||
244 | .Fn skip_* | ||
245 | family, additional code between | ||
246 | .Fn todo_start | ||
247 | and | ||
248 | .Fn todo_end | ||
249 | .Em is | ||
250 | executed. | ||
251 | .Ss SKIP vs. TODO | ||
252 | From the Test::More documentation; | ||
253 | .Bd -literal -offset indent | ||
254 | If it's something the user might not be able to do, use SKIP. | ||
255 | This includes optional modules that aren't installed, running | ||
256 | under an OS that doesn't have some feature (like fork() or | ||
257 | symlinks), or maybe you need an Internet connection and one | ||
258 | isn't available. | ||
259 | |||
260 | If it's something the programmer hasn't done yet, use TODO. | ||
261 | This is for any code you haven't written yet, or bugs you have | ||
262 | yet 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 | ||
273 | If your tests need to produce diagnostic output, use | ||
274 | .Fn diag . | ||
275 | It ensures that the output will not be considered by the TAP test harness. | ||
276 | .Fn diag | ||
277 | adds the necessary trailing | ||
278 | .Dq \en | ||
279 | for you. | ||
280 | .Bd -literal -offset indent | ||
281 | diag("Expected return code 0, got return code %d", rcode); | ||
282 | .Ed | ||
283 | .Pp | ||
284 | .Fn diag | ||
285 | always 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 | ||
294 | For maximum compatability your test program should return a particular | ||
295 | exit code. This is calculated by | ||
296 | .Fn exit_status | ||
297 | so it is sufficient to always return from | ||
298 | .Fn main | ||
299 | with either | ||
300 | .Dq return exit_status(); | ||
301 | or | ||
302 | .Dq exit(exit_status()); | ||
303 | as appropriate. | ||
304 | .Sh EXAMPLES | ||
305 | The | ||
306 | .Pa tests | ||
307 | directory in the source distribution contains numerous tests of | ||
308 | .Nm | ||
309 | functionality, written using | ||
310 | .Nm . | ||
311 | Examine them for examples of how to construct test suites. | ||
312 | .Sh COMPATABILITY | ||
313 | .Nm | ||
314 | strives to be compatible with the Perl Test::More and Test::Harness | ||
315 | modules. The test suite verifies that | ||
316 | .Nm | ||
317 | is bug-for-bug compatible with their behaviour. This is why some | ||
318 | functions which would more naturally return nothing return constant | ||
319 | values. | ||
320 | .Pp | ||
321 | If the | ||
322 | .Lb libpthread | ||
323 | is found at compile time, | ||
324 | .Nm | ||
325 | .Em should | ||
326 | be thread safe. Indications to the contrary (and test cases that expose | ||
327 | incorrect 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 | ||
334 | requires a | ||
335 | .St -isoC-99 | ||
336 | compiler. Some of the | ||
337 | .Nm | ||
338 | functionality is implemented as variadic macros, and that functionality | ||
339 | was not formally codified until C99. Patches to use | ||
340 | .Nm | ||
341 | with earlier compilers that have their own implementation of variadic | ||
342 | macros will be gratefully received. | ||
343 | .Sh HISTORY | ||
344 | .Nm | ||
345 | was written to help improve the quality and coverage of the FreeBSD | ||
346 | regression test suite, and released in the hope that others find it | ||
347 | a 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 | ||
353 | would not exist without the efforts of | ||
354 | .An "Michael G Schwern" Aq schqern@pobox.com , | ||
355 | .An "Andy Lester" Aq andy@petdance.com , | ||
356 | and the countless others who have worked on the Perl QA programme. | ||
357 | .Sh BUGS | ||
358 | Ideally, running the tests would have no side effects on the behaviour | ||
359 | of the application you are testing. However, it is not always possible | ||
360 | to avoid them. The following side effects of using | ||
361 | .Nm | ||
362 | are known. | ||
363 | .Bl -bullet -offset indent | ||
364 | .It | ||
365 | stdout is set to unbuffered mode after calling any of the | ||
366 | .Fn plan_* | ||
367 | functions. | ||
368 | .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 @@ | |||
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 | |||
34 | static int no_plan = 0; | ||
35 | static int skip_all = 0; | ||
36 | static int have_plan = 0; | ||
37 | static unsigned int test_count = 0; /* Number of tests that have been run */ | ||
38 | static unsigned int e_tests = 0; /* Expected number of tests to run */ | ||
39 | static unsigned int failures = 0; /* Number of tests that failed */ | ||
40 | static char *todo_msg = NULL; | ||
41 | static char *todo_msg_fixed = "libtap malloc issue"; | ||
42 | static int todo = 0; | ||
43 | static 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> | ||
49 | static 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 | |||
57 | static void _expected_tests(unsigned int); | ||
58 | static void _tap_init(void); | ||
59 | static 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 | */ | ||
68 | unsigned 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 | */ | ||
164 | void | ||
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 | */ | ||
187 | int | ||
188 | plan_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 | */ | ||
213 | int | ||
214 | plan_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 | */ | ||
238 | int | ||
239 | plan_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 | |||
269 | unsigned int | ||
270 | diag(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 | |||
289 | void | ||
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 | |||
301 | int | ||
302 | skip(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 | |||
327 | void | ||
328 | todo_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 | |||
343 | void | ||
344 | todo_end(void) | ||
345 | { | ||
346 | |||
347 | LOCK; | ||
348 | |||
349 | todo = 0; | ||
350 | free(todo_msg); | ||
351 | |||
352 | UNLOCK; | ||
353 | } | ||
354 | |||
355 | int | ||
356 | exit_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 | */ | ||
388 | void | ||
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 00000000..e64f9d5f --- /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 | |||
76 | unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...); | ||
77 | |||
78 | int plan_no_plan(void); | ||
79 | int plan_skip_all(char *); | ||
80 | int plan_tests(unsigned int); | ||
81 | |||
82 | unsigned int diag(char *, ...); | ||
83 | |||
84 | int skip(unsigned int, char *, ...); | ||
85 | |||
86 | void todo_start(char *, ...); | ||
87 | void todo_end(void); | ||
88 | |||
89 | 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 @@ | |||
1 | SUBDIRS= diag | ||
2 | SUBDIRS+= fail | ||
3 | SUBDIRS+= ok | ||
4 | SUBDIRS+= pass | ||
5 | SUBDIRS+= plan | ||
6 | SUBDIRS+= skip | ||
7 | 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 @@ | |||
1 | Most 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 00000000..c1ccb751 --- /dev/null +++ b/tap/tests/diag/Makefile.am | |||
@@ -0,0 +1,13 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../src | ||
10 | test_LDFLAGS = -L../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..621dc27d --- /dev/null +++ b/tap/tests/diag/test.pl | |||
@@ -0,0 +1,16 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | plan tests => 2; | ||
11 | |||
12 | $rc = diag("A diagnostic message"); | ||
13 | diag("Returned: $rc"); | ||
14 | |||
15 | ok(1, 'test 1') or diag "ok() failed, and shouldn't"; | ||
16 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../src | ||
10 | test_LDFLAGS = -L../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..73de1a7b --- /dev/null +++ b/tap/tests/fail/test.pl | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 2; | ||
11 | diag("Returned: " . sprintf('%d', $rc)); | ||
12 | |||
13 | $rc = fail('test to fail'); | ||
14 | diag("Returned: $rc"); | ||
15 | |||
16 | $rc = fail('test to fail with extra string'); | ||
17 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | SUBDIRS = ok | ||
2 | SUBDIRS += ok-hash | ||
3 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..306ddca0 --- /dev/null +++ b/tap/tests/ok/ok-hash/test.pl | |||
@@ -0,0 +1,24 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 4; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | |||
14 | $rc = ok(1, 'Test with no hash'); | ||
15 | diag("Returned: $rc"); | ||
16 | |||
17 | $rc = ok(1, 'Test with one # hash'); | ||
18 | diag("Returned: $rc"); | ||
19 | |||
20 | $rc = ok(1, 'Test with # two # hashes'); | ||
21 | diag("Returned: $rc"); | ||
22 | |||
23 | $rc = ok(1, 'Test with ## back to back hashes'); | ||
24 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..86f165f2 --- /dev/null +++ b/tap/tests/ok/ok-numeric/test.pl | |||
@@ -0,0 +1,21 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 3; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | |||
14 | $rc = ok(1, 'First test'); | ||
15 | diag("Returned: $rc"); | ||
16 | |||
17 | $rc = ok(1, '1'); | ||
18 | diag("Returned: $rc"); | ||
19 | |||
20 | $rc = ok(1, 'Third test'); | ||
21 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..59f41819 --- /dev/null +++ b/tap/tests/ok/ok/test.pl | |||
@@ -0,0 +1,27 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 5; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | |||
14 | $rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should | ||
15 | diag("Returned: $rc"); | ||
16 | |||
17 | $rc = ok(1 == 1, '1 equals 1'); # Used for %d testing in test.c | ||
18 | diag("Returned: $rc"); | ||
19 | |||
20 | $rc = ok(1 == 1, '1 == 1'); # Test ok1() passes when it should | ||
21 | diag("Returned: $rc"); | ||
22 | |||
23 | $rc = ok(1 == 2, '1 equals 2'); # Test ok() fails when it should | ||
24 | diag("Returned: $rc"); | ||
25 | |||
26 | $rc = ok(1 == 2, '1 == 2'); # Test ok1() fails when it should | ||
27 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../src | ||
10 | test_LDFLAGS = -L../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..8abc92e7 --- /dev/null +++ b/tap/tests/pass/test.pl | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 2; | ||
11 | diag("Returned: " . sprintf('%d', $rc)); | ||
12 | |||
13 | $rc = pass('test to pass'); | ||
14 | diag("Returned: $rc"); | ||
15 | |||
16 | $rc = pass('test to pass with extra string'); | ||
17 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | SUBDIRS = no-tests | ||
2 | SUBDIRS += no_plan | ||
3 | SUBDIRS += not-enough-tests | ||
4 | SUBDIRS += too-many-plans | ||
5 | SUBDIRS += too-many-tests | ||
6 | SUBDIRS += sane | ||
7 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..93d2b3b8 --- /dev/null +++ b/tap/tests/plan/no-tests/test.pl | |||
@@ -0,0 +1,14 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 0; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..19e42b57 --- /dev/null +++ b/tap/tests/plan/no_plan/test.pl | |||
@@ -0,0 +1,14 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | my $rc = 0; | ||
7 | |||
8 | use Test::More; | ||
9 | |||
10 | $rc = plan qw(no_plan); | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..73787a7c --- /dev/null +++ b/tap/tests/plan/not-enough-tests/test.pl | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 1; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | diag("Returned: $rc"); | ||
15 | |||
16 | $rc = ok(1); | ||
17 | diag("Returned: $rc"); | ||
18 | |||
19 | $rc = ok(1); | ||
20 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..35c4ef2f --- /dev/null +++ b/tap/tests/plan/sane/test.pl | |||
@@ -0,0 +1,14 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 1; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
29 | int | ||
30 | main(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 00000000..32555724 --- /dev/null +++ b/tap/tests/plan/skip_all/test.pl | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan skip_all => "No good reason"; | ||
11 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..893e5fc0 --- /dev/null +++ b/tap/tests/plan/too-many-plans/test.pl | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 1; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | diag("Returned: $rc"); | ||
15 | |||
16 | $rc = plan tests => 1; | ||
17 | diag("Returned: $rc"); | ||
18 | |||
19 | $rc = ok(0); | ||
20 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/twice!.*$/twice!/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/twice!.*$/twice!/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../../src | ||
10 | test_LDFLAGS = -L../../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..0a1666ba --- /dev/null +++ b/tap/tests/plan/too-many-tests/test.pl | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 5; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | $rc = ok(1); | ||
14 | diag("Returned: $rc"); | ||
15 | |||
16 | $rc = ok(0); | ||
17 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../src | ||
10 | test_LDFLAGS = -L../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..dc294717 --- /dev/null +++ b/tap/tests/skip/test.pl | |||
@@ -0,0 +1,40 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 4; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | my $side_effect = 0; # Check whether skipping has side effects | ||
14 | |||
15 | $rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should | ||
16 | diag("Returned: $rc"); | ||
17 | |||
18 | # Start skipping | ||
19 | SKIP: { | ||
20 | $rc = skip "Testing skipping", 1; | ||
21 | |||
22 | $side_effect++; | ||
23 | |||
24 | $rc = ok($side_effect == 1, '$side_effect checked out'); | ||
25 | } | ||
26 | |||
27 | diag("Returned: $rc"); | ||
28 | |||
29 | SKIP: { | ||
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"); | ||
40 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed test \(.*\)/# Failed test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | 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 @@ | |||
1 | |||
2 | TESTS = test.t | ||
3 | TESTS_ENVIRONMENT = $(SHELL) | ||
4 | |||
5 | EXTRA_DIST = $(TESTS) test.pl | ||
6 | |||
7 | check_PROGRAMS = test | ||
8 | |||
9 | test_CFLAGS = -g -I../../src | ||
10 | test_LDFLAGS = -L../../src | ||
11 | test_LDADD = -ltap | ||
12 | |||
13 | 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 @@ | |||
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 | |||
31 | int | ||
32 | main(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 00000000..2621e12f --- /dev/null +++ b/tap/tests/todo/test.pl | |||
@@ -0,0 +1,41 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | use warnings; | ||
4 | use strict; | ||
5 | |||
6 | use Test::More; | ||
7 | |||
8 | my $rc = 0; | ||
9 | |||
10 | $rc = plan tests => 5; | ||
11 | diag("Returned: " . sprintf("%d", $rc)); | ||
12 | |||
13 | my $side_effect = 0; # Check whether TODO has side effects | ||
14 | |||
15 | $rc = ok(1 == 1, '1 equals 1'); # Test ok() passes when it should | ||
16 | diag("Returned: $rc"); | ||
17 | |||
18 | # Start TODO tests | ||
19 | TODO: { | ||
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 | |||
33 | TODO: { | ||
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"); | ||
41 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd `dirname $0` | ||
4 | |||
5 | echo '1..2' | ||
6 | |||
7 | make 2>&1 > /dev/null | ||
8 | |||
9 | perl ./test.pl 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.pl.out | ||
10 | perlstatus=$? | ||
11 | |||
12 | ./test 2>&1 | sed -e 's/# Failed (TODO) test \(.*\)/# Failed (TODO) test ()/' > test.c.out | ||
13 | cstatus=$? | ||
14 | |||
15 | diff -u test.pl.out test.c.out | ||
16 | |||
17 | if [ $? -eq 0 ]; then | ||
18 | echo 'ok 1 - output is identical' | ||
19 | else | ||
20 | echo 'not ok 1 - output is identical' | ||
21 | fi | ||
22 | |||
23 | if [ $perlstatus -eq $cstatus ]; then | ||
24 | echo 'ok 2 - status code' | ||
25 | else | ||
26 | echo 'not ok 2 - status code' | ||
27 | echo "# perlstatus = $perlstatus" | ||
28 | echo "# cstatus = $cstatus" | ||
29 | fi | ||