Skip to content

Commit 30ae7b2

Browse files
authored
Merge pull request #2710 from heeplr/fix-tests
Fix tests
2 parents a69e45a + 9739d4d commit 30ae7b2

6 files changed

Lines changed: 26 additions & 4 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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,23 @@ run_tests () {
176176
find "$*" -name test.hal -or -name test.sh -or -name test \
177177
| sort > "$TMPDIR/alltests"
178178

179-
while read -r testname; do
180-
testdir=$(dirname "$testname")
181-
if [ -e "$testdir/skip" ]; then
182-
if ! [ -x "$testdir/skip" ] || ! "$testdir/skip"; then
179+
while read testname; do
180+
testdir=$(dirname $testname)
181+
# check if there's a "musthave" file with prerequisites from config.h
182+
if [ -e $testdir/musthave ] ; then
183+
# one prerequisite per line
184+
while IFS= read -r prereq ; do
185+
if ! grep --quiet --regexp "^#define HAVE_$prereq.*" "$TOPDIR/src/config.h" ; then
186+
echo "Skipping test for missing prerequisite \"$prereq\": $testdir" 1>&2
187+
SKIP=$(($SKIP+1))
188+
continue 3
189+
fi
190+
done < $testdir/musthave
191+
fi
192+
# skip test if there's a "skip" file
193+
if [ -e $testdir/skip ]; then
194+
if ! [ -x $testdir/skip ] || ! $testdir/skip; then
195+
183196
echo "Skipping disabled test: $testdir" 1>&2
184197
SKIP=$((SKIP + 1))
185198
continue

tests/mb2hal/mb2hal.1a/musthave

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBMODBUS3

tests/mb2hal/mb2hal.1b/musthave

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBMODBUS3

tests/mb2hal/mb2hal.2a/musthave

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBMODBUS3

tests/mb2hal/mb2hal.2b/musthave

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LIBMODBUS3

0 commit comments

Comments
 (0)