]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
convert resconf_test; remove ATF from lib/irs/tests
authorEvan Hunt <each@isc.org>
Wed, 24 Oct 2018 16:22:15 +0000 (09:22 -0700)
committerEvan Hunt <each@isc.org>
Thu, 15 Nov 2018 04:17:04 +0000 (20:17 -0800)
lib/irs/tests/Kyuafile
lib/irs/tests/Makefile.in
lib/irs/tests/resconf_test.c

index 4ef71369e9697653fe4883649f1f7074d9769098..466f1bff628f992f9bd6b4efa0a65b13cf30857b 100644 (file)
@@ -1,4 +1,4 @@
 syntax(2)
 test_suite('bind9')
 
-atf_test_program{name='resconf_test'}
+tap_test_program{name='resconf_test'}
index 021fee6fd20ffc528b84cacd058a0778ab39e248..bdf5f623311b95783386d2519101f77da51ef0ce 100644 (file)
@@ -27,10 +27,8 @@ ISCDEPLIBS = ../../isc/libisc.@A@
 IRSLIBS =      ../libirs.@A@
 IRSDEPLIBS =   ../libirs.@A@
 
-LIBS =         ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @ATFLIBS@
-
-CMOCKA_CFLAGS =        @CMOCKA_CFLAGS@
-CMOCKA_LIBS =  @CMOCKA_LIBS@
+CFLAGS =       @CFLAGS@ @CMOCKA_CFLAGS@
+LIBS =         ${IRSLIBS} ${CFGLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@ @CMOCKA_LIBS@
 
 OBJS =
 SRCS =         resconf_test.c
@@ -41,8 +39,8 @@ TARGETS =     resconf_test@EXEEXT@
 @BIND9_MAKE_RULES@
 
 resconf_test@EXEEXT@: resconf_test.@O@ ${CFGDEPLIBS} ${DNSDEPLIBS} ${IRSDEPLIBS} ${ISCDEPLIBS}
-       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
-                       resconf_test.@O@ ${LIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
+               ${LDFLAGS} -o $@ resconf_test.@O@ ${LIBS}
 
 unit::
        sh ${top_builddir}/unit/unittest.sh
index 23938d2e412cb7e9d6cf5f6a2e7f6c8593ff37d9..3afa82d267800dc956cbe3f7a05dec2d2f98e9e1 100644 (file)
 
 #include <config.h>
 
-#include <atf-c.h>
+#if HAVE_CMOCKA
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+#define UNIT_TESTING
+#include <cmocka.h>
+
 #include <isc/mem.h>
 #include <isc/util.h>
 
@@ -31,21 +38,19 @@ setup_test() {
        isc_result_t result;
 
        result = isc_mem_create(0, 0, &mctx);
-       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       assert_int_equal(result, ISC_R_SUCCESS);
 
        /*
-        * atf-run changes us to a /tmp directory, so tests
+        * the caller might run from another directory, but tests
         * that access test data files must first chdir to the proper
         * location.
         */
-       ATF_REQUIRE(chdir(TESTS) != -1);
+       assert_return_code(chdir(TESTS), 0);
 }
 
-ATF_TC(irs_resconf_load);
-ATF_TC_HEAD(irs_resconf_load, tc) {
-       atf_tc_set_md_var(tc, "descr", "irs_resconf_load");
-}
-ATF_TC_BODY(irs_resconf_load, tc) {
+/* test irs_resconf_load() */
+static void
+irs_resconf_load_test(void **state) {
        isc_result_t result;
        irs_resconf_t *resconf = NULL;
        unsigned int i;
@@ -110,33 +115,58 @@ ATF_TC_BODY(irs_resconf_load, tc) {
 
        };
 
-       UNUSED(tc);
+       UNUSED(state);
 
        setup_test();
 
        for (i = 0; i < sizeof(tests)/sizeof(tests[1]); i++) {
                result = irs_resconf_load(mctx, tests[i].file, &resconf);
-               ATF_CHECK_EQ_MSG(result, tests[i].loadres, "%s", tests[i].file);
-               if (result == ISC_R_SUCCESS)
-                       ATF_CHECK_MSG(resconf != NULL, "%s", tests[i].file);
-               else
-                       ATF_CHECK_MSG(resconf == NULL, "%s", tests[i].file);
+               if (result != tests[i].loadres) {
+                       fail_msg("# unexpected result %s loading %s",
+                                isc_result_totext(result), tests[i].file);
+               }
+
+               if (result == ISC_R_SUCCESS && resconf == NULL) {
+                       fail_msg("# NULL on success loading %s",
+                                tests[i].file);
+               } else if (result != ISC_R_SUCCESS && resconf != NULL) {
+                       fail_msg("# non-NULL on failure loading %s",
+                                tests[i].file);
+               }
+
                if (resconf != NULL && tests[i].check != NULL) {
                        result = (tests[i].check)(resconf);
-                       ATF_CHECK_EQ_MSG(result, tests[i].checkres, "%s",
+                       if (result != tests[i].checkres) {
+                               fail_msg("# unexpected result %s loading %s",
+                                        isc_result_totext(result),
                                         tests[i].file);
+                       }
                }
-               if (resconf != NULL)
+               if (resconf != NULL) {
                        irs_resconf_destroy(&resconf);
+               }
        }
 
        isc_mem_detach(&mctx);
 }
 
-/*
- * Main
- */
-ATF_TP_ADD_TCS(tp) {
-       ATF_TP_ADD_TC(tp, irs_resconf_load);
-       return (atf_no_error());
+int
+main(void) {
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(irs_resconf_load_test),
+       };
+
+       return (cmocka_run_group_tests(tests, NULL, NULL));
 }
+
+#else /* HAVE_CMOCKA */
+
+#include <stdio.h>
+
+int
+main(void) {
+       printf("1..0 # Skipped: cmocka not available\n");
+       return (0);
+}
+
+#endif