Module Name:    src
Committed By:   rillig
Date:           Sat Jul 25 21:19:29 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: Makefile
Added Files:
        src/usr.bin/make/unit-tests: envfirst.exp envfirst.mk vardebug.exp
            vardebug.mk varfind.exp varfind.mk

Log Message:
make(1): add tests for previously uncovered code


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/envfirst.exp \
    src/usr.bin/make/unit-tests/envfirst.mk \
    src/usr.bin/make/unit-tests/vardebug.exp \
    src/usr.bin/make/unit-tests/vardebug.mk \
    src/usr.bin/make/unit-tests/varfind.exp \
    src/usr.bin/make/unit-tests/varfind.mk

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

Modified files:

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.63 src/usr.bin/make/unit-tests/Makefile:1.64
--- src/usr.bin/make/unit-tests/Makefile:1.63	Thu Jul  9 22:40:14 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sat Jul 25 21:19:29 2020
@@ -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+=		cond2
 TESTS+=		dollar
 TESTS+=		doterror
 TESTS+=		dotwait
+TESTS+=		envfirst
 TESTS+=		error
 TESTS+=		# escape	# broken by reverting POSIX changes
 TESTS+=		export
@@ -67,20 +68,30 @@ TESTS+=		ternary
 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 @@ LANG=		C
 # 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 @@ _SED_CMDS+=	-e 's,${UNIT_TESTS:S,.,\\.,g
 .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

Added files:

Index: src/usr.bin/make/unit-tests/envfirst.exp
diff -u /dev/null src/usr.bin/make/unit-tests/envfirst.exp:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/envfirst.exp	Sat Jul 25 21:19:29 2020
@@ -0,0 +1 @@
+exit status 0
Index: src/usr.bin/make/unit-tests/envfirst.mk
diff -u /dev/null src/usr.bin/make/unit-tests/envfirst.mk:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/envfirst.mk	Sat Jul 25 21:19:29 2020
@@ -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
Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u /dev/null src/usr.bin/make/unit-tests/vardebug.exp:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/vardebug.exp	Sat Jul 25 21:19:29 2020
@@ -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
Index: src/usr.bin/make/unit-tests/vardebug.mk
diff -u /dev/null src/usr.bin/make/unit-tests/vardebug.mk:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/vardebug.mk	Sat Jul 25 21:19:29 2020
@@ -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:
+	@:
Index: src/usr.bin/make/unit-tests/varfind.exp
diff -u /dev/null src/usr.bin/make/unit-tests/varfind.exp:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/varfind.exp	Sat Jul 25 21:19:29 2020
@@ -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
Index: src/usr.bin/make/unit-tests/varfind.mk
diff -u /dev/null src/usr.bin/make/unit-tests/varfind.mk:1.1
--- /dev/null	Sat Jul 25 21:19:29 2020
+++ src/usr.bin/make/unit-tests/varfind.mk	Sat Jul 25 21:19:29 2020
@@ -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}

Reply via email to