pkgsrc-Changes archive

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

CVS commit: pkgsrc/regress



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat Mar 21 18:43:02 UTC 2020

Modified Files:
        pkgsrc/regress/infra-unittests: subst.sh test.subr
Removed Files:
        pkgsrc/regress/subst: Makefile PLIST spec
        pkgsrc/regress/subst/files: expected

Log Message:
regress: migrate SUBST test to the other SUBST tests

In the old test code, the input and output data for each test case were
in different files. This was too far apart to relate them. In addition,
all test cases were merged into a single big test, which made it hard to
tell the topics apart.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 pkgsrc/regress/infra-unittests/subst.sh
cvs rdiff -u -r1.5 -r1.6 pkgsrc/regress/infra-unittests/test.subr
cvs rdiff -u -r1.6 -r0 pkgsrc/regress/subst/Makefile
cvs rdiff -u -r1.2 -r0 pkgsrc/regress/subst/PLIST
cvs rdiff -u -r1.1 -r0 pkgsrc/regress/subst/spec
cvs rdiff -u -r1.2 -r0 pkgsrc/regress/subst/files/expected

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/regress/infra-unittests/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.10 pkgsrc/regress/infra-unittests/subst.sh:1.11
--- pkgsrc/regress/infra-unittests/subst.sh:1.10        Sat Mar 21 13:30:35 2020
+++ pkgsrc/regress/infra-unittests/subst.sh     Sat Mar 21 18:43:02 2020
@@ -644,7 +644,6 @@ SUBST_SHOW_DIFF=    yes
 .include "mk/subst.mk"
 EOF
 
-       LC_ALL=C \
        test_file "testcase.mk" "pre-configure" \
                1> "$tmpdir/stdout" \
                2> "$tmpdir/stderr" \
@@ -668,3 +667,174 @@ EOF
 
        test_case_end
 fi
+
+
+if test_case_begin "SUBST_VARS"; then
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        vars' \
+               'SUBST_STAGE.vars=      pre-configure' \
+               'SUBST_FILES.vars=      vars.txt' \
+               'SUBST_VARS.vars=       PLAIN DQUOT SQUOT DELIM PRINTABLE' \
+               'SUBST_VARS.vars+=      UNDEFINED' \
+               '' \
+               'PLAIN=         plain' \
+               'DQUOT=         "double   quoted"' \
+               'SQUOT=         '\''single   quoted'\''' \
+               'DELIM=         hello,   world' \
+               'PRINTABLE=     !"\#$$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
+               '#UNDEFINED=    # undefined' \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "vars.txt" \
+               "@PLAIN@" \
+               "@DQUOT@" \
+               "@SQUOT@" \
+               "@DELIM@" \
+               "@PRINTABLE@" \
+               "@UNDEFINED@"
+
+       test_file "testcase.mk" "pre-configure" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
+       && exitcode=0 || exitcode=$?
+
+       # The double quotes and single quotes are kept since the variables
+       # are treated as simple string variables, not as lists of shell
+       # words. In these string variables, the quotes are part of the value.
+       assert_that "vars.txt" --file-is-lines \
+               "plain" \
+               "\"double   quoted\"" \
+               "'single   quoted'" \
+               "hello,   world" \
+               '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
+               ""
+       assert_that "stdout" --file-is-lines \
+               "=> Substituting \"vars\" in vars.txt"
+       assert_that "stderr" --file-is-empty
+       assert_that "$exitcode" --equals 0
+
+       test_case_end
+fi
+
+if test_case_begin "SUBST_VARS with surrounding whitespace"; then
+
+       # Ensure that leading and trailing whitespace is preserved
+       # in the variable values.
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        vars' \
+               'SUBST_STAGE.vars=      pre-configure' \
+               'SUBST_FILES.vars=      vars.txt' \
+               'SUBST_VARS.vars=       SPACE TAB NEWLINE' \
+               '' \
+               'SPACE=                 ${:U }between spaces${:U }' \
+               'TAB=                   ${:U    }between tabs${:U       }' \
+               'NEWLINE=               ${.newline}between newlines${.newline}' \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "vars.txt" \
+               "@SPACE@" \
+               "@TAB@" \
+               "@NEWLINE@"
+
+       test_file "testcase.mk" "pre-configure" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
+       && exitcode=0 || exitcode=$?
+
+       space=' '
+       tab='   '
+       newline='
+'
+       assert_that "vars.txt" --file-is-lines \
+               "$space""between spaces""$space" \
+               "$tab""between tabs""$tab" \
+               "$newline""between newlines""$newline"
+       assert_that "stdout" --file-is-lines \
+               "=> Substituting \"vars\" in vars.txt"
+       assert_that "stderr" --file-is-empty
+       assert_that "$exitcode" --equals 0
+
+       test_case_end
+fi
+
+
+if test_case_begin "SUBST_VARS with backslashes"; then
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        bs' \
+               'SUBST_STAGE.bs=        pre-configure' \
+               'SUBST_FILES.bs=        backslash.txt' \
+               'SUBST_VARS.bs=         BACKSLASHES' \
+               '' \
+               'BACKSLASHES=   \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "backslash.txt" "@BACKSLASHES@"
+
+       test_file "testcase.mk" "pre-configure" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
+       && exitcode=0 || exitcode=$?
+
+       assert_that "backslash.txt" --file-is-lines \
+               '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$'
+       assert_that "stdout" --file-is-lines \
+               "=> Substituting \"bs\" in backslash.txt"
+       assert_that "stderr" --file-is-empty
+       assert_that "$exitcode" --equals 0
+
+       test_case_end
+fi
+
+
+if test_case_begin "SUBST_VARS for variables with regex characters"; then
+
+       # Ensure that special regex characters like dots and parentheses
+       # may appear in variable names and are properly escaped.
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        vars' \
+               'SUBST_STAGE.vars=      pre-configure' \
+               'SUBST_FILES.vars=      vars.txt' \
+               'SUBST_VARS.vars=       VAR...... VAR.abcde VAR.() VAR.<>' \
+               '' \
+               'VAR......=     dots' \
+               'VAR.abcde=     letters' \
+               'VAR.()=        parentheses' \
+               'VAR.<>=        angle brackets' \
+               'VAR.[]=        square brackets' \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "vars.txt" \
+               "@VAR......@" \
+               "@VAR.abcde@" \
+               "@VAR.()@" \
+               "@VAR.<>@" \
+               "@VAR.[]@"
+
+       test_file "testcase.mk" "pre-configure" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
+       && exitcode=0 || exitcode=$?
+
+       # TODO: Why are the angle brackets replaced, but not the parentheses
+       # and square brackets?
+       assert_that "vars.txt" --file-is-lines \
+               "dots" \
+               "letters" \
+               "@VAR.()@" \
+               "angle brackets" \
+               "@VAR.[]@"
+       assert_that "stdout" --file-is-lines \
+               "=> Substituting \"vars\" in vars.txt"
+       assert_that "stderr" --file-is-empty
+       assert_that "$exitcode" --equals 0
+
+       test_case_end
+fi

