pkgsrc-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: rewri...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5df07852c26f
branches:  trunk
changeset: 414470:5df07852c26f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Mar 27 22:56:29 2020 +0000

description:
regress/infra-unittests: rewrite documentation, adjust code a little

The documentation now starts with a high-level introduction instead of
listing only the details.

The name of the function test_file had to be changed since the old name
was not expressive enough. Same for the variable real_pkgsrcdir.

diffstat:

 regress/infra-unittests/extract.sh        |    3 -
 regress/infra-unittests/mocked-include.sh |    2 +-
 regress/infra-unittests/subst.sh          |   50 ++++----
 regress/infra-unittests/test.subr         |  166 ++++++++++++++++++++---------
 regress/infra-unittests/tools-bison.sh    |    4 +-
 5 files changed, 144 insertions(+), 81 deletions(-)

diffs (truncated from 494 to 300 lines):

diff -r 0d98aeffa662 -r 5df07852c26f regress/infra-unittests/extract.sh
--- a/regress/infra-unittests/extract.sh        Fri Mar 27 21:41:33 2020 +0000
+++ b/regress/infra-unittests/extract.sh        Fri Mar 27 22:56:29 2020 +0000
@@ -16,9 +16,6 @@
        export LC_ALL
 }
 
-# XXX: This definition should be available everywhere.
-pkgsrcdir="`cd "$real_pkgsrcdir" && exec pwd`"
-
 if test_case_begin "exclude directory by basename"; then
 
        # Demonstrates that excluding a directory name also excludes that
diff -r 0d98aeffa662 -r 5df07852c26f regress/infra-unittests/mocked-include.sh
--- a/regress/infra-unittests/mocked-include.sh Fri Mar 27 21:41:33 2020 +0000
+++ b/regress/infra-unittests/mocked-include.sh Fri Mar 27 22:56:29 2020 +0000
@@ -16,7 +16,7 @@
        @echo 'the mocked definition wins'
 EOF
 
-       out=$(test_file "including.mk")
+       out=$(run_bmake "including.mk")
 
        assert_that "$out" --equals "the mocked definition wins"
 
diff -r 0d98aeffa662 -r 5df07852c26f regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Fri Mar 27 21:41:33 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Fri Mar 27 22:56:29 2020 +0000
@@ -33,7 +33,7 @@
 DO_NADA=       : do-nada
 INFO_MSG=      echo "info:"
 WARNING_MSG=   echo "warning:"
-FAIL_MSG=      sh $PWD/$real_pkgsrcdir/mk/scripts/fail echo "fail:"
+FAIL_MSG=      sh $pkgsrcdir/mk/scripts/fail echo "fail:"
 
 WRKDIR=                $tmpdir
 WRKSRC=                $tmpdir
@@ -60,7 +60,7 @@
        create_file_lines "subst-single.txt" \
                "before"
 
-       test_file "subst-single.mk" > "$tmpdir/output"
+       run_bmake "subst-single.mk" > "$tmpdir/output"
 
        assert_that "output" --file-contains-exactly "=> Substituting \"class\" in subst-single.txt"
        assert_that "subst-single.txt" --file-contains-exactly "after"
@@ -89,7 +89,7 @@
        create_file_lines "second"      "the second file"
        create_file_lines "third"       "the third file"
 
-       output=$(test_file "testcase.mk")
+       output=$(run_bmake "testcase.mk")
 
        assert_that "$output" --equals "=> Substituting \"class\" in first second third"
        assert_that "first" --file-contains-exactly "the first example"
@@ -121,7 +121,7 @@
        create_file_lines "pattern-second"      "the second file"
        create_file_lines "pattern-third"       "the third file"
 
-       output=$(test_file "testcase.mk")
+       output=$(run_bmake "testcase.mk")
 
        assert_that "$output" --equals "=> Substituting \"class\" in pattern-*"
        assert_that "pattern-first" --file-contains-exactly "the first example"
@@ -157,7 +157,7 @@
        create_file_lines "pattern-second"      "the second is already an example"
        create_file_lines "pattern-third"       "the third file"
 
-       test_file "testcase.mk" > "$tmpdir/actual-output"
+       run_bmake "testcase.mk" > "$tmpdir/actual-output"
        create_file_lines "expected-output" \
                '=> Substituting "class" in pattern-*' \
                'info: [subst.mk:class] Nothing changed in ./pattern-second.'
