From f8bb87a4455a574b3b27c97f138295be458fef62 Mon Sep 17 00:00:00 2001 From: daniel Date: Sun, 17 Mar 2024 21:24:44 +0100 Subject: [PATCH] introduce "musthave" files, so tests can easily check for HAVE_* prerequisites from config.h --- docs/src/code/writing-tests.adoc | 5 +++++ scripts/runtests.in | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/src/code/writing-tests.adoc b/docs/src/code/writing-tests.adoc index d346b6cc974..c50061f1a4a 100644 --- a/docs/src/code/writing-tests.adoc +++ b/docs/src/code/writing-tests.adoc @@ -79,6 +79,11 @@ checkresult:: At the moment, the use of _sudo_ can be flagged, and tests requiring sudo can be skipped when using `runtests -u`. To flag such requirements, add a line with `Restrictions: sudo` to this file. + musthave:: + This file can contain a list of prerequisites from config.h (one per line). If it's not met, the test will be skipped. + e.g. if your test depends on config.h having `#define HAVE_TK_H 1` and `#define HAVE_LIBMODBUS3 yes`, add a line with + `TK_H` and a line with `LIBMODBUS3` to this file. + == Some testing approaches There are various ways to structure a test, depending on what one wants to test. diff --git a/scripts/runtests.in b/scripts/runtests.in index f7e95e37c39..49d2f2fe2fd 100755 --- a/scripts/runtests.in +++ b/scripts/runtests.in @@ -126,6 +126,18 @@ run_tests () { while read testname; do testdir=$(dirname $testname) + # check if there's a "musthave" file with prerequisites from config.h + if [ -e $testdir/musthave ] ; then + # one prerequisite per line + while IFS= read -r prereq ; do + if ! grep --quiet --regexp "^#define HAVE_$prereq.*" "$TOPDIR/src/config.h" ; then + echo "Skipping test for missing prerequisite \"$prereq\": $testdir" 1>&2 + SKIP=$(($SKIP+1)) + continue 3 + fi + done < $testdir/musthave + fi + # skip test if there's a "skip" file if [ -e $testdir/skip ]; then if ! [ -x $testdir/skip ] || ! $testdir/skip; then echo "Skipping disabled test: $testdir" 1>&2