Index: pkgsrc/regress/infra-unittests/test.subr
diff -u pkgsrc/regress/infra-unittests/test.subr:1.5 pkgsrc/regress/infra-unittests/test.subr:1.6
--- pkgsrc/regress/infra-unittests/test.subr:1.5        Sat Mar 21 06:53:18 2020
+++ pkgsrc/regress/infra-unittests/test.subr    Sat Mar 21 18:43:02 2020
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: test.subr,v 1.5 2020/03/21 06:53:18 rillig Exp $
+# $NetBSD: test.subr,v 1.6 2020/03/21 18:43:02 rillig Exp $
 set -eu
 
 # This file defines utilities for testing Makefile fragments in a mocked
@@ -70,10 +70,18 @@ done
        exit 1
 }
 
+verbose_printf() {
+       $if_verbose printf "$@"
+}
+
 test_case_name="unknown test"
+test_case_begun=0
+test_case_ended=0
 
 test_case_begin() {
        test_case_name="$1"
+       test_case_begun="`expr "$test_case_begun" + 1`"
+       verbose_printf 'running test case "%s"\n' "$test_case_name"
 
        test_case_set_up
 }
@@ -89,6 +97,11 @@ test_case_tear_down() {
 test_case_end() {
        test_case_tear_down
 
+       test_case_ended="`expr "$test_case_ended" + 1`"
+       test "$test_case_ended" = "$test_case_begun" \
+       || assert_fail 'unbalanced test_case_begin (%d) and test_case_end (%d)\n' \
+               "$test_case_begun" "$test_case_ended"
+
        test_case_name="unknown test"
 }
 
@@ -101,7 +114,7 @@ test_subr_cleanup() {
 
        [ "$cleanup" = "yes" ] && rm -rf "$tmpdir"
 
-       $if_verbose printf '%s%d assertions succeeded, %d assertions failed\n' \
+       verbose_printf '%s%d assertions succeeded, %d failed\n' \
                "$assert_fail_sep" "$assert_succeeded" "$assert_failed"
 
        if [ "$assert_failed" != 0 ]; then



Home | Main Index | Thread Index | Old Index