@@ -188,7 +188,7 @@
 
        create_file_lines "single"      "already an example"
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in single' \
@@ -218,7 +218,7 @@
 
        create_file_lines "single"      "already an example"
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in single' \
@@ -251,7 +251,7 @@
 all: subst-class
 EOF
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in nonexistent' \
@@ -283,7 +283,7 @@
 all: subst-class
 EOF
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in nonexistent' \
@@ -311,7 +311,7 @@
 
        create_file_lines "exists"      "this file exists"
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in *exist* *not-found*' \
@@ -336,7 +336,7 @@
 .include "mk/subst.mk"
 EOF
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in does not exist' \
@@ -365,7 +365,7 @@
        create_file_lines "second"      "second"
        create_file_lines "third"       "third"
 
-       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in first second third' \
@@ -410,7 +410,7 @@
        \${RUN} \${ECHO} "from" > "\${WRKSRC}/third"
 EOF
 
-       test_file "testcase.mk" "subst-class" \
+       run_bmake "testcase.mk" "subst-class" \
                1> "$tmpdir/actual-output" \
                2> "$tmpdir/actual-stderr" \
        && exitcode=0 || exitcode=$?
@@ -450,7 +450,7 @@
        create_file_lines "--no-option"         "before"
        create_file_lines ".hidden"             "before"
 
-       test_file "testcase.mk" "subst-class" \
+       run_bmake "testcase.mk" "subst-class" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -494,7 +494,7 @@
        create_file_lines "*"   "before"
        create_file_lines "[*]" "before"
 
-       test_file "testcase.mk" "subst-class" \
+       run_bmake "testcase.mk" "subst-class" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -527,7 +527,7 @@
 .include "mk/subst.mk"
 EOF
 
-       test_file "testcase.mk" "all" \
+       run_bmake "testcase.mk" "all" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -568,7 +568,7 @@
 .include "mk/subst.mk"
 EOF
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -604,7 +604,7 @@
 EOF
 
        LC_ALL=C \
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -644,7 +644,7 @@
 .include "mk/subst.mk"
 EOF
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -695,7 +695,7 @@
                "@PRINTABLE@" \
                "@UNDEFINED@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -740,7 +740,7 @@
                "@TAB@" \
                "@NEWLINE@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -776,7 +776,7 @@
                '.include "mk/subst.mk"'
        create_file_lines "backslash.txt" "@BACKSLASHES@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -818,7 +818,7 @@
                "@VAR.<>@" \
                "@VAR.[]@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -865,7 +865,7 @@
        create_file_lines "subst-file" \
                "@VAR@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
@@ -905,7 +905,7 @@
        create_file_lines "subdir/subfile" \
                "@VAR@"
 
-       test_file "testcase.mk" "pre-configure" \
+       run_bmake "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
        && exitcode=0 || exitcode=$?
diff -r 0d98aeffa662 -r 5df07852c26f regress/infra-unittests/test.subr
--- a/regress/infra-unittests/test.subr Fri Mar 27 21:41:33 2020 +0000
+++ b/regress/infra-unittests/test.subr Fri Mar 27 22:56:29 2020 +0000
@@ -1,56 +1,118 @@
 #! /bin/sh
-# $NetBSD: test.subr,v 1.8 2020/03/27 21:41:33 rillig Exp $
+# $NetBSD: test.subr,v 1.9 2020/03/27 22:56:29 rillig Exp $
 set -eu
 
-# This file defines utilities for testing Makefile fragments in a mocked
-# environment. It is used primarily to test the pkgsrc infrastructure.
+# This file defines utilities for testing Makefile fragments and shell
+# programs from the pkgsrc infrastructure. While testing one part of the
+# infrastructure, other parts can be mocked away.
 #
-# It defines the following shell variables:
+# A test case is defined by the following functions:
+#
+#      test_case_begin
+#      test_case_set_up
+#      test_case_tear_down
+#      test_case_end
 #
-#      cleanup
-#              If yes (the default), clean up the temporary directory
-#              after the test has run successfully.
+# These functions form the structure for a test. To define a test, use the
+# following pattern:
 #
-# It defines the following shell functions:
+#      if test_case_begin "description of the test"; then
+#              ...
+#              test_end
+#      fi
+#
+# The functions test_case_set_up and test_case_tear_down can be defined in the
+# test file to provide a test fixture that is common to all test cases. These
+# functions are called by test_case_begin and test_case_end, respectively.
+#
+# During a test case, the following variables are defined:
 #
-#      mock_cmd
-#              Returns the path to a newly created shell program whose
-#              behavior (output and exit status) is specified by pairs
-#              of --when-args/--then-output or --when-args/--then-exit.
-#              Example:
+#      tmpdir          a directory for creating intermediate files



Home | Main Index | Thread Index | Old Index