summaryrefslogtreecommitdiffstats
path: root/unit/atf-src/test-programs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--unit/atf-src/test-programs/Atffile9
-rw-r--r--unit/atf-src/test-programs/Kyuafile9
-rw-r--r--unit/atf-src/test-programs/Makefile.am.inc84
-rw-r--r--unit/atf-src/test-programs/c_helpers.c503
-rw-r--r--unit/atf-src/test-programs/common.sh39
-rw-r--r--unit/atf-src/test-programs/config_test.sh58
-rw-r--r--unit/atf-src/test-programs/cpp_helpers.cpp355
-rw-r--r--unit/atf-src/test-programs/expect_test.sh151
-rw-r--r--unit/atf-src/test-programs/meta_data_test.sh60
-rw-r--r--unit/atf-src/test-programs/result_test.sh135
-rw-r--r--unit/atf-src/test-programs/sh_helpers.sh390
-rw-r--r--unit/atf-src/test-programs/srcdir_test.sh145
12 files changed, 1938 insertions, 0 deletions
diff --git a/unit/atf-src/test-programs/Atffile b/unit/atf-src/test-programs/Atffile
new file mode 100644
index 0000000..6a67a8f
--- /dev/null
+++ b/unit/atf-src/test-programs/Atffile
@@ -0,0 +1,9 @@
+Content-Type: application/X-atf-atffile; version="1"
+
+prop: test-suite = atf
+
+tp: config_test
+tp: expect_test
+tp: meta_data_test
+tp: srcdir_test
+tp: result_test
diff --git a/unit/atf-src/test-programs/Kyuafile b/unit/atf-src/test-programs/Kyuafile
new file mode 100644
index 0000000..e525282
--- /dev/null
+++ b/unit/atf-src/test-programs/Kyuafile
@@ -0,0 +1,9 @@
+syntax("kyuafile", 1)
+
+test_suite("atf")
+
+atf_test_program{name="config_test"}
+atf_test_program{name="expect_test"}
+atf_test_program{name="meta_data_test"}
+atf_test_program{name="srcdir_test"}
+atf_test_program{name="result_test"}
diff --git a/unit/atf-src/test-programs/Makefile.am.inc b/unit/atf-src/test-programs/Makefile.am.inc
new file mode 100644
index 0000000..9ef2b12
--- /dev/null
+++ b/unit/atf-src/test-programs/Makefile.am.inc
@@ -0,0 +1,84 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+tests_test_programs_DATA = test-programs/Atffile \
+ test-programs/Kyuafile
+tests_test_programsdir = $(pkgtestsdir)/test-programs
+EXTRA_DIST += $(tests_test_programs_DATA)
+
+tests_test_programs_PROGRAMS = test-programs/c_helpers
+test_programs_c_helpers_SOURCES = test-programs/c_helpers.c
+test_programs_c_helpers_LDADD = libatf-c.la
+
+tests_test_programs_PROGRAMS += test-programs/cpp_helpers
+test_programs_cpp_helpers_SOURCES = test-programs/cpp_helpers.cpp
+test_programs_cpp_helpers_LDADD = $(ATF_CXX_LIBS)
+
+common_sh = $(srcdir)/test-programs/common.sh
+EXTRA_DIST += test-programs/common.sh
+
+tests_test_programs_SCRIPTS = test-programs/sh_helpers
+CLEANFILES += test-programs/sh_helpers
+EXTRA_DIST += test-programs/sh_helpers.sh
+test-programs/sh_helpers: $(srcdir)/test-programs/sh_helpers.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/sh_helpers.sh $(common_sh)"; \
+ dst="test-programs/sh_helpers"; $(BUILD_SH_TP)
+
+tests_test_programs_SCRIPTS += test-programs/config_test
+CLEANFILES += test-programs/config_test
+EXTRA_DIST += test-programs/config_test.sh
+test-programs/config_test: $(srcdir)/test-programs/config_test.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/config_test.sh $(common_sh)"; \
+ dst="test-programs/config_test"; $(BUILD_SH_TP)
+
+tests_test_programs_SCRIPTS += test-programs/expect_test
+CLEANFILES += test-programs/expect_test
+EXTRA_DIST += test-programs/expect_test.sh
+test-programs/expect_test: $(srcdir)/test-programs/expect_test.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/expect_test.sh $(common_sh)"; \
+ dst="test-programs/expect_test"; $(BUILD_SH_TP)
+
+tests_test_programs_SCRIPTS += test-programs/meta_data_test
+CLEANFILES += test-programs/meta_data_test
+EXTRA_DIST += test-programs/meta_data_test.sh
+test-programs/meta_data_test: $(srcdir)/test-programs/meta_data_test.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/meta_data_test.sh $(common_sh)"; \
+ dst="test-programs/meta_data_test"; $(BUILD_SH_TP)
+
+tests_test_programs_SCRIPTS += test-programs/result_test
+CLEANFILES += test-programs/result_test
+EXTRA_DIST += test-programs/result_test.sh
+test-programs/result_test: $(srcdir)/test-programs/result_test.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/result_test.sh $(common_sh)"; \
+ dst="test-programs/result_test"; $(BUILD_SH_TP)
+
+tests_test_programs_SCRIPTS += test-programs/srcdir_test
+CLEANFILES += test-programs/srcdir_test
+EXTRA_DIST += test-programs/srcdir_test.sh
+test-programs/srcdir_test: $(srcdir)/test-programs/srcdir_test.sh
+ $(AM_V_GEN)src="$(srcdir)/test-programs/srcdir_test.sh $(common_sh)"; \
+ dst="test-programs/srcdir_test"; $(BUILD_SH_TP)
+
+# vim: syntax=make:noexpandtab:shiftwidth=8:softtabstop=8
diff --git a/unit/atf-src/test-programs/c_helpers.c b/unit/atf-src/test-programs/c_helpers.c
new file mode 100644
index 0000000..1b7aa4e
--- /dev/null
+++ b/unit/atf-src/test-programs/c_helpers.c
@@ -0,0 +1,503 @@
+/* Copyright (c) 2007 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <atf-c.h>
+
+#include "atf-c/detail/env.h"
+#include "atf-c/detail/fs.h"
+#include "atf-c/detail/test_helpers.h"
+#include "atf-c/detail/text.h"
+#include "atf-c/error.h"
+
+/* ---------------------------------------------------------------------
+ * Auxiliary functions.
+ * --------------------------------------------------------------------- */
+
+static
+void
+safe_remove(const char* path)
+{
+ if (unlink(path) == -1)
+ atf_tc_fail("unlink(2) of %s failed", path);
+}
+
+static
+void
+touch(const char *path)
+{
+ int fd;
+ fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
+ if (fd == -1)
+ atf_tc_fail("Could not create file %s", path);
+ close(fd);
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_cleanup".
+ * --------------------------------------------------------------------- */
+
+ATF_TC_WITH_CLEANUP(cleanup_pass);
+ATF_TC_HEAD(cleanup_pass, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_cleanup test "
+ "program");
+}
+ATF_TC_BODY(cleanup_pass, tc)
+{
+ touch(atf_tc_get_config_var(tc, "tmpfile"));
+}
+ATF_TC_CLEANUP(cleanup_pass, tc)
+{
+ if (atf_tc_get_config_var_as_bool(tc, "cleanup"))
+ safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
+}
+
+ATF_TC_WITH_CLEANUP(cleanup_fail);
+ATF_TC_HEAD(cleanup_fail, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_cleanup test "
+ "program");
+}
+ATF_TC_BODY(cleanup_fail, tc)
+{
+ touch(atf_tc_get_config_var(tc, "tmpfile"));
+ atf_tc_fail("On purpose");
+}
+ATF_TC_CLEANUP(cleanup_fail, tc)
+{
+ if (atf_tc_get_config_var_as_bool(tc, "cleanup"))
+ safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
+}
+
+ATF_TC_WITH_CLEANUP(cleanup_skip);
+ATF_TC_HEAD(cleanup_skip, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_cleanup test "
+ "program");
+}
+ATF_TC_BODY(cleanup_skip, tc)
+{
+ touch(atf_tc_get_config_var(tc, "tmpfile"));
+ atf_tc_skip("On purpose");
+}
+ATF_TC_CLEANUP(cleanup_skip, tc)
+{
+ if (atf_tc_get_config_var_as_bool(tc, "cleanup"))
+ safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
+}
+
+ATF_TC_WITH_CLEANUP(cleanup_curdir);
+ATF_TC_HEAD(cleanup_curdir, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_cleanup test "
+ "program");
+}
+ATF_TC_BODY(cleanup_curdir, tc)
+{
+ FILE *f;
+
+ f = fopen("oldvalue", "w");
+ if (f == NULL)
+ atf_tc_fail("Failed to create oldvalue file");
+ fprintf(f, "1234");
+ fclose(f);
+}
+ATF_TC_CLEANUP(cleanup_curdir, tc)
+{
+ FILE *f;
+
+ f = fopen("oldvalue", "r");
+ if (f != NULL) {
+ int i;
+ if (fscanf(f, "%d", &i) != 1)
+ fprintf(stderr, "Failed to read old value\n");
+ else
+ printf("Old value: %d", i);
+ fclose(f);
+ }
+}
+
+ATF_TC_WITH_CLEANUP(cleanup_sigterm);
+ATF_TC_HEAD(cleanup_sigterm, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_cleanup test "
+ "program");
+}
+ATF_TC_BODY(cleanup_sigterm, tc)
+{
+ char *nofile;
+
+ touch(atf_tc_get_config_var(tc, "tmpfile"));
+ kill(getpid(), SIGTERM);
+
+ RE(atf_text_format(&nofile, "%s.no",
+ atf_tc_get_config_var(tc, "tmpfile")));
+ touch(nofile);
+ free(nofile);
+}
+ATF_TC_CLEANUP(cleanup_sigterm, tc)
+{
+ safe_remove(atf_tc_get_config_var(tc, "tmpfile"));
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_config".
+ * --------------------------------------------------------------------- */
+
+ATF_TC(config_unset);
+ATF_TC_HEAD(config_unset, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_config test "
+ "program");
+}
+ATF_TC_BODY(config_unset, tc)
+{
+ ATF_REQUIRE(!atf_tc_has_config_var(tc, "test"));
+}
+
+ATF_TC(config_empty);
+ATF_TC_HEAD(config_empty, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_config test "
+ "program");
+}
+ATF_TC_BODY(config_empty, tc)
+{
+ ATF_REQUIRE(atf_tc_has_config_var(tc, "test"));
+ ATF_REQUIRE(strlen(atf_tc_get_config_var(tc, "test")) == 0);
+}
+
+ATF_TC(config_value);
+ATF_TC_HEAD(config_value, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_config test "
+ "program");
+}
+ATF_TC_BODY(config_value, tc)
+{
+ ATF_REQUIRE(atf_tc_has_config_var(tc, "test"));
+ ATF_REQUIRE(strcmp(atf_tc_get_config_var(tc, "test"), "foo") == 0);
+}
+
+ATF_TC(config_multi_value);
+ATF_TC_HEAD(config_multi_value, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_config test "
+ "program");
+}
+ATF_TC_BODY(config_multi_value, tc)
+{
+ ATF_REQUIRE(atf_tc_has_config_var(tc, "test"));
+ ATF_REQUIRE(strcmp(atf_tc_get_config_var(tc, "test"), "foo bar") == 0);
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_expect".
+ * --------------------------------------------------------------------- */
+
+ATF_TC_WITHOUT_HEAD(expect_pass_and_pass);
+ATF_TC_BODY(expect_pass_and_pass, tc)
+{
+ atf_tc_expect_pass();
+
+}
+
+ATF_TC_WITHOUT_HEAD(expect_pass_but_fail_requirement);
+ATF_TC_BODY(expect_pass_but_fail_requirement, tc)
+{
+ atf_tc_expect_pass();
+ atf_tc_fail("Some reason");
+}
+
+ATF_TC_WITHOUT_HEAD(expect_pass_but_fail_check);
+ATF_TC_BODY(expect_pass_but_fail_check, tc)
+{
+ atf_tc_expect_pass();
+ atf_tc_fail_nonfatal("Some reason");
+}
+
+ATF_TC_WITHOUT_HEAD(expect_fail_and_fail_requirement);
+ATF_TC_BODY(expect_fail_and_fail_requirement, tc)
+{
+ atf_tc_expect_fail("Fail %s", "reason");
+ atf_tc_fail("The failure");
+ atf_tc_expect_pass();
+}
+
+ATF_TC_WITHOUT_HEAD(expect_fail_and_fail_check);
+ATF_TC_BODY(expect_fail_and_fail_check, tc)
+{
+ atf_tc_expect_fail("Fail first");
+ atf_tc_fail_nonfatal("abc");
+ atf_tc_expect_pass();
+
+ atf_tc_expect_fail("And fail again");
+ atf_tc_fail_nonfatal("def");
+ atf_tc_expect_pass();
+}
+
+ATF_TC_WITHOUT_HEAD(expect_fail_but_pass);
+ATF_TC_BODY(expect_fail_but_pass, tc)
+{
+ atf_tc_expect_fail("Fail first");
+ atf_tc_fail_nonfatal("abc");
+ atf_tc_expect_pass();
+
+ atf_tc_expect_fail("Will not fail");
+ atf_tc_expect_pass();
+
+ atf_tc_expect_fail("And fail again");
+ atf_tc_fail_nonfatal("def");
+ atf_tc_expect_pass();
+}
+
+ATF_TC_WITHOUT_HEAD(expect_exit_any_and_exit);
+ATF_TC_BODY(expect_exit_any_and_exit, tc)
+{
+ atf_tc_expect_exit(-1, "Call will exit");
+ exit(EXIT_SUCCESS);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_exit_code_and_exit);
+ATF_TC_BODY(expect_exit_code_and_exit, tc)
+{
+ atf_tc_expect_exit(123, "Call will exit");
+ exit(123);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_exit_but_pass);
+ATF_TC_BODY(expect_exit_but_pass, tc)
+{
+ atf_tc_expect_exit(-1, "Call won't exit");
+}
+
+ATF_TC_WITHOUT_HEAD(expect_signal_any_and_signal);
+ATF_TC_BODY(expect_signal_any_and_signal, tc)
+{
+ atf_tc_expect_signal(-1, "Call will signal");
+ kill(getpid(), SIGKILL);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_signal_no_and_signal);
+ATF_TC_BODY(expect_signal_no_and_signal, tc)
+{
+ atf_tc_expect_signal(SIGHUP, "Call will signal");
+ kill(getpid(), SIGHUP);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_signal_but_pass);
+ATF_TC_BODY(expect_signal_but_pass, tc)
+{
+ atf_tc_expect_signal(-1, "Call won't signal");
+}
+
+ATF_TC_WITHOUT_HEAD(expect_death_and_exit);
+ATF_TC_BODY(expect_death_and_exit, tc)
+{
+ atf_tc_expect_death("Exit case");
+ exit(123);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_death_and_signal);
+ATF_TC_BODY(expect_death_and_signal, tc)
+{
+ atf_tc_expect_death("Signal case");
+ kill(getpid(), SIGKILL);
+}
+
+ATF_TC_WITHOUT_HEAD(expect_death_but_pass);
+ATF_TC_BODY(expect_death_but_pass, tc)
+{
+ atf_tc_expect_death("Call won't die");
+}
+
+ATF_TC(expect_timeout_and_hang);
+ATF_TC_HEAD(expect_timeout_and_hang, tc)
+{
+ atf_tc_set_md_var(tc, "timeout", "1");
+}
+ATF_TC_BODY(expect_timeout_and_hang, tc)
+{
+ atf_tc_expect_timeout("Will overrun");
+ sleep(5);
+}
+
+ATF_TC(expect_timeout_but_pass);
+ATF_TC_HEAD(expect_timeout_but_pass, tc)
+{
+ atf_tc_set_md_var(tc, "timeout", "1");
+}
+ATF_TC_BODY(expect_timeout_but_pass, tc)
+{
+ atf_tc_expect_timeout("Will just exit");
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_meta_data".
+ * --------------------------------------------------------------------- */
+
+ATF_TC_WITHOUT_HEAD(metadata_no_descr);
+ATF_TC_BODY(metadata_no_descr, tc)
+{
+}
+
+ATF_TC_WITHOUT_HEAD(metadata_no_head);
+ATF_TC_BODY(metadata_no_head, tc)
+{
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_srcdir".
+ * --------------------------------------------------------------------- */
+
+ATF_TC(srcdir_exists);
+ATF_TC_HEAD(srcdir_exists, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_srcdir test "
+ "program");
+}
+ATF_TC_BODY(srcdir_exists, tc)
+{
+ atf_fs_path_t p;
+ bool b;
+
+ RE(atf_fs_path_init_fmt(&p, "%s/datafile",
+ atf_tc_get_config_var(tc, "srcdir")));
+ RE(atf_fs_exists(&p, &b));
+ atf_fs_path_fini(&p);
+ if (!b)
+ atf_tc_fail("Cannot find datafile");
+}
+
+/* ---------------------------------------------------------------------
+ * Helper tests for "t_result".
+ * --------------------------------------------------------------------- */
+
+ATF_TC_WITHOUT_HEAD(result_pass);
+ATF_TC_BODY(result_pass, tc)
+{
+ printf("msg\n");
+}
+
+ATF_TC_WITHOUT_HEAD(result_fail);
+ATF_TC_BODY(result_fail, tc)
+{
+ printf("msg\n");
+ atf_tc_fail("Failure reason");
+}
+
+ATF_TC_WITHOUT_HEAD(result_skip);
+ATF_TC_BODY(result_skip, tc)
+{
+ printf("msg\n");
+ atf_tc_skip("Skipped reason");
+}
+
+ATF_TC(result_newlines_fail);
+ATF_TC_HEAD(result_newlines_fail, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_result test "
+ "program");
+}
+ATF_TC_BODY(result_newlines_fail, tc)
+{
+ atf_tc_fail("First line\nSecond line");
+}
+
+ATF_TC(result_newlines_skip);
+ATF_TC_HEAD(result_newlines_skip, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Helper test case for the t_result test "
+ "program");
+}
+ATF_TC_BODY(result_newlines_skip, tc)
+{
+ atf_tc_skip("First line\nSecond line");
+}
+
+/* ---------------------------------------------------------------------
+ * Main.
+ * --------------------------------------------------------------------- */
+
+ATF_TP_ADD_TCS(tp)
+{
+ /* Add helper tests for t_cleanup. */
+ ATF_TP_ADD_TC(tp, cleanup_pass);
+ ATF_TP_ADD_TC(tp, cleanup_fail);
+ ATF_TP_ADD_TC(tp, cleanup_skip);
+ ATF_TP_ADD_TC(tp, cleanup_curdir);
+ ATF_TP_ADD_TC(tp, cleanup_sigterm);
+
+ /* Add helper tests for t_config. */
+ ATF_TP_ADD_TC(tp, config_unset);
+ ATF_TP_ADD_TC(tp, config_empty);
+ ATF_TP_ADD_TC(tp, config_value);
+ ATF_TP_ADD_TC(tp, config_multi_value);
+
+ /* Add helper tests for t_expect. */
+ ATF_TP_ADD_TC(tp, expect_pass_and_pass);
+ ATF_TP_ADD_TC(tp, expect_pass_but_fail_requirement);
+ ATF_TP_ADD_TC(tp, expect_pass_but_fail_check);
+ ATF_TP_ADD_TC(tp, expect_fail_and_fail_requirement);
+ ATF_TP_ADD_TC(tp, expect_fail_and_fail_check);
+ ATF_TP_ADD_TC(tp, expect_fail_but_pass);
+ ATF_TP_ADD_TC(tp, expect_exit_any_and_exit);
+ ATF_TP_ADD_TC(tp, expect_exit_code_and_exit);
+ ATF_TP_ADD_TC(tp, expect_exit_but_pass);
+ ATF_TP_ADD_TC(tp, expect_signal_any_and_signal);
+ ATF_TP_ADD_TC(tp, expect_signal_no_and_signal);
+ ATF_TP_ADD_TC(tp, expect_signal_but_pass);
+ ATF_TP_ADD_TC(tp, expect_death_and_exit);
+ ATF_TP_ADD_TC(tp, expect_death_and_signal);
+ ATF_TP_ADD_TC(tp, expect_death_but_pass);
+ ATF_TP_ADD_TC(tp, expect_timeout_and_hang);
+ ATF_TP_ADD_TC(tp, expect_timeout_but_pass);
+
+ /* Add helper tests for t_meta_data. */
+ ATF_TP_ADD_TC(tp, metadata_no_descr);
+ ATF_TP_ADD_TC(tp, metadata_no_head);
+
+ /* Add helper tests for t_srcdir. */
+ ATF_TP_ADD_TC(tp, srcdir_exists);
+
+ /* Add helper tests for t_result. */
+ ATF_TP_ADD_TC(tp, result_pass);
+ ATF_TP_ADD_TC(tp, result_fail);
+ ATF_TP_ADD_TC(tp, result_skip);
+ ATF_TP_ADD_TC(tp, result_newlines_fail);
+ ATF_TP_ADD_TC(tp, result_newlines_skip);
+
+ return atf_no_error();
+}
diff --git a/unit/atf-src/test-programs/common.sh b/unit/atf-src/test-programs/common.sh
new file mode 100644
index 0000000..9165752
--- /dev/null
+++ b/unit/atf-src/test-programs/common.sh
@@ -0,0 +1,39 @@
+# Copyright (c) 2008 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+get_helpers()
+{
+ srcdir=$(atf_get_srcdir)
+
+ if [ ${#} -eq 0 ]; then
+ set -- c_helpers cpp_helpers sh_helpers
+ fi
+
+ for h_name in "${@}"; do
+ echo ${srcdir}/${h_name}
+ done
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/config_test.sh b/unit/atf-src/test-programs/config_test.sh
new file mode 100644
index 0000000..5102852
--- /dev/null
+++ b/unit/atf-src/test-programs/config_test.sh
@@ -0,0 +1,58 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+atf_test_case vflag
+vflag_head()
+{
+ atf_set "descr" "Tests that the -v flag works correctly to set" \
+ "configuration variables"
+}
+vflag_body()
+{
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o ignore -e ignore ${h} -s $(atf_get_srcdir) \
+ -r resfile config_unset
+ atf_check -s eq:0 -o ignore -e empty grep 'passed' resfile
+
+ atf_check -s eq:0 -o ignore -e ignore ${h} -s $(atf_get_srcdir) \
+ -r resfile -v 'test=' config_empty
+ atf_check -s eq:0 -o ignore -e empty grep 'passed' resfile
+
+ atf_check -s eq:0 -o ignore -e ignore ${h} -s $(atf_get_srcdir) \
+ -r resfile -v 'test=foo' config_value
+ atf_check -s eq:0 -o ignore -e empty grep 'passed' resfile
+
+ atf_check -s eq:0 -o ignore -e ignore -x ${h} -s $(atf_get_srcdir) \
+ -r resfile -v \'test=foo bar\' config_multi_value
+ atf_check -s eq:0 -o ignore -e empty grep 'passed' resfile
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case vflag
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/cpp_helpers.cpp b/unit/atf-src/test-programs/cpp_helpers.cpp
new file mode 100644
index 0000000..ff9e543
--- /dev/null
+++ b/unit/atf-src/test-programs/cpp_helpers.cpp
@@ -0,0 +1,355 @@
+// Copyright (c) 2007 The NetBSD Foundation, Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+extern "C" {
+#include <signal.h>
+#include <unistd.h>
+}
+
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+
+#include <atf-c++.hpp>
+
+#include "atf-c++/detail/fs.hpp"
+
+// ------------------------------------------------------------------------
+// Helper tests for "t_config".
+// ------------------------------------------------------------------------
+
+ATF_TEST_CASE(config_unset);
+ATF_TEST_CASE_HEAD(config_unset)
+{
+ set_md_var("descr", "Helper test case for the t_config test program");
+}
+ATF_TEST_CASE_BODY(config_unset)
+{
+ ATF_REQUIRE(!has_config_var("test"));
+}
+
+ATF_TEST_CASE(config_empty);
+ATF_TEST_CASE_HEAD(config_empty)
+{
+ set_md_var("descr", "Helper test case for the t_config test program");
+}
+ATF_TEST_CASE_BODY(config_empty)
+{
+ ATF_REQUIRE_EQ(get_config_var("test"), "");
+}
+
+ATF_TEST_CASE(config_value);
+ATF_TEST_CASE_HEAD(config_value)
+{
+ set_md_var("descr", "Helper test case for the t_config test program");
+}
+ATF_TEST_CASE_BODY(config_value)
+{
+ ATF_REQUIRE_EQ(get_config_var("test"), "foo");
+}
+
+ATF_TEST_CASE(config_multi_value);
+ATF_TEST_CASE_HEAD(config_multi_value)
+{
+ set_md_var("descr", "Helper test case for the t_config test program");
+}
+ATF_TEST_CASE_BODY(config_multi_value)
+{
+ ATF_REQUIRE_EQ(get_config_var("test"), "foo bar");
+}
+
+// ------------------------------------------------------------------------
+// Helper tests for "t_expect".
+// ------------------------------------------------------------------------
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_and_pass);
+ATF_TEST_CASE_BODY(expect_pass_and_pass)
+{
+ expect_pass();
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_but_fail_requirement);
+ATF_TEST_CASE_BODY(expect_pass_but_fail_requirement)
+{
+ expect_pass();
+ fail("Some reason");
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_but_fail_check);
+ATF_TEST_CASE_BODY(expect_pass_but_fail_check)
+{
+ expect_pass();
+ fail_nonfatal("Some reason");
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_and_fail_requirement);
+ATF_TEST_CASE_BODY(expect_fail_and_fail_requirement)
+{
+ expect_fail("Fail reason");
+ fail("The failure");
+ expect_pass();
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_and_fail_check);
+ATF_TEST_CASE_BODY(expect_fail_and_fail_check)
+{
+ expect_fail("Fail first");
+ fail_nonfatal("abc");
+ expect_pass();
+
+ expect_fail("And fail again");
+ fail_nonfatal("def");
+ expect_pass();
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_but_pass);
+ATF_TEST_CASE_BODY(expect_fail_but_pass)
+{
+ expect_fail("Fail first");
+ fail_nonfatal("abc");
+ expect_pass();
+
+ expect_fail("Will not fail");
+ expect_pass();
+
+ expect_fail("And fail again");
+ fail_nonfatal("def");
+ expect_pass();
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_any_and_exit);
+ATF_TEST_CASE_BODY(expect_exit_any_and_exit)
+{
+ expect_exit(-1, "Call will exit");
+ std::exit(EXIT_SUCCESS);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_code_and_exit);
+ATF_TEST_CASE_BODY(expect_exit_code_and_exit)
+{
+ expect_exit(123, "Call will exit");
+ std::exit(123);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_but_pass);
+ATF_TEST_CASE_BODY(expect_exit_but_pass)
+{
+ expect_exit(-1, "Call won't exit");
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_any_and_signal);
+ATF_TEST_CASE_BODY(expect_signal_any_and_signal)
+{
+ expect_signal(-1, "Call will signal");
+ ::kill(getpid(), SIGKILL);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_no_and_signal);
+ATF_TEST_CASE_BODY(expect_signal_no_and_signal)
+{
+ expect_signal(SIGHUP, "Call will signal");
+ ::kill(getpid(), SIGHUP);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_but_pass);
+ATF_TEST_CASE_BODY(expect_signal_but_pass)
+{
+ expect_signal(-1, "Call won't signal");
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_death_and_exit);
+ATF_TEST_CASE_BODY(expect_death_and_exit)
+{
+ expect_death("Exit case");
+ std::exit(123);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_death_and_signal);
+ATF_TEST_CASE_BODY(expect_death_and_signal)
+{
+ expect_death("Signal case");
+ kill(getpid(), SIGKILL);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(expect_death_but_pass);
+ATF_TEST_CASE_BODY(expect_death_but_pass)
+{
+ expect_death("Call won't die");
+}
+
+ATF_TEST_CASE(expect_timeout_and_hang);
+ATF_TEST_CASE_HEAD(expect_timeout_and_hang)
+{
+ set_md_var("timeout", "1");
+}
+ATF_TEST_CASE_BODY(expect_timeout_and_hang)
+{
+ expect_timeout("Will overrun");
+ ::sleep(5);
+}
+
+ATF_TEST_CASE(expect_timeout_but_pass);
+ATF_TEST_CASE_HEAD(expect_timeout_but_pass)
+{
+ set_md_var("timeout", "1");
+}
+ATF_TEST_CASE_BODY(expect_timeout_but_pass)
+{
+ expect_timeout("Will just exit");
+}
+
+// ------------------------------------------------------------------------
+// Helper tests for "t_meta_data".
+// ------------------------------------------------------------------------
+
+ATF_TEST_CASE(metadata_no_descr);
+ATF_TEST_CASE_HEAD(metadata_no_descr)
+{
+}
+ATF_TEST_CASE_BODY(metadata_no_descr)
+{
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(metadata_no_head);
+ATF_TEST_CASE_BODY(metadata_no_head)
+{
+}
+
+// ------------------------------------------------------------------------
+// Helper tests for "t_srcdir".
+// ------------------------------------------------------------------------
+
+ATF_TEST_CASE(srcdir_exists);
+ATF_TEST_CASE_HEAD(srcdir_exists)
+{
+ set_md_var("descr", "Helper test case for the t_srcdir test program");
+}
+ATF_TEST_CASE_BODY(srcdir_exists)
+{
+ if (!atf::fs::exists(atf::fs::path(get_config_var("srcdir")) /
+ "datafile"))
+ ATF_FAIL("Cannot find datafile");
+}
+
+// ------------------------------------------------------------------------
+// Helper tests for "t_result".
+// ------------------------------------------------------------------------
+
+ATF_TEST_CASE(result_pass);
+ATF_TEST_CASE_HEAD(result_pass) { }
+ATF_TEST_CASE_BODY(result_pass)
+{
+ std::cout << "msg\n";
+}
+
+ATF_TEST_CASE(result_fail);
+ATF_TEST_CASE_HEAD(result_fail) { }
+ATF_TEST_CASE_BODY(result_fail)
+{
+ std::cout << "msg\n";
+ ATF_FAIL("Failure reason");
+}
+
+ATF_TEST_CASE(result_skip);
+ATF_TEST_CASE_HEAD(result_skip) { }
+ATF_TEST_CASE_BODY(result_skip)
+{
+ std::cout << "msg\n";
+ ATF_SKIP("Skipped reason");
+}
+
+ATF_TEST_CASE(result_newlines_fail);
+ATF_TEST_CASE_HEAD(result_newlines_fail)
+{
+ set_md_var("descr", "Helper test case for the t_result test program");
+}
+ATF_TEST_CASE_BODY(result_newlines_fail)
+{
+ ATF_FAIL("First line\nSecond line");
+}
+
+ATF_TEST_CASE(result_newlines_skip);
+ATF_TEST_CASE_HEAD(result_newlines_skip)
+{
+ set_md_var("descr", "Helper test case for the t_result test program");
+}
+ATF_TEST_CASE_BODY(result_newlines_skip)
+{
+ ATF_SKIP("First line\nSecond line");
+}
+
+ATF_TEST_CASE(result_exception);
+ATF_TEST_CASE_HEAD(result_exception) { }
+ATF_TEST_CASE_BODY(result_exception)
+{
+ throw std::runtime_error("This is unhandled");
+}
+
+// ------------------------------------------------------------------------
+// Main.
+// ------------------------------------------------------------------------
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ // Add helper tests for t_config.
+ ATF_ADD_TEST_CASE(tcs, config_unset);
+ ATF_ADD_TEST_CASE(tcs, config_empty);
+ ATF_ADD_TEST_CASE(tcs, config_value);
+ ATF_ADD_TEST_CASE(tcs, config_multi_value);
+
+ // Add helper tests for t_expect.
+ ATF_ADD_TEST_CASE(tcs, expect_pass_and_pass);
+ ATF_ADD_TEST_CASE(tcs, expect_pass_but_fail_requirement);
+ ATF_ADD_TEST_CASE(tcs, expect_pass_but_fail_check);
+ ATF_ADD_TEST_CASE(tcs, expect_fail_and_fail_requirement);
+ ATF_ADD_TEST_CASE(tcs, expect_fail_and_fail_check);
+ ATF_ADD_TEST_CASE(tcs, expect_fail_but_pass);
+ ATF_ADD_TEST_CASE(tcs, expect_exit_any_and_exit);
+ ATF_ADD_TEST_CASE(tcs, expect_exit_code_and_exit);
+ ATF_ADD_TEST_CASE(tcs, expect_exit_but_pass);
+ ATF_ADD_TEST_CASE(tcs, expect_signal_any_and_signal);
+ ATF_ADD_TEST_CASE(tcs, expect_signal_no_and_signal);
+ ATF_ADD_TEST_CASE(tcs, expect_signal_but_pass);
+ ATF_ADD_TEST_CASE(tcs, expect_death_and_exit);
+ ATF_ADD_TEST_CASE(tcs, expect_death_and_signal);
+ ATF_ADD_TEST_CASE(tcs, expect_death_but_pass);
+ ATF_ADD_TEST_CASE(tcs, expect_timeout_and_hang);
+ ATF_ADD_TEST_CASE(tcs, expect_timeout_but_pass);
+
+ // Add helper tests for t_meta_data.
+ ATF_ADD_TEST_CASE(tcs, metadata_no_descr);
+ ATF_ADD_TEST_CASE(tcs, metadata_no_head);
+
+ // Add helper tests for t_srcdir.
+ ATF_ADD_TEST_CASE(tcs, srcdir_exists);
+
+ // Add helper tests for t_result.
+ ATF_ADD_TEST_CASE(tcs, result_pass);
+ ATF_ADD_TEST_CASE(tcs, result_fail);
+ ATF_ADD_TEST_CASE(tcs, result_skip);
+ ATF_ADD_TEST_CASE(tcs, result_newlines_fail);
+ ATF_ADD_TEST_CASE(tcs, result_newlines_skip);
+ ATF_ADD_TEST_CASE(tcs, result_exception);
+}
diff --git a/unit/atf-src/test-programs/expect_test.sh b/unit/atf-src/test-programs/expect_test.sh
new file mode 100644
index 0000000..74e38e1
--- /dev/null
+++ b/unit/atf-src/test-programs/expect_test.sh
@@ -0,0 +1,151 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+check_result() {
+ file="${1}"; shift
+
+ atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}"
+ rm "${file}"
+}
+
+atf_test_case expect_pass
+expect_pass_body() {
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass
+ check_result result "passed"
+
+ atf_check -s eq:1 -e ignore "${h}" -r result \
+ expect_pass_but_fail_requirement
+ check_result result "failed: Some reason"
+
+ # atf-sh does not support non-fatal failures yet; skip checks for
+ # such conditions.
+ case "${h}" in *sh_helpers*) continue ;; esac
+
+ atf_check -s eq:1 -o empty -e match:"Some reason" \
+ "${h}" -r result expect_pass_but_fail_check
+ check_result result "failed: 1 checks failed"
+ done
+}
+
+atf_test_case expect_fail
+expect_fail_body() {
+ for h in $(get_helpers c_helpers cpp_helpers); do
+ atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement
+ check_result result "expected_failure: Fail reason: The failure"
+
+ atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \
+ -e not-match:"And fail again" "${h}" -r result expect_fail_but_pass
+ check_result result "failed: .*expecting a failure"
+
+ # atf-sh does not support non-fatal failures yet; skip checks for
+ # such conditions.
+ case "${h}" in *sh_helpers*) continue ;; esac
+
+ atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \
+ -e match:"Expected check failure: And fail again: def" \
+ "${h}" -r result expect_fail_and_fail_check
+ check_result result "expected_failure: And fail again: 2 checks" \
+ "failed as expected"
+ done
+
+ # atf-sh does not support non-fatal failures yet; skip checks for
+ # such conditions.
+ for h in $(get_helpers sh_helpers); do
+ atf_check -s eq:0 -e ignore "${h}" -r result \
+ expect_fail_and_fail_requirement
+ check_result result "expected_failure: Fail reason: The failure"
+
+ atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass
+ check_result result "failed: .*expecting a failure"
+ done
+}
+
+atf_test_case expect_exit
+expect_exit_body() {
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit
+ check_result result "expected_exit: Call will exit"
+
+ atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit
+ check_result result "expected_exit\(123\): Call will exit"
+
+ atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass
+ check_result result "failed: .*expected to exit"
+ done
+}
+
+atf_test_case expect_signal
+expect_signal_body() {
+ for h in $(get_helpers); do
+ atf_check -s signal:9 -e ignore "${h}" -r result \
+ expect_signal_any_and_signal
+ check_result result "expected_signal: Call will signal"
+
+ atf_check -s signal:hup -e ignore "${h}" -r result \
+ expect_signal_no_and_signal
+ check_result result "expected_signal\(1\): Call will signal"
+
+ atf_check -s eq:1 -e ignore "${h}" -r result \
+ expect_signal_but_pass
+ check_result result "failed: .*termination signal"
+ done
+}
+
+atf_test_case expect_death
+expect_death_body() {
+ for h in $(get_helpers); do
+ atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit
+ check_result result "expected_death: Exit case"
+
+ atf_check -s signal:kill -e ignore "${h}" -r result \
+ expect_death_and_signal
+ check_result result "expected_death: Signal case"
+
+ atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass
+ check_result result "failed: .*terminate abruptly"
+ done
+}
+
+atf_test_case expect_timeout
+expect_timeout_body() {
+ for h in $(get_helpers); do
+ atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass
+ check_result result "failed: Test case was expected to hang but it" \
+ "continued execution"
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case expect_pass
+ atf_add_test_case expect_fail
+ atf_add_test_case expect_exit
+ atf_add_test_case expect_signal
+ atf_add_test_case expect_death
+ atf_add_test_case expect_timeout
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/meta_data_test.sh b/unit/atf-src/test-programs/meta_data_test.sh
new file mode 100644
index 0000000..150b9e2
--- /dev/null
+++ b/unit/atf-src/test-programs/meta_data_test.sh
@@ -0,0 +1,60 @@
+# Copyright (c) 2010 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+atf_test_case no_descr
+no_descr_head()
+{
+ atf_set "descr" "Tests that the description may not be present"
+}
+no_descr_body()
+{
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o ignore -e ignore ${h} -s $(atf_get_srcdir) -l
+ atf_check -s eq:0 -o match:passed -e ignore ${h} -s $(atf_get_srcdir) \
+ metadata_no_descr
+ done
+}
+
+atf_test_case no_head
+no_head_head()
+{
+ atf_set "descr" "Tests that the head may not be present"
+}
+no_head_body()
+{
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o ignore -e ignore ${h} -s $(atf_get_srcdir) -l
+ atf_check -s eq:0 -o match:passed -e ignore ${h} -s $(atf_get_srcdir) \
+ metadata_no_head
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case no_descr
+ atf_add_test_case no_head
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/result_test.sh b/unit/atf-src/test-programs/result_test.sh
new file mode 100644
index 0000000..a87f08d
--- /dev/null
+++ b/unit/atf-src/test-programs/result_test.sh
@@ -0,0 +1,135 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+atf_test_case runtime_warnings
+runtime_warnings_head()
+{
+ # The fact that this test case is in this test program is an abuse.
+ atf_set "descr" "Tests that the test case prints a warning because" \
+ "it is being run outside of a runtime engine"
+}
+runtime_warnings_body()
+{
+ unset __RUNNING_INSIDE_ATF_RUN
+ srcdir="$(atf_get_srcdir)"
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*kyua" \
+ "${h}" -s "${srcdir}" result_pass
+ done
+}
+
+atf_test_case result_on_stdout
+result_on_stdout_head()
+{
+ atf_set "descr" "Tests that the test case result is printed on stdout" \
+ "by default"
+}
+result_on_stdout_body()
+{
+ srcdir="$(atf_get_srcdir)"
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o match:"passed" -o match:"msg" \
+ -e ignore "${h}" -s "${srcdir}" result_pass
+ atf_check -s eq:1 -o match:"failed: Failure reason" -o match:"msg" \
+ -e ignore "${h}" -s "${srcdir}" result_fail
+ atf_check -s eq:0 -o match:"skipped: Skipped reason" -o match:"msg" \
+ -e ignore "${h}" -s "${srcdir}" result_skip
+ done
+}
+
+atf_test_case result_to_file
+result_to_file_head()
+{
+ atf_set "descr" "Tests that the test case result is sent to a file if -r" \
+ "is used"
+}
+result_to_file_body()
+{
+ srcdir="$(atf_get_srcdir)"
+ for h in $(get_helpers); do
+ atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
+ -r resfile result_pass
+ atf_check -o inline:"passed\n" cat resfile
+
+ atf_check -s eq:1 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
+ -r resfile result_fail
+ atf_check -o inline:"failed: Failure reason\n" cat resfile
+
+ atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
+ -r resfile result_skip
+ atf_check -o inline:"skipped: Skipped reason\n" cat resfile
+ done
+}
+
+atf_test_case result_to_file_fail
+result_to_file_fail_head()
+{
+ atf_set "descr" "Tests controlled failure if the test program fails to" \
+ "create the results file"
+ atf_set "require.user" "unprivileged"
+}
+result_to_file_fail_body()
+{
+ mkdir dir
+ chmod 444 dir
+
+ srcdir="$(atf_get_srcdir)"
+
+ for h in $(get_helpers c_helpers cpp_helpers); do
+ atf_check -s signal -o ignore \
+ -e match:"FATAL ERROR: Cannot create.*'dir/resfile'" \
+ "${h}" -s "${srcdir}" -r dir/resfile result_pass
+ done
+
+ for h in $(get_helpers sh_helpers); do
+ atf_check -s exit -o ignore \
+ -e match:"ERROR: Cannot create.*'dir/resfile'" \
+ "${h}" -s "${srcdir}" -r dir/resfile result_pass
+ done
+}
+
+atf_test_case result_exception
+result_exception_head()
+{
+ atf_set "descr" "Tests that an unhandled exception is correctly captured"
+}
+result_exception_body()
+{
+ for h in $(get_helpers cpp_helpers); do
+ atf_check -s signal -o not-match:'failed: .*This is unhandled' \
+ -e ignore "${h}" -s "${srcdir}" result_exception
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case runtime_warnings
+ atf_add_test_case result_on_stdout
+ atf_add_test_case result_to_file
+ atf_add_test_case result_to_file_fail
+ atf_add_test_case result_exception
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/sh_helpers.sh b/unit/atf-src/test-programs/sh_helpers.sh
new file mode 100644
index 0000000..b27a541
--- /dev/null
+++ b/unit/atf-src/test-programs/sh_helpers.sh
@@ -0,0 +1,390 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_cleanup".
+# -------------------------------------------------------------------------
+
+atf_test_case cleanup_pass cleanup
+cleanup_pass_head()
+{
+ atf_set "descr" "Helper test case for the t_cleanup test program"
+}
+cleanup_pass_body()
+{
+ touch $(atf_config_get tmpfile)
+}
+cleanup_pass_cleanup()
+{
+ if [ $(atf_config_get cleanup no) = yes ]; then
+ rm $(atf_config_get tmpfile)
+ fi
+}
+
+atf_test_case cleanup_fail cleanup
+cleanup_fail_head()
+{
+ atf_set "descr" "Helper test case for the t_cleanup test program"
+}
+cleanup_fail_body()
+{
+ touch $(atf_config_get tmpfile)
+ atf_fail "On purpose"
+}
+cleanup_fail_cleanup()
+{
+ if [ $(atf_config_get cleanup no) = yes ]; then
+ rm $(atf_config_get tmpfile)
+ fi
+}
+
+atf_test_case cleanup_skip cleanup
+cleanup_skip_head()
+{
+ atf_set "descr" "Helper test case for the t_cleanup test program"
+}
+cleanup_skip_body()
+{
+ touch $(atf_config_get tmpfile)
+ atf_skip "On purpose"
+}
+cleanup_skip_cleanup()
+{
+ if [ $(atf_config_get cleanup no) = yes ]; then
+ rm $(atf_config_get tmpfile)
+ fi
+}
+
+atf_test_case cleanup_curdir cleanup
+cleanup_curdir_head()
+{
+ atf_set "descr" "Helper test case for the t_cleanup test program"
+}
+cleanup_curdir_body()
+{
+ echo 1234 >oldvalue
+}
+cleanup_curdir_cleanup()
+{
+ test -f oldvalue && echo "Old value: $(cat oldvalue)"
+}
+
+atf_test_case cleanup_sigterm cleanup
+cleanup_sigterm_head()
+{
+ atf_set "descr" "Helper test case for the t_cleanup test program"
+}
+cleanup_sigterm_body()
+{
+ touch $(atf_config_get tmpfile)
+ kill $$
+ touch $(atf_config_get tmpfile).no
+}
+cleanup_sigterm_cleanup()
+{
+ rm $(atf_config_get tmpfile)
+}
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_config".
+# -------------------------------------------------------------------------
+
+atf_test_case config_unset
+config_unset_head()
+{
+ atf_set "descr" "Helper test case for the t_config test program"
+}
+config_unset_body()
+{
+ if atf_config_has 'test'; then
+ atf_fail "Test variable already defined"
+ fi
+}
+
+atf_test_case config_empty
+config_empty_head()
+{
+ atf_set "descr" "Helper test case for the t_config test program"
+}
+config_empty_body()
+{
+ atf_check_equal "$(atf_config_get 'test')" ""
+}
+
+atf_test_case config_value
+config_value_head()
+{
+ atf_set "descr" "Helper test case for the t_config test program"
+}
+config_value_body()
+{
+ atf_check_equal "$(atf_config_get 'test')" "foo"
+}
+
+atf_test_case config_multi_value
+config_multi_value_head()
+{
+ atf_set "descr" "Helper test case for the t_config test program"
+}
+config_multi_value_body()
+{
+ atf_check_equal "$(atf_config_get 'test')" "foo bar"
+}
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_expect".
+# -------------------------------------------------------------------------
+
+atf_test_case expect_pass_and_pass
+expect_pass_and_pass_body()
+{
+ atf_expect_pass
+}
+
+atf_test_case expect_pass_but_fail_requirement
+expect_pass_but_fail_requirement_body()
+{
+ atf_expect_pass
+ atf_fail "Some reason"
+}
+
+atf_test_case expect_pass_but_fail_check
+expect_pass_but_fail_check_body()
+{
+ atf_fail "Non-fatal failures not implemented"
+}
+
+atf_test_case expect_fail_and_fail_requirement
+expect_fail_and_fail_requirement_body()
+{
+ atf_expect_fail "Fail reason"
+ atf_fail "The failure"
+ atf_expect_pass
+}
+
+atf_test_case expect_fail_and_fail_check
+expect_fail_and_fail_check_body()
+{
+ atf_fail "Non-fatal failures not implemented"
+}
+
+atf_test_case expect_fail_but_pass
+expect_fail_but_pass_body()
+{
+ atf_expect_fail "Fail first"
+ atf_expect_pass
+}
+
+atf_test_case expect_exit_any_and_exit
+expect_exit_any_and_exit_body()
+{
+ atf_expect_exit -1 "Call will exit"
+ exit 0
+}
+
+atf_test_case expect_exit_code_and_exit
+expect_exit_code_and_exit_body()
+{
+ atf_expect_exit 123 "Call will exit"
+ exit 123
+}
+
+atf_test_case expect_exit_but_pass
+expect_exit_but_pass_body()
+{
+ atf_expect_exit -1 "Call won't exit"
+}
+
+atf_test_case expect_signal_any_and_signal
+expect_signal_any_and_signal_body()
+{
+ atf_expect_signal -1 "Call will signal"
+ kill -9 $$
+}
+
+atf_test_case expect_signal_no_and_signal
+expect_signal_no_and_signal_body()
+{
+ atf_expect_signal 1 "Call will signal"
+ kill -1 $$
+}
+
+atf_test_case expect_signal_but_pass
+expect_signal_but_pass_body()
+{
+ atf_expect_signal -1 "Call won't signal"
+}
+
+atf_test_case expect_death_and_exit
+expect_death_and_exit_body()
+{
+ atf_expect_death "Exit case"
+ exit 123
+}
+
+atf_test_case expect_death_and_signal
+expect_death_and_signal_body()
+{
+ atf_expect_death "Signal case"
+ kill -9 $$
+}
+
+atf_test_case expect_death_but_pass
+expect_death_but_pass_body()
+{
+ atf_expect_death "Call won't die"
+}
+
+atf_test_case expect_timeout_and_hang
+expect_timeout_and_hang_head()
+{
+ atf_set "timeout" "1"
+}
+expect_timeout_and_hang_body()
+{
+ atf_expect_timeout "Will overrun"
+ sleep 5
+}
+
+atf_test_case expect_timeout_but_pass
+expect_timeout_but_pass_head()
+{
+ atf_set "timeout" "1"
+}
+expect_timeout_but_pass_body()
+{
+ atf_expect_timeout "Will just exit"
+}
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_meta_data".
+# -------------------------------------------------------------------------
+
+atf_test_case metadata_no_descr
+metadata_no_descr_head()
+{
+ :
+}
+metadata_no_descr_body()
+{
+ :
+}
+
+atf_test_case metadata_no_head
+metadata_no_head_body()
+{
+ :
+}
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_srcdir".
+# -------------------------------------------------------------------------
+
+atf_test_case srcdir_exists
+srcdir_exists_head()
+{
+ atf_set "descr" "Helper test case for the t_srcdir test program"
+}
+srcdir_exists_body()
+{
+ [ -f "$(atf_get_srcdir)/datafile" ] || atf_fail "Cannot find datafile"
+}
+
+# -------------------------------------------------------------------------
+# Helper tests for "t_result".
+# -------------------------------------------------------------------------
+
+atf_test_case result_pass
+result_pass_body()
+{
+ echo "msg"
+}
+
+atf_test_case result_fail
+result_fail_body()
+{
+ echo "msg"
+ atf_fail "Failure reason"
+}
+
+atf_test_case result_skip
+result_skip_body()
+{
+ echo "msg"
+ atf_skip "Skipped reason"
+}
+
+# -------------------------------------------------------------------------
+# Main.
+# -------------------------------------------------------------------------
+
+atf_init_test_cases()
+{
+ # Add helper tests for t_cleanup.
+ atf_add_test_case cleanup_pass
+ atf_add_test_case cleanup_fail
+ atf_add_test_case cleanup_skip
+ atf_add_test_case cleanup_curdir
+ atf_add_test_case cleanup_sigterm
+
+ # Add helper tests for t_config.
+ atf_add_test_case config_unset
+ atf_add_test_case config_empty
+ atf_add_test_case config_value
+ atf_add_test_case config_multi_value
+
+ # Add helper tests for t_expect.
+ atf_add_test_case expect_pass_and_pass
+ atf_add_test_case expect_pass_but_fail_requirement
+ atf_add_test_case expect_pass_but_fail_check
+ atf_add_test_case expect_fail_and_fail_requirement
+ atf_add_test_case expect_fail_and_fail_check
+ atf_add_test_case expect_fail_but_pass
+ atf_add_test_case expect_exit_any_and_exit
+ atf_add_test_case expect_exit_code_and_exit
+ atf_add_test_case expect_exit_but_pass
+ atf_add_test_case expect_signal_any_and_signal
+ atf_add_test_case expect_signal_no_and_signal
+ atf_add_test_case expect_signal_but_pass
+ atf_add_test_case expect_death_and_exit
+ atf_add_test_case expect_death_and_signal
+ atf_add_test_case expect_death_but_pass
+ atf_add_test_case expect_timeout_and_hang
+ atf_add_test_case expect_timeout_but_pass
+
+ # Add helper tests for t_meta_data.
+ atf_add_test_case metadata_no_descr
+ atf_add_test_case metadata_no_head
+
+ # Add helper tests for t_srcdir.
+ atf_add_test_case srcdir_exists
+
+ # Add helper tests for t_result.
+ atf_add_test_case result_pass
+ atf_add_test_case result_fail
+ atf_add_test_case result_skip
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
diff --git a/unit/atf-src/test-programs/srcdir_test.sh b/unit/atf-src/test-programs/srcdir_test.sh
new file mode 100644
index 0000000..90a468a
--- /dev/null
+++ b/unit/atf-src/test-programs/srcdir_test.sh
@@ -0,0 +1,145 @@
+# Copyright (c) 2007 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+create_files()
+{
+ mkdir tmp
+ touch tmp/datafile
+}
+
+atf_test_case default
+default_head()
+{
+ atf_set "descr" "Checks that the program can find its files if" \
+ "executed from the same directory"
+}
+default_body()
+{
+ create_files
+
+ for hp in $(get_helpers); do
+ h=${hp##*/}
+ cp ${hp} tmp
+ atf_check -s eq:0 -o ignore -e ignore -x \
+ "cd tmp && ./${h} srcdir_exists"
+ atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
+ atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
+ done
+}
+
+atf_test_case libtool
+libtool_head()
+{
+ atf_set "descr" "Checks that the program can find its files if" \
+ "executed from the source directory and if it" \
+ "was built with libtool"
+}
+libtool_body()
+{
+ create_files
+ mkdir tmp/.libs
+
+ for hp in $(get_helpers c_helpers cpp_helpers); do
+ h=${hp##*/}
+ cp ${hp} tmp
+ cp ${hp} tmp/.libs
+ atf_check -s eq:0 -o ignore -e ignore -x \
+ "cd tmp && ./.libs/${h} srcdir_exists"
+ atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
+ atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
+ done
+
+ for hp in $(get_helpers c_helpers cpp_helpers); do
+ h=${hp##*/}
+ cp ${hp} tmp
+ cp ${hp} tmp/.libs/lt-${h}
+ atf_check -s eq:0 -o ignore -e ignore -x \
+ "cd tmp && ./.libs/lt-${h} srcdir_exists"
+ atf_check -s eq:1 -o empty -e ignore "${hp}" -r res srcdir_exists
+ atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
+ done
+}
+
+atf_test_case sflag
+sflag_head()
+{
+ atf_set "descr" "Checks that the program can find its files when" \
+ "using the -s flag"
+}
+sflag_body()
+{
+ create_files
+
+ for hp in $(get_helpers); do
+ h=${hp##*/}
+ cp ${hp} tmp
+ atf_check -s eq:0 -o ignore -e ignore -x \
+ "cd tmp && ./${h} -s $(pwd)/tmp \
+ srcdir_exists"
+ atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res srcdir_exists
+ atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
+ atf_check -s eq:0 -o ignore -e ignore \
+ "${hp}" -s "$(pwd)"/tmp srcdir_exists
+ done
+}
+
+atf_test_case relative
+relative_head()
+{
+ atf_set "descr" "Checks that passing a relative path through -s" \
+ "works"
+}
+relative_body()
+{
+ create_files
+
+ for hp in $(get_helpers); do
+ h=${hp##*/}
+ cp ${hp} tmp
+
+ for p in tmp tmp/. ./tmp; do
+ echo "Helper is: ${h}"
+ echo "Using source directory: ${p}"
+
+ atf_check -s eq:0 -o ignore -e ignore \
+ "./tmp/${h}" -s "${p}" srcdir_exists
+ atf_check -s eq:1 -o empty -e save:stderr "${hp}" -r res \
+ srcdir_exists
+ atf_check -s eq:0 -o ignore -e empty grep "Cannot find datafile" res
+ atf_check -s eq:0 -o ignore -e ignore \
+ "${hp}" -s "${p}" srcdir_exists
+ done
+ done
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case default
+ atf_add_test_case libtool
+ atf_add_test_case sflag
+ atf_add_test_case relative
+}
+
+# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4