Module Name:    src
Committed By:   rillig
Date:           Sun Aug 16 20:43:01 UTC 2020

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/usr.bin/make/unit-tests: Makefile varmod-order-shuffle.mk
            varmod-order.exp varmod-order.mk
Removed Files:
        src/usr.bin/make/unit-tests: modorder.exp modorder.mk

Log Message:
make(1): move tests for the :Ox modifier into separate file

The test has been extended by ensuring that the shuffled words are still
the same.  Comparing two shuffled lists is probabilistic, but comparing
their sorted results is not, therefore that's completely sensible to do.

When writing this test, by coincidence I discovered how to generate the
"Undefined variable" error message.  Unfortunately, the error message is
wrong since the variable NUMBERS is defined at that point.  In summary,
that error message is shown when it shouldn't, and when it should it is
not shown.  Still, I'm glad that I finally found it.


To generate a diff of this commit:
cvs rdiff -u -r1.891 -r1.892 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.99 -r1.100 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r1.3 -r0 src/usr.bin/make/unit-tests/modorder.exp
cvs rdiff -u -r1.4 -r0 src/usr.bin/make/unit-tests/modorder.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-order-shuffle.mk
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/varmod-order.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-order.mk

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.891 src/distrib/sets/lists/tests/mi:1.892
--- src/distrib/sets/lists/tests/mi:1.891	Sun Aug 16 20:03:52 2020
+++ src/distrib/sets/lists/tests/mi	Sun Aug 16 20:43:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.891 2020/08/16 20:03:52 rillig Exp $
+# $NetBSD: mi,v 1.892 2020/08/16 20:43:01 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4757,8 +4757,6 @@
 ./usr/tests/usr.bin/make/unit-tests/modmatch.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/modmisc.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/modmisc.mk	tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/modorder.exp	tests-usr.bin-tests	compattestfile,atf
-./usr/tests/usr.bin/make/unit-tests/modorder.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/modts.exp	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/modts.mk	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/make/unit-tests/modword.exp	tests-usr.bin-tests	compattestfile,atf

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.99 src/usr.bin/make/unit-tests/Makefile:1.100
--- src/usr.bin/make/unit-tests/Makefile:1.99	Sun Aug 16 20:03:53 2020
+++ src/usr.bin/make/unit-tests/Makefile	Sun Aug 16 20:43:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.99 2020/08/16 20:03:53 rillig Exp $
+# $NetBSD: Makefile,v 1.100 2020/08/16 20:43:01 rillig Exp $
 #
 # Unit tests for make(1)
 #
@@ -151,7 +151,6 @@ TESTS+=		misc
 TESTS+=		moderrs
 TESTS+=		modmatch
 TESTS+=		modmisc
-TESTS+=		modorder
 TESTS+=		modts
 TESTS+=		modword
 TESTS+=		opt

Index: src/usr.bin/make/unit-tests/varmod-order-shuffle.mk
diff -u src/usr.bin/make/unit-tests/varmod-order-shuffle.mk:1.2 src/usr.bin/make/unit-tests/varmod-order-shuffle.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-order-shuffle.mk:1.2	Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varmod-order-shuffle.mk	Sun Aug 16 20:43:01 2020
@@ -1,9 +1,39 @@
-# $NetBSD: varmod-order-shuffle.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varmod-order-shuffle.mk,v 1.3 2020/08/16 20:43:01 rillig Exp $
 #
 # Tests for the :Ox variable modifier, which returns the words of the
 # variable, shuffled.
+#
+# As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
+# This makes the random numbers completely predictable since there is no other
+# part of make that uses random numbers.
+
+NUMBERS=	one two three four five six seven eight nine ten
+
+# Note that 1 in every 10! trials two independently generated
+# randomized orderings will be the same.  The test framework doesn't
+# support checking probabilistic output, so we accept that each of the
+# 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
+# lets the whole test fail once in 1.209.600 runs, on average.
+
+# Create two shuffles using the := assignment operator.
+shuffled1:=	${NUMBERS:Ox}
+shuffled2:=	${NUMBERS:Ox}
+.if ${shuffled1} == ${shuffled2}
+.error ${shuffled1} == ${shuffled2}
+.endif
+
+# Sorting the list before shuffling it has no effect.
+shuffled1:=	${NUMBERS:O:Ox}
+shuffled2:=	${NUMBERS:O:Ox}
+.if ${shuffled1} == ${shuffled2}
+.error ${shuffled1} == ${shuffled2}
+.endif
 
-# TODO: Implementation
+# Sorting after shuffling must produce the original numbers.
+sorted:=	${NUMBERS:Ox:O}
+.if ${sorted} != ${NUMBERS:O}
+.error ${sorted} != ${NUMBERS:O}
+.endif
 
 all:
 	@:;

Index: src/usr.bin/make/unit-tests/varmod-order.exp
diff -u src/usr.bin/make/unit-tests/varmod-order.exp:1.1 src/usr.bin/make/unit-tests/varmod-order.exp:1.2
--- src/usr.bin/make/unit-tests/varmod-order.exp:1.1	Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/varmod-order.exp	Sun Aug 16 20:43:01 2020
@@ -1 +1,7 @@
-exit status 0
+make: Bad modifier `:OX' for NUMBERS
+make: "varmod-order.mk" line 13: Undefined variable "${NUMBERS:OX"
+make: Bad modifier `:OxXX' for NUMBERS
+make: "varmod-order.mk" line 16: Undefined variable "${NUMBERS:Ox"
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/varmod-order.mk
diff -u src/usr.bin/make/unit-tests/varmod-order.mk:1.3 src/usr.bin/make/unit-tests/varmod-order.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-order.mk:1.3	Sun Aug 16 20:13:10 2020
+++ src/usr.bin/make/unit-tests/varmod-order.mk	Sun Aug 16 20:43:01 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-order.mk,v 1.3 2020/08/16 20:13:10 rillig Exp $
+# $NetBSD: varmod-order.mk,v 1.4 2020/08/16 20:43:01 rillig Exp $
 #
 # Tests for the :O variable modifier, which returns the words, sorted in
 # ascending order.
@@ -9,5 +9,11 @@ NUMBERS=	one two three four five six sev
 .error ${NUMBERS:O}
 .endif
 
+# Unknown modifier "OX"
+_:=	${NUMBERS:OX}
+
+# Unknown modifier "OxXX"
+_:=	${NUMBERS:OxXX}
+
 all:
 	@:;

Reply via email to