Skip to content

Commit

Permalink
introduce "musthave" files, so tests can easily check for HAVE_* prer…
Browse files Browse the repository at this point in the history
…equisites from config.h
  • Loading branch information
daniel committed Mar 17, 2024
1 parent f29698b commit f8bb87a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/src/code/writing-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions scripts/runtests.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f8bb87a

Please sign in to comment.