Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make/unit-tests make(1): add tests for previously un...



details:   https://anonhg.NetBSD.org/src/rev/9d71a927aee1
branches:  trunk
changeset: 936299:9d71a927aee1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 25 21:19:29 2020 +0000

description:
make(1): add tests for previously uncovered code

diffstat:

 usr.bin/make/unit-tests/Makefile     |  35 ++++++++++++++++++++-------
 usr.bin/make/unit-tests/envfirst.exp |   1 +
 usr.bin/make/unit-tests/envfirst.mk  |  35 +++++++++++++++++++++++++++
 usr.bin/make/unit-tests/vardebug.exp |  46 ++++++++++++++++++++++++++++++++++++
 usr.bin/make/unit-tests/vardebug.mk  |  41 ++++++++++++++++++++++++++++++++
 usr.bin/make/unit-tests/varfind.exp  |  15 +++++++++++
 usr.bin/make/unit-tests/varfind.mk   |  31 ++++++++++++++++++++++++
 7 files changed, 195 insertions(+), 9 deletions(-)

diffs (276 lines):

diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sat Jul 25 21:00:48 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sat Jul 25 21:19:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.63 2020/07/09 22:40:14 sjg Exp $
+# $NetBSD: Makefile,v 1.64 2020/07/25 21:19:29 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -38,6 +38,7 @@
 TESTS+=                dollar
 TESTS+=                doterror
 TESTS+=                dotwait
+TESTS+=                envfirst
 TESTS+=                error
 TESTS+=                # escape        # broken by reverting POSIX changes
 TESTS+=                export
@@ -67,20 +68,30 @@
 TESTS+=                unexport
 TESTS+=                unexport-env
 TESTS+=                varcmd
+TESTS+=                vardebug
+TESTS+=                varfind
 TESTS+=                varmisc
 TESTS+=                varmod-edge
 TESTS+=                varquote
 TESTS+=                varshell
 
-# Override make flags for certain tests; default is -k.
+# Override environment variables for some of the tests.
+ENV.envfirst=          FROM_ENV=value-from-env
+
+# Override make flags for some of the tests; default is -k.
 FLAGS.doterror=                # none
 FLAGS.order=           -j1
+FLAGS.envfirst=                -e
+FLAGS.vardebug=                -k -dv FROM_CMDLINE=
 
 # Some tests need extra post-processing.
 SED_CMDS.modmisc+=     -e 's,\(substitution error:\).*,\1 (details omitted),'
 SED_CMDS.varshell+=    -e 's,^[a-z]*sh: ,,'
 SED_CMDS.varshell+=    -e '/command/s,No such.*,not found,'
 
+# Some tests need an additional round of postprocessing.
+POSTPROC.vardebug=     ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p'
+
 # End of the configuration section.
 
 .MAIN: all
@@ -114,10 +125,14 @@
 # the tests are actually done with sub-makes.
 .SUFFIXES: .mk .rawout .out
 .mk.rawout:
-       @echo ${TEST_MAKE} ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC}
-       -@cd ${.OBJDIR} && \
-       { ${TEST_MAKE} ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
-         2>&1 ; echo $$? >${.TARGET:R}.status ; } > ${.TARGET}.tmp
+       @echo testing ${.IMPSRC}
+       @set -eu; \
+       cd ${.OBJDIR}; \
+       ${ENV.${.TARGET:R}} ${TEST_MAKE} \
+         ${FLAGS.${.TARGET:R}:U-k} -f ${.IMPSRC} \
+         > ${.TARGET}.tmp 2>&1 \
+       && status=$$? || status=$$?; \
+       echo $$status > ${.TARGET:R}.status
        @mv ${.TARGET}.tmp ${.TARGET}
 
 # Post-process the test output so that the results can be compared.
@@ -134,9 +149,11 @@
 .rawout.out:
        @echo postprocess ${.TARGET}
        @${TOOL_SED} ${_SED_CMDS} ${SED_CMDS.${.TARGET:R}} \
