Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/regress/infra-unittests regress/infra-unittests: clean...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/08b904c0ffa2
branches:  trunk
changeset: 431315:08b904c0ffa2
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue May 12 05:34:04 2020 +0000

description:
regress/infra-unittests: clean up test code, add portability

The test can now be run with bash and ksh as well.

Bash exits if a function call returns failure, the NetBSD /bin/sh
doesn't.  After reading POSIX, sections "2.9.1 Simple Commands" and "set
-e", I'm in favor of bash here.

Ksh exits in "set -eu" mode if "$@" is used but no arguments are given.

diffstat:

 regress/infra-unittests/subst.sh  |  152 ++++++++++++-------------------------
 regress/infra-unittests/test.subr |    4 +-
 2 files changed, 52 insertions(+), 104 deletions(-)

diffs (truncated from 470 to 300 lines):

diff -r e05bc3ff77fc -r 08b904c0ffa2 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Tue May 12 04:35:55 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Tue May 12 05:34:04 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: subst.sh,v 1.39 2020/05/12 04:35:55 rillig Exp $
+# $NetBSD: subst.sh,v 1.40 2020/05/12 05:34:04 rillig Exp $
 #
 # Tests for mk/subst.mk.
 #
@@ -36,7 +36,7 @@
                DO_NADA=        : do-nada
                INFO_MSG=       echo 'info:'
                WARNING_MSG=    echo 'warning:'
-               FAIL_MSG=       sh $pkgsrcdir/mk/scripts/fail echo 'fail:'
+               FAIL_MSG=       sh $pkgsrcdir/mk/scripts/fail echo 'fail:' 1>&2
 
                WRKDIR=         $tmpdir/wrkdir
                WRKSRC=         .
@@ -61,15 +61,12 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'subst-single.txt' \
                'before'
 
-       run_bmake 'testcase.mk' \
-               1> "$tmpdir/output" 2>&1 \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -93,15 +90,14 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'first'       'the first file'
        create_file_lines 'second'      'the second file'
        create_file_lines 'third'       'the third file'
 
-       run_bmake 'testcase.mk' > "$tmpdir/output"
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
+       && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in first second third'
@@ -126,17 +122,14 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'pattern-first'       'the first file'
        create_file_lines 'pattern-second'      'the second file'
        create_file_lines 'pattern-third'       'the third file'
 
-       run_bmake 'testcase.mk' \
-               1> "$tmpdir/output" 2>&1 \
-       && exitcode=0 || exitcode=1
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
+       && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in pattern-*'
@@ -173,7 +166,8 @@
        create_file_lines 'pattern-second'      'the second is already an example'
        create_file_lines 'pattern-third'       'the third file'
 
-       run_bmake 'testcase.mk' > "$tmpdir/output"
+       run_bmake 'testcase.mk' 1> "$tmpdir/output" \
+       && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in pattern-*' \
@@ -197,20 +191,17 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'single'      'already an example'
 
-       run_bmake 'testcase.mk' > "$tmpdir/output" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in single' \
                'info: [subst.mk:class] Nothing changed in "single".'
        assert_that 'single' --file-is-lines 'already an example'
-       assert_that "$exitcode" --equals '0'
 
        test_case_end
 fi
@@ -227,13 +218,11 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'single'      'already an example'
 
-       run_bmake 'testcase.mk' > "$tmpdir/output" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -262,11 +251,9 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
-       run_bmake 'testcase.mk' > "$tmpdir/output" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -294,11 +281,9 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
-       run_bmake 'testcase.mk' > "$tmpdir/output" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -320,13 +305,11 @@
 
                .include "prepare-subst.mk"
                .include "mk/subst.mk"
-
-               all: subst-class
        EOF
 
        create_file_lines 'exists'      'this file exists'
 
-       run_bmake 'testcase.mk' > "$tmpdir/output" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -425,8 +408,7 @@
        \${RUN} \${ECHO} 'from' > '\${WRKSRC}/third'
 EOF
 
-       run_bmake 'testcase.mk' 'subst-class' \
-               1> "$tmpdir/output" 2>&1 \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        assert_that "$tmpdir/output" --file-is-lines \
@@ -462,16 +444,12 @@
        create_file_lines '--no-option'         'before'
        create_file_lines '.hidden'             'before'
 
-       run_bmake 'testcase.mk' 'subst-class' \
-               1> "$tmpdir/stdout" \
-               2> "$tmpdir/stderr" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "$tmpdir/stdout" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in *' \
                'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".'
