]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
meson: tests/config - use script to prepare workdir
authorTomas Krizek <tomas.krizek@nic.cz>
Fri, 1 Feb 2019 12:13:26 +0000 (13:13 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Mar 2019 09:41:54 +0000 (10:41 +0100)
scripts/test-config.sh [new file with mode: 0755]
tests/config/meson.build
tests/config/runtest.sh [deleted file]

diff --git a/scripts/test-config.sh b/scripts/test-config.sh
new file mode 100755 (executable)
index 0000000..1774e14
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Utility script used by meson to run config tests post installation
+set -o nounset -o errexit
+
+# if anything fails during test setup, use exit code 77 to mark it as skipped
+function skip {
+    exit 77
+}
+trap skip ERR
+
+TEST_DIR="$(dirname ${TEST_FILE})"
+TMP_RUNDIR="$(mktemp -d)"
+
+function finish {
+    rm -rf "${TMP_RUNDIR}"
+}
+trap finish EXIT
+
+cp -a "${TEST_DIR}/"* "${TMP_RUNDIR}/"
+cd "${TMP_RUNDIR}"
+
+test -x "${KRESD_EXEC}" || (echo "${KRESD_EXEC} not executable!"; exit 77)
+trap ERR  # get actual kresd error code from now on
+
+${KRESD_EXEC} "$@"
index 8b2fc1a927cf0b3bb5ed73bc240e353a58175466..4d6193d53a158cd0e093c4813e79ed4748ed3c42 100644 (file)
@@ -24,29 +24,8 @@ config_tests += [
 
 
 if get_option('daemon')
+  run_configtest = find_program('../../scripts/test-config.sh')
   foreach config_test : config_tests
-    conftest_dir = join_paths(meson.current_build_dir(), config_test[0])
-
-    testdir_clean = custom_target(
-      'config.' + config_test[0] + ': clean testdir',
-      command: [
-       'rm', '-r', '-f', conftest_dir,
-      ],
-      output: config_test[0] + '.rm',
-      build_by_default: false,
-    )
-
-    testdir_create = custom_target(
-      'config.' + config_test[0] + ': create testdir',
-      command: [
-       'mkdir', conftest_dir,
-      ],
-      depends: testdir_clean,
-      output: config_test[0],
-      build_always_stale: true,  # make sure to always recreate dir
-      build_by_default: false,
-    )
-
     # kresd arguments
     conftest_args = [
       '-c', files('test.cfg'),
@@ -61,16 +40,18 @@ if get_option('daemon')
 
     test(
       'config.' + config_test[0],
-      kresd,
+      run_configtest,
       args: conftest_args,
       env: [
        'KRESD_NO_LISTEN=1',
        'SOURCE_PATH=@0@'.format(meson.current_source_dir()),
        'TEST_FILE=@0@/@1@'.format(meson.source_root(), config_test[1][0]),
+       'KRESD_EXEC=@0@'.format(kresd_install_path),
+      ],
+      suite: [
+       'postinstall',
+       'config',
       ],
-      suite: 'config',
-      workdir: join_paths(meson.current_build_dir(), config_test[0]),
-      depends: testdir_create,
       should_fail: conftest_should_fail,
     )
   endforeach
diff --git a/tests/config/runtest.sh b/tests/config/runtest.sh
deleted file mode 100755 (executable)
index 11d9b46..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash -e
-export SOURCE_PATH="$(cd "$(dirname "$0")" && pwd -P)"
-export TEST_FILE="${2}"
-TEST_DIR="$(dirname $TEST_FILE)"
-export TMP_RUNDIR="$(mktemp -d)"
-export KRESD_NO_LISTEN=1
-function finish {
-       rm -rf "${TMP_RUNDIR}"
-}
-trap finish EXIT
-
-
-echo "# $(basename ${TEST_FILE})"
-cp -a "${TEST_DIR}/"* "${TMP_RUNDIR}/"
-CMDLINE_ARGS="$(cat "${TEST_FILE%.test.lua}.args" 2>/dev/null || echo "")"
-EXPECTED_RETURNCODE="$(cat "${TEST_FILE%.test.lua}.returncode" 2>/dev/null || echo 0)"
-set +e
-${DEBUGGER} ${1} -f 1 -c ${SOURCE_PATH}/test.cfg $CMDLINE_ARGS "${TMP_RUNDIR}"
-RETCODE="$?"
-if [ "$RETCODE" -ne "$EXPECTED_RETURNCODE" ]; then
-       echo "Expected return code '$EXPECTED_RETURNCODE' got '$RETCODE'."
-fi
-test "$RETCODE" -eq "$EXPECTED_RETURNCODE"