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): move tests for the :Ox modi...



details:   https://anonhg.NetBSD.org/src/rev/e4a6fbde2f28
branches:  trunk
changeset: 937370:e4a6fbde2f28
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 16 20:43:01 2020 +0000

description:
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.

diffstat:

 distrib/sets/lists/tests/mi                     |   4 +--
 usr.bin/make/unit-tests/Makefile                |   3 +-
 usr.bin/make/unit-tests/modorder.exp            |   9 ------
 usr.bin/make/unit-tests/modorder.mk             |  21 ---------------
 usr.bin/make/unit-tests/varmod-order-shuffle.mk |  34 +++++++++++++++++++++++-
 usr.bin/make/unit-tests/varmod-order.exp        |   8 +++++-
 usr.bin/make/unit-tests/varmod-order.mk         |   8 +++++-
 7 files changed, 48 insertions(+), 39 deletions(-)

diffs (151 lines):

diff -r 2bd43ab32239 -r e4a6fbde2f28 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Aug 16 20:13:10 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Aug 16 20:43:01 2020 +0000
@@ -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
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Sun Aug 16 20:13:10 2020 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Sun Aug 16 20:43:01 2020 +0000
@@ -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+=                moderrs
 TESTS+=                modmatch
 TESTS+=                modmisc
-TESTS+=                modorder
 TESTS+=                modts
 TESTS+=                modword
 TESTS+=                opt
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/modorder.exp
--- a/usr.bin/make/unit-tests/modorder.exp      Sun Aug 16 20:13:10 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-LIST:Ox   = Ok
-LIST:O:Ox = Ok
-LISTX     = Ok
-LISTSX    = Ok
-make: Bad modifier `:OX' for LIST
-BADMOD 1  = }
-make: Bad modifier `:OxXX' for LIST
-BADMOD 2  = XX}
-exit status 0
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/modorder.mk
--- a/usr.bin/make/unit-tests/modorder.mk       Sun Aug 16 20:13:10 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-# $NetBSD: modorder.mk,v 1.4 2020/08/16 20:13:10 rillig Exp $
-
-LIST=          one two three four five six seven eight nine ten
-LISTX=         ${LIST:Ox}
-LISTSX:=       ${LIST:Ox}
-TEST_RESULT= && echo Ok || echo Failed
-
-# unit-tests have to produce the same results on each run
-# so we cannot actually include :Ox output.
-all:
-       # 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.
-       @echo "LIST:Ox   = `test '${LIST:Ox}' != '${LIST:Ox}' ${TEST_RESULT}`"
-       @echo "LIST:O:Ox = `test '${LIST:O:Ox}' != '${LIST:O:Ox}' ${TEST_RESULT}`"
-       @echo "LISTX     = `test '${LISTX}' != '${LISTX}' ${TEST_RESULT}`"
-       @echo "LISTSX    = `test '${LISTSX}' = '${LISTSX}' ${TEST_RESULT}`"
-       @echo "BADMOD 1  = ${LIST:OX}"
-       @echo "BADMOD 2  = ${LIST:OxXX}"
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/varmod-order-shuffle.mk
--- a/usr.bin/make/unit-tests/varmod-order-shuffle.mk   Sun Aug 16 20:13:10 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-shuffle.mk   Sun Aug 16 20:43:01 2020 +0000
@@ -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.
 
-# TODO: Implementation
+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
+
+# Sorting after shuffling must produce the original numbers.
+sorted:=       ${NUMBERS:Ox:O}
+.if ${sorted} != ${NUMBERS:O}
+.error ${sorted} != ${NUMBERS:O}
+.endif
 
 all:
        @:;
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/varmod-order.exp
--- a/usr.bin/make/unit-tests/varmod-order.exp  Sun Aug 16 20:13:10 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-order.exp  Sun Aug 16 20:43:01 2020 +0000
@@ -1,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
diff -r 2bd43ab32239 -r e4a6fbde2f28 usr.bin/make/unit-tests/varmod-order.mk
--- a/usr.bin/make/unit-tests/varmod-order.mk   Sun Aug 16 20:13:10 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-order.mk   Sun Aug 16 20:43:01 2020 +0000
@@ -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 @@
 .error ${NUMBERS:O}
 .endif
 
+# Unknown modifier "OX"
+_:=    ${NUMBERS:OX}
+
+# Unknown modifier "OxXX"
+_:=    ${NUMBERS:OxXX}
+
 all:
        @:;



Home | Main Index | Thread Index | Old Index