-       assert_that "$tmpdir/stderr" --file-is-empty
-       assert_that "$exitcode" --equals '0'
 
        assert_that     ' !"#$%&'\''()*+,-.'    --file-is-lines 'after'
        assert_that     '0123456789:;<=>?'      --file-is-lines 'after'
@@ -503,14 +481,11 @@
        create_file_lines '*'   'before'
        create_file_lines '[*]' 'before'
 
-       run_bmake 'testcase.mk' 'subst-class' \
-               1> "$tmpdir/stdout" \
-               2> "$tmpdir/stderr" \
+       run_bmake 'testcase.mk' 'subst-class' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
-       assert_that "$tmpdir/stdout" --file-is-lines \
+       assert_that "$tmpdir/output" --file-is-lines \
                '=> Substituting "class" in [*]'
-       assert_that "$tmpdir/stderr" --file-is-empty
        assert_that "$exitcode" --equals '0'
 
        assert_that 'any'       --file-is-lines 'before'
@@ -577,21 +552,17 @@
                .include "mk/subst.mk"
        EOF
 
-       run_bmake 'testcase.mk' 'pre-configure' \
-               1> "$tmpdir/stdout" \
-               2> "$tmpdir/stderr" \
+       run_bmake 'testcase.mk' 'pre-configure' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        # The order of the above output is not guaranteed.
-       LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted"
+       LC_ALL=C sort < "$tmpdir/output" > "$tmpdir/output-sorted"
 
        assert_that 'file' --file-is-lines 'zero I II III four'
-       assert_that "$tmpdir/stdout-sorted" --file-is-lines \
+       assert_that "$tmpdir/output-sorted" --file-is-lines \
                '=> Substituting "one" in file' \
                '=> Substituting "three" in file' \
                '=> Substituting "two" in file'
-       assert_that "$tmpdir/stderr" --file-is-empty
-       assert_that "$exitcode" --equals '0'
 
        test_case_end
 fi
@@ -613,16 +584,14 @@
        EOF
 
        LC_ALL=C \
-       run_bmake 'testcase.mk' 'pre-configure' \
-               1> "$tmpdir/stdout" \
-               2> "$tmpdir/stderr" \
+       run_bmake 'testcase.mk' 'pre-configure' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
-       < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
+       < "$tmpdir/output" > "$tmpdir/output-filtered"
 
        assert_that 'file' --file-is-lines 'one' 'II' 'three'
-       assert_that "$tmpdir/stdout-filtered" --file-is-lines \
+       assert_that "$tmpdir/output-filtered" --file-is-lines \
                '=> Substituting "two" in file' \
                '--- file (filtered timestamp)' \
                '+++ file.subst.sav (filtered timestamp)' \
@@ -631,8 +600,6 @@
                '-two' \
                '+II' \
                ' three'
-       assert_that "$tmpdir/stderr" --file-is-empty
-       assert_that "$exitcode" --equals '0'
 
        test_case_end
 fi
@@ -640,7 +607,10 @@
 
 if test_case_begin 'global show diff'; then
 
-       create_file_lines 'file' 'one' 'two' 'three'
+       create_file_lines 'file' \
+               'one' \
+               'two' \
+               'three'
 
        create_file 'testcase.mk' <<-EOF
                SUBST_CLASSES+=         two
@@ -653,16 +623,17 @@
                .include "mk/subst.mk"
        EOF
 
-       run_bmake 'testcase.mk' 'pre-configure' \
-               1> "$tmpdir/stdout" \
-               2> "$tmpdir/stderr" \
+       run_bmake 'testcase.mk' 'pre-configure' 1> "$tmpdir/output" 2>&1 \
        && exitcode=0 || exitcode=$?
 
        awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
-       < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
+       < "$tmpdir/output" > "$tmpdir/output-filtered"
 
-       assert_that 'file' --file-is-lines 'one' 'II' 'three'
-       assert_that "$tmpdir/stdout-filtered" --file-is-lines \
+       assert_that 'file' --file-is-lines \
+               'one' \
+               'II' \
+               'three'
+       assert_that "$tmpdir/output-filtered" --file-is-lines \
                '=> Substituting "two" in file' \
                '--- file (filtered timestamp)' \
                '+++ file.subst.sav (filtered timestamp)' \
@@ -671,8 +642,6 @@
                '-two' \



Home | Main Index | Thread Index | Old Index