Received: by mail.netbsd.org (Postfix, from userid 605) id E1EFF84DBB; Fri, 27 Mar 2020 22:56:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 6C90784DB8 for ; Fri, 27 Mar 2020 22:56:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id aoWrDYR-_A6e for ; Fri, 27 Mar 2020 22:56:30 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id 36FA984CEA for ; Fri, 27 Mar 2020 22:56:30 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 305F4FB27; Fri, 27 Mar 2020 22:56:30 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1585349790197000" MIME-Version: 1.0 Date: Fri, 27 Mar 2020 22:56:30 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc/regress/infra-unittests To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20200327225630.305F4FB27@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: pkgsrc-changes.NetBSD.org Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1585349790197000 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: rillig Date: Fri Mar 27 22:56:30 UTC 2020 Modified Files: pkgsrc/regress/infra-unittests: extract.sh mocked-include.sh subst.sh test.subr tools-bison.sh Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 pkgsrc/regress/infra-unittests/extract.sh \ pkgsrc/regress/infra-unittests/mocked-include.sh \ pkgsrc/regress/infra-unittests/tools-bison.sh cvs rdiff -u -r1.13 -r1.14 pkgsrc/regress/infra-unittests/subst.sh cvs rdiff -u -r1.8 -r1.9 pkgsrc/regress/infra-unittests/test.subr Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1585349790197000 Content-Disposition: inline Content-Length: 16719 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/regress/infra-unittests/extract.sh diff -u pkgsrc/regress/infra-unittests/extract.sh:1.2 pkgsrc/regress/infra-unittests/extract.sh:1.3 --- pkgsrc/regress/infra-unittests/extract.sh:1.2 Fri Mar 27 21:41:33 2020 +++ pkgsrc/regress/infra-unittests/extract.sh Fri Mar 27 22:56:29 2020 @@ -16,9 +16,6 @@ test_case_set_up() { 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 Index: pkgsrc/regress/infra-unittests/mocked-include.sh diff -u pkgsrc/regress/infra-unittests/mocked-include.sh:1.2 pkgsrc/regress/infra-unittests/mocked-include.sh:1.3 --- pkgsrc/regress/infra-unittests/mocked-include.sh:1.2 Fri Mar 20 08:56:42 2020 +++ pkgsrc/regress/infra-unittests/mocked-include.sh Fri Mar 27 22:56:29 2020 @@ -16,7 +16,7 @@ all: @echo 'the mocked definition wins' EOF - out=$(test_file "including.mk") + out=$(run_bmake "including.mk") assert_that "$out" --equals "the mocked definition wins" Index: pkgsrc/regress/infra-unittests/tools-bison.sh diff -u pkgsrc/regress/infra-unittests/tools-bison.sh:1.2 pkgsrc/regress/infra-unittests/tools-bison.sh:1.3 --- pkgsrc/regress/infra-unittests/tools-bison.sh:1.2 Fri Mar 20 08:56:42 2020 +++ pkgsrc/regress/infra-unittests/tools-bison.sh Fri Mar 27 22:56:29 2020 @@ -35,7 +35,7 @@ all: .include "mk/tools/bison.mk" EOF - out=$(test_file "multiple-reqd-entries.mk") + out=$(run_bmake "multiple-reqd-entries.mk") assert_that "$out" --equals "yes" @@ -63,7 +63,7 @@ all: .include "mk/tools/bison.mk" EOF - out=$(test_file "multiple-reqd-entries.mk") + out=$(run_bmake "multiple-reqd-entries.mk") assert_that "$out" --equals "no" Index: pkgsrc/regress/infra-unittests/subst.sh diff -u pkgsrc/regress/infra-unittests/subst.sh:1.13 pkgsrc/regress/infra-unittests/subst.sh:1.14 --- pkgsrc/regress/infra-unittests/subst.sh:1.13 Sun Mar 22 13:19:50 2020 +++ pkgsrc/regress/infra-unittests/subst.sh Fri Mar 27 22:56:29 2020 @@ -33,7 +33,7 @@ STEP_MSG= echo "=>" 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 @@ EOF 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 @@ EOF 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 @@ EOF 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 @@ EOF 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 @@ EOF 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 @@ EOF 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 @@ SUBST_NOOP_OK.class= no 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 @@ SUBST_NOOP_OK.class= yes 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 @@ EOF 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 @@ SUBST_SED.class= -e 'sahara' .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 @@ EOF 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 @@ prepare-subst-class: \${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 @@ EOF 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 @@ EOF 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 @@ all: .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 @@ SUBST_SED.three= -e 's,three,III,' .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 @@ SUBST_SHOW_DIFF.two= yes 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 @@ SUBST_SHOW_DIFF= yes .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 @@ if test_case_begin "SUBST_VARS"; then "@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 @@ if test_case_begin "SUBST_VARS with surr "@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 @@ if test_case_begin "SUBST_VARS with back '.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 @@ if test_case_begin "SUBST_VARS for varia "@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 @@ if test_case_begin "pattern matches dire 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 @@ if test_case_begin "pattern matches only 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=$? Index: pkgsrc/regress/infra-unittests/test.subr diff -u pkgsrc/regress/infra-unittests/test.subr:1.8 pkgsrc/regress/infra-unittests/test.subr:1.9 --- pkgsrc/regress/infra-unittests/test.subr:1.8 Fri Mar 27 21:41:33 2020 +++ pkgsrc/regress/infra-unittests/test.subr Fri Mar 27 22:56:29 2020 @@ -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: # -# cleanup -# If yes (the default), clean up the temporary directory -# after the test has run successfully. -# -# It defines the following shell functions: -# -# 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: -# -# hello=$(mock_cmd mock-hello \ -# --when-args "" --then-output "Hello, world!" \ -# --when-args "-t" --then-output "hello, world" \ -# --when-args "-?" --then-exit 1 -# ) -# -# create_file $filename <&2 exit 1 -} +fi verbose_printf() { $if_verbose printf "$@" @@ -128,7 +192,9 @@ mock_cmd() { shift 1 { - printf '#! /bin/sh\n\n' + printf '#! /bin/sh\n' + printf '\n' + while [ $# -ge 4 ]; do case $1,$3 in (--when-args,--then-output) @@ -151,7 +217,7 @@ EOF esac done cat <&2 +printf 'error: %s: no mock behavior defined for arguments "%s"\n' "\$0" "\$*" 1>&2 exit 1 EOF } > "$tmpdir/$cmdname" @@ -177,11 +243,11 @@ create_pkgsrc_file() { cat > "$mocked_pkgsrcdir/$1" } -test_file() { +run_bmake() { cat < "$tmpdir/test.subr.main.mk" -PKGSRCDIR= $real_pkgsrcdir +PKGSRCDIR= $relative_pkgsrcdir .PATH: $mocked_pkgsrcdir -.PATH: $real_pkgsrcdir +.PATH: $pkgsrcdir .include "$1" EOF shift --_----------=_1585349790197000--