-         < ${.IMPSRC} > ${.TARGET}.tmp
-       @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp
-       @mv ${.TARGET}.tmp ${.TARGET}
+         < ${.IMPSRC} > ${.TARGET}.tmp1
+       @${POSTPROC.${.TARGET:R}:U${TOOL_SED}} < ${.TARGET}.tmp1 > ${.TARGET}.tmp2
+       @rm ${.TARGET}.tmp1
+       @echo "exit status `cat ${.TARGET:R}.status`" >> ${.TARGET}.tmp2
+       @mv ${.TARGET}.tmp2 ${.TARGET}
 
 # Compare all output files
 test:  ${OUTFILES} .PHONY
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/envfirst.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/envfirst.exp      Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,1 @@
+exit status 0
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/envfirst.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/envfirst.mk       Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,35 @@
+# $NetBSD: envfirst.mk,v 1.1 2020/07/25 21:19:29 rillig Exp $
+#
+# The -e option makes environment variables stronger than global variables.
+
+.if ${FROM_ENV} != value-from-env
+.error ${FROM_ENV}
+.endif
+
+# Try to override the variable; this does not have any effect.
+FROM_ENV=      value-from-mk
+.if ${FROM_ENV} != value-from-env
+.error ${FROM_ENV}
+.endif
+
+# Try to append to the variable; this also doesn't have any effect.
+FROM_ENV+=     appended
+.if ${FROM_ENV} != value-from-env
+.error ${FROM_ENV}
+.endif
+
+# The default assignment also cannot change the variable.
+FROM_ENV?=     default
+.if ${FROM_ENV} != value-from-env
+.error ${FROM_ENV}
+.endif
+
+# Neither can the assignment modifiers.
+.if ${FROM_ENV::=from-condition}
+.endif
+.if ${FROM_ENV} != value-from-env
+.error ${FROM_ENV}
+.endif
+
+all:
+       @: nothing
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/vardebug.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/vardebug.exp      Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,46 @@
+Global:RELEVANT = yes
+Global:VAR = added
+Global:VAR = overwritten
+Global:delete VAR
+Global:delete VAR (not found)
+Applying[] :U to ""
+Result[] of :U is ""
+Var_Set("${:U}", "empty name", ...) name expands to empty string - ignored
+Applying[] :U to ""
+Result[] of :U is ""
+Var_Append("${:U}", "empty name", ...) name expands to empty string - ignored
+Global:FROM_CMDLINE = overwritten ignored!
+Global:VAR = 1
+Global:VAR = 1 2
+Global:VAR = 1 2 3
+Applying[VAR] :M to "1 2 3"
+Pattern[VAR] for [1 2 3] is [[2]]
+ModifyWords: split "1 2 3" into 3 words
+VarMatch [1] [[2]]
+VarMatch [2] [[2]]
+VarMatch [3] [[2]]
+Result[VAR] of :M is "2"
+Applying[VAR] :N to "1 2 3"
+Pattern[VAR] for [1 2 3] is [[2]]
+ModifyWords: split "1 2 3" into 3 words
+Result[VAR] of :N is "1 3"
+Applying[VAR] :S to "1 2 3"
+Modifier part: "2"
+Modifier part: "two"
+ModifyWords: split "1 2 3" into 3 words
+Result[VAR] of :S is "1 two 3"
+Applying[VAR] :Q to "1 2 3"
+QuoteMeta: [1\ 2\ 3]
+Result[VAR] of :Q is "1\ 2\ 3"
+Applying[VAR] :t to "1 2 3"
+Result[VAR] of :t is "1 2 3"
+Applying[VAR] :t to "1 2 3"
+Result[VAR] of :t is "1 2 3"
+Applying[VAR] :Q to "1 2 3"
+QuoteMeta: [1\ 2\ 3]
+Result[VAR] of :Q is "1\ 2\ 3"
+Applying[] :U to ""
+Result[] of :U is "VAR"
+Global:delete VAR
+Global:RELEVANT = no
+exit status 0
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/vardebug.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/vardebug.mk       Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,41 @@
+# $NetBSD: vardebug.mk,v 1.1 2020/07/25 21:19:29 rillig Exp $
+#
+# Demonstrates the debugging output for var.c.
+
+RELEVANT=      yes
+
+VAR=           added           # VarAdd
+VAR=           overwritten     # Var_Set
+.undef VAR                     # Var_Delete (found)
+.undef VAR                     # Var_Delete (not found)
+
+# The variable with the empty name cannot be set at all.
+${:U}=         empty name      # Var_Set
+${:U}+=                empty name      # Var_Append
+
+FROM_CMDLINE=  overwritten     # Var_Set (ignored)
+
+VAR=           1
+VAR+=          2
+VAR+=          3
+
+.if ${VAR:M[2]}                        # VarMatch
+.endif
+.if ${VAR:N[2]}                        # VarNoMatch (no debug output)
+.endif
+
+.if ${VAR:S,2,two,}            # VarGetPattern
+.endif
+
+.if ${VAR:Q}                   # VarQuote
+.endif
+
+.if ${VAR:tu:tl:Q}             # ApplyModifiers
+.endif
+
+.undef ${:UVAR}                        # Var_Delete
+
+RELEVANT=      no
+
+all:
+       @:
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/varfind.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varfind.exp       Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,15 @@
+VarFind-aliases.to: long explicit-dependency VarFind-aliases.from
+VarFind-aliases.to: abbr explicit-dependency VarFind-aliases.from
+VarFind-aliases.to: long
+VarFind-aliases.to: abbr
+VarFind-aliases.to: long VarFind-aliases.from
+VarFind-aliases.to: abbr VarFind-aliases.from
+VarFind-aliases.to: long
+VarFind-aliases.to: abbr
+VarFind-aliases.to: long explicit-dependency VarFind-aliases.from
+VarFind-aliases.to: abbr explicit-dependency VarFind-aliases.from
+VarFind-aliases.to: long VarFind-aliases
+VarFind-aliases.to: abbr VarFind-aliases
+VarFind-aliases.to: long VarFind-aliases.to
+VarFind-aliases.to: abbr VarFind-aliases.to
+exit status 0
diff -r 188bd37870f1 -r 9d71a927aee1 usr.bin/make/unit-tests/varfind.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/make/unit-tests/varfind.mk        Sat Jul 25 21:19:29 2020 +0000
@@ -0,0 +1,31 @@
+# $NetBSD: varfind.mk,v 1.1 2020/07/25 21:19:29 rillig Exp $
+#
+# Demonstrates variable name aliases in VarFind.
+
+all: VarFind-aliases.to
+
+.SUFFIXES: .from .to
+
+VarFind-aliases.from:
+       @: do nothing
+
+VarFind-aliases.to: explicit-dependency
+
+explicit-dependency:
+       @: do nothing
+
+.from.to:
+       @echo $@: long ${.ALLSRC:Q}
+       @echo $@: abbr ${>:Q}
+       @echo $@: long ${.ARCHIVE:Q}
+       @echo $@: abbr ${!:Q}
+       @echo $@: long ${.IMPSRC:Q}
+       @echo $@: abbr ${<:Q}
+       @echo $@: long ${.MEMBER:Q}
+       @echo $@: abbr ${%:Q}
+       @echo $@: long ${.OODATE:Q}
+       @echo $@: abbr ${?:Q}
+       @echo $@: long ${.PREFIX:Q}
+       @echo $@: abbr ${*:Q}
+       @echo $@: long ${.TARGET:Q}
+       @echo $@: abbr ${@:Q}



Home | Main Index | Thread Index | Old Index