Skip to content

Commit f8bb87a

Browse files
author
daniel
committed
introduce "musthave" files, so tests can easily check for HAVE_* prerequisites from config.h
1 parent f29698b commit f8bb87a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

docs/src/code/writing-tests.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ checkresult::
7979
At the moment, the use of _sudo_ can be flagged, and tests requiring sudo can be skipped when using `runtests -u`.
8080
To flag such requirements, add a line with `Restrictions: sudo` to this file.
8181

82+
musthave::
83+
This file can contain a list of prerequisites from config.h (one per line). If it's not met, the test will be skipped.
84+
e.g. if your test depends on config.h having `#define HAVE_TK_H 1` and `#define HAVE_LIBMODBUS3 yes`, add a line with
85+
`TK_H` and a line with `LIBMODBUS3` to this file.
86+
8287
== Some testing approaches
8388

8489
There are various ways to structure a test, depending on what one wants to test.

scripts/runtests.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ run_tests () {
126126

127127
while read testname; do
128128
testdir=$(dirname $testname)
129+
# check if there's a "musthave" file with prerequisites from config.h
130+
if [ -e $testdir/musthave ] ; then
131+
# one prerequisite per line
132+
while IFS= read -r prereq ; do
133+
if ! grep --quiet --regexp "^#define HAVE_$prereq.*" "$TOPDIR/src/config.h" ; then
134+
echo "Skipping test for missing prerequisite \"$prereq\": $testdir" 1>&2
135+
SKIP=$(($SKIP+1))
136+
continue 3
137+
fi
138+
done < $testdir/musthave
139+
fi
140+
# skip test if there's a "skip" file
129141
if [ -e $testdir/skip ]; then
130142
if ! [ -x $testdir/skip ] || ! $testdir/skip; then
131143
echo "Skipping disabled test: $testdir" 1>&2

0 commit comments

Comments
 (0)