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: add t...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/919a10f7f1e2
branches:  trunk
changeset: 425137:919a10f7f1e2
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Mar 19 16:58:35 2020 +0000

description:
regress/infra-unittests: add tests for mk/subst.mk

diffstat:

 regress/infra-unittests/spec      |    7 +-
 regress/infra-unittests/subst.sh  |  307 ++++++++++++++++++++++++++++++++++++++
 regress/infra-unittests/test.subr |   36 +++-
 3 files changed, 343 insertions(+), 7 deletions(-)

diffs (truncated from 410 to 300 lines):

diff -r 5ad5f01db77e -r 919a10f7f1e2 regress/infra-unittests/spec
--- a/regress/infra-unittests/spec      Thu Mar 19 16:57:35 2020 +0000
+++ b/regress/infra-unittests/spec      Thu Mar 19 16:58:35 2020 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: spec,v 1.1 2019/03/21 21:45:30 rillig Exp $
+# $NetBSD: spec,v 1.2 2020/03/19 16:58:35 rillig Exp $
 #
 # Unit tests for the pkgsrc infrastructure.
 
 do_test() {
-       sh ./mocked-include.sh || TEST_EXITSTATUS=$?
-       sh ./tools-bison.sh || TEST_EXITSTATUS=$?
+       for testfile in ./*.sh; do
+               sh "$testfile" || TEST_EXITSTATUS=$?
+       done
 }
 
 check_result() {
diff -r 5ad5f01db77e -r 919a10f7f1e2 regress/infra-unittests/subst.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/infra-unittests/subst.sh  Thu Mar 19 16:58:35 2020 +0000
@@ -0,0 +1,307 @@
+#! /bin/sh
+#
+# Tests for mk/subst.mk.
+#
+set -eu
+
+. "./test.subr"
+
+testcase() {
+       test_name="$1"
+
+       rm -rf "$tmpdir/".subst_*_done
+       rm -rf "$tmpdir"/*
+       ls -A "$tmpdir"
+
+       create_file "prepare-subst.mk" <<EOF
+
+# The tools that are used by subst.mk
+CHMOD=         chmod-is-not-used
+CMP=           cmp
+ECHO=          echo
+MV=            mv
+RM=            rm
+SED=           sed
+TEST=          test
+TOUCH=         touch
+TOUCH_FLAGS=   # none
+TR=            tr
+TRUE=          true
+
+# Commands that are specific to pkgsrc
+RUN=           @: set -x;
+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:"
+
+WRKDIR=                $tmpdir
+WRKSRC=                $tmpdir
+EOF
+}
+
+
+if testcase "single file"; then
+
+       # A single file is patched successfully.
+
+       create_file "subst-single.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     subst-single.txt
+SUBST_SED.class=       -e 's,before,after,'
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+
+all: subst-class
+EOF
+
+       create_file_lines "subst-single.txt" \
+               "before"
+
+       test_file "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"
+fi
+
+
+if testcase "several individual files"; then
+
+       # Several individual files are patched successfully.
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     first second third
+SUBST_SED.class=       -e 's,file,example,'
+
+.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"
+
+       output=$(test_file "testcase.mk")
+
+       assert_that "$output" --equals "=> Substituting \"class\" in first second third"
+       assert_that "first" --file-contains-exactly "the first example"
+       assert_that "second" --file-contains-exactly "the second example"
+       assert_that "third" --file-contains-exactly "the third example"
+fi
+
+
+if testcase "several files by pattern"; then
+
+       # Several files are patched successfully.
+       # The filenames are given by a pattern.
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     pattern-*
+SUBST_SED.class=       -e 's,file,example,'
+
+.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"
+
+       output=$(test_file "testcase.mk")
+
+       assert_that "$output" --equals "=> Substituting \"class\" in pattern-*"
+       assert_that "pattern-first" --file-contains-exactly "the first example"
+       assert_that "pattern-second" --file-contains-exactly "the second example"
+       assert_that "pattern-third" --file-contains-exactly "the third example"
+fi
+
+
+if testcase "pattern with 1 noop"; then
+
+       # Several files are given via a pattern.
+       # Most of the files are patched, but one stays the same.
+       # Since it is easier to give a too broad pattern like *.py
+       # than to exclude a few files from such a pattern,
+       # only an info is logged.
+       # This is not an error.
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     pattern-*
+SUBST_SED.class=       -e 's,file,example,'
+
+.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 is already an example"
+       create_file_lines "pattern-third"       "the third file"
+
+       test_file "testcase.mk" > "$tmpdir/actual-output"
+       create_file_lines "expected-output" \
+               '=> Substituting "class" in pattern-*' \
+               'info: [subst.mk:class] Nothing changed in ./pattern-second.'
+
+       assert_that "actual-output" --file-equals "expected-output"
+       assert_that "pattern-first" --file-contains-exactly "the first example"
+       assert_that "pattern-second" --file-contains-exactly "the second is already an example"
+       assert_that "pattern-third" --file-contains-exactly "the third example"
+fi
+
+
+if testcase "single file noop"; then
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     single
+SUBST_SED.class=       -e 's,file,example,'
+SUBST_NOOP_OK.class=   yes
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+
+all: subst-class
+EOF
+
+       create_file_lines "single"      "already an example"
+
+       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       assert_that "$exitcode" --equals "0"
+       create_file_lines "expected-output" \
+               '=> Substituting "class" in single' \
+               'info: [subst.mk:class] Nothing changed in ./single.'
+
+       assert_that "actual-output" --file-equals "expected-output"
+       assert_that "single" --file-contains-exactly "already an example"
+fi
+
+
+if testcase "single file noop ok"; then
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     single
+SUBST_SED.class=       -e 's,file,example,'
+SUBST_NOOP_OK.class=   no
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+
+all: subst-class
+EOF
+
+       create_file_lines "single"      "already an example"
+
+       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       assert_that "$exitcode" --equals "1"
+       create_file_lines "expected-output" \
+               '=> Substituting "class" in single' \
+               'info: [subst.mk:class] Nothing changed in ./single.' \
+               'fail: [subst.mk:class] The pattern single has no effect.' \
+               '*** Error code 1' \
+               '' \
+               'Stop.' \
+               "$make: stopped in $PWD"
+
+       assert_that "actual-output" --file-equals "expected-output"
+       assert_that "single" --file-contains-exactly "already an example"
+fi
+
+
+if testcase "single file nonexistent"; then
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     nonexistent
+SUBST_SED.class=       -e 's,file,example,'
+SUBST_NOOP_OK.class=   no
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+
+all: subst-class
+EOF
+
+       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       assert_that "$exitcode" --equals "1"
+       create_file_lines "expected-output" \
+               '=> Substituting "class" in nonexistent' \
+               'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".' \
+               'fail: [subst.mk:class] The pattern nonexistent has no effect.' \
+               '*** Error code 1' \
+               '' \
+               'Stop.' \
+               "$make: stopped in $PWD"
+
+       assert_that "actual-output" --file-equals "expected-output"
+fi
+
+
+if testcase "single file nonexistent ok"; then
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                class
+SUBST_STAGE.class=     pre-configure
+SUBST_FILES.class=     nonexistent
+SUBST_SED.class=       -e 's,file,example,'
+SUBST_NOOP_OK.class=   yes
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+
+all: subst-class
+EOF
+
+       test_file "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
+       assert_that "$exitcode" --equals "0"
+       create_file_lines "expected-output" \
+               '=> Substituting "class" in nonexistent' \
+               'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".'
+



Home | Main Index | Thread Index | Old Index