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 tests/make: fix test for the variabl...



details:   https://anonhg.NetBSD.org/src/rev/e3ddbaa02a26
branches:  trunk
changeset: 1022713:e3ddbaa02a26
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 03 04:46:49 2021 +0000

description:
tests/make: fix test for the variable modifier ':On'

The variable modifier ':On' sorts words numerically.  If these words are
not numeric at all, they get assigned the numeric value 0.  Internally,
':On' uses qsort for sorting the words.  Since qsort is not specified to
use a stable sorting algorithm, the test data must only use words that
either are written in the same way or that are numerically different.

The test varmod-order failed this requirement by trying to numerically
sort a list of non-numeric words.  This led to different results on BSD
and Ubuntu, as could be expected.

To fix the tests, distinguish between words and numbers in the tests.
While here, clean up the tests for all variants of the variable modifier
':O'.

Found by sjg on Ubuntu.

diffstat:

 usr.bin/make/unit-tests/varmod-order-numeric.mk |  28 ++++++++++++++++++------
 usr.bin/make/unit-tests/varmod-order-reverse.mk |   9 +++----
 usr.bin/make/unit-tests/varmod-order-shuffle.mk |  19 ++++++++--------
 usr.bin/make/unit-tests/varmod-order-string.mk  |   4 +-
 usr.bin/make/unit-tests/varmod-order.exp        |  28 ++++++++++++------------
 usr.bin/make/unit-tests/varmod-order.mk         |  15 +++++++------
 6 files changed, 58 insertions(+), 45 deletions(-)

diffs (216 lines):

diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order-numeric.mk
--- a/usr.bin/make/unit-tests/varmod-order-numeric.mk   Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-numeric.mk   Tue Aug 03 04:46:49 2021 +0000
@@ -1,11 +1,17 @@
-# $NetBSD: varmod-order-numeric.mk,v 1.4 2021/07/31 20:55:46 rillig Exp $
+# $NetBSD: varmod-order-numeric.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
 #
-# Tests for the :On variable modifier, which returns the words, sorted in
-# ascending numeric order.
+# Tests for the variable modifiers ':On', which returns the words, sorted in
+# ascending numeric order, and for ':Orn' and ':Onr', which additionally
+# reverse the order.
+#
+# The variable modifiers ':On', ':Onr' and ':Orn' were added in var.c 1.939
+# from 2021-07-30.
 
 # This list contains only 32-bit numbers since the make code needs to conform
 # to C90, which does not provide integer types larger than 32 bit.  It uses
-# 'long long' by default, but that type is overridable if necessary.
+# 'long long' by default, but that type is overridable if necessary to support
+# older environments.
+#
 # To get 53-bit integers even in C90, it would be possible to switch to
 # 'double' instead, but that would allow floating-point numbers as well, which
 # is out of scope for this variable modifier.
@@ -24,6 +30,14 @@
 .  error ${NUMBERS:Onr}
 .endif
 
+# Duplicate numbers are preserved in the output.  In this case the
+# equal-valued numbers are spelled the same, so they are indistinguishable in
+# the output.
+DUPLICATES=    3 1 2 2 1 1     # https://oeis.org/A034002
+.if ${DUPLICATES:On} != "1 1 1 2 2 3"
+.  error ${DUPLICATES:On}
+.endif
+
 # If there are several numbers that have the same integer value, they are
 # returned in unspecified order.
 SAME_VALUE:=   ${:U 79 80 0x0050 81 :On}
@@ -32,9 +46,9 @@
 .endif
 
 # Hexadecimal and octal numbers are supported as well.
-OCTAL=         0 010 0x7 9
-.if ${OCTAL:On} != "0 0x7 010 9"
-.  error ${OCTAL:On}
+MIXED_BASE=    0 010 0x7 9
+.if ${MIXED_BASE:On} != "0 0x7 010 9"
+.  error ${MIXED_BASE:On}
 .endif
 
 all:
diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order-reverse.mk
--- a/usr.bin/make/unit-tests/varmod-order-reverse.mk   Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-reverse.mk   Tue Aug 03 04:46:49 2021 +0000
@@ -1,13 +1,12 @@
-# $NetBSD: varmod-order-reverse.mk,v 1.4 2020/10/24 08:46:08 rillig Exp $
+# $NetBSD: varmod-order-reverse.mk,v 1.5 2021/08/03 04:46:49 rillig Exp $
 #
 # Tests for the :Or variable modifier, which returns the words, sorted in
 # descending order.
 
-NUMBERS=       one two three four five six seven eight nine ten
+WORDS=         one two three four five six seven eight nine ten
 
-.if ${NUMBERS:Or} != "two three ten six seven one nine four five eight"
-.  error ${NUMBERS:Or}
+.if ${WORDS:Or} != "two three ten six seven one nine four five eight"
+.  error ${WORDS:Or}
 .endif
 
 all:
-       @:;
diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order-shuffle.mk
--- a/usr.bin/make/unit-tests/varmod-order-shuffle.mk   Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-shuffle.mk   Tue Aug 03 04:46:49 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-order-shuffle.mk,v 1.6 2020/11/09 20:16:33 rillig Exp $
+# $NetBSD: varmod-order-shuffle.mk,v 1.7 2021/08/03 04:46:49 rillig Exp $
 #
 # Tests for the :Ox variable modifier, which returns the words of the
 # variable, shuffled.
@@ -11,7 +11,7 @@
 #
 # Tags: probabilistic
 
-NUMBERS=       one two three four five six seven eight nine ten
+WORDS=         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
@@ -20,24 +20,23 @@
 # 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}
+shuffled1:=    ${WORDS:Ox}
+shuffled2:=    ${WORDS: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}
+shuffled1:=    ${WORDS:O:Ox}
+shuffled2:=    ${WORDS: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}
+sorted:=       ${WORDS:Ox:O}
+.if ${sorted} != ${WORDS:O}
+.  error ${sorted} != ${WORDS:O}
 .endif
 
 all:
-       @:;
diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order-string.mk
--- a/usr.bin/make/unit-tests/varmod-order-string.mk    Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order-string.mk    Tue Aug 03 04:46:49 2021 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: varmod-order-string.mk,v 1.1 2021/07/31 20:55:46 rillig Exp $
+# $NetBSD: varmod-order-string.mk,v 1.2 2021/08/03 04:46:49 rillig Exp $
 #
 # Tests for the :O variable modifier, which returns the words, sorted in
 # ascending order.
 
 # Simple words are sorted lexicographically.
-WORDS= one two three four five six seven eight nine ten
+WORDS=         one two three four five six seven eight nine ten
 .if ${WORDS:O} != "eight five four nine one seven six ten three two"
 .  error ${WORDS:O}
 .endif
diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order.exp
--- a/usr.bin/make/unit-tests/varmod-order.exp  Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order.exp  Tue Aug 03 04:46:49 2021 +0000
@@ -1,24 +1,24 @@
-make: Bad modifier ":OX" for variable "NUMBERS"
-make: "varmod-order.mk" line 13: Undefined variable "${NUMBERS:OX"
-make: Bad modifier ":OxXX" for variable "NUMBERS"
-make: "varmod-order.mk" line 16: Undefined variable "${NUMBERS:Ox"
-make: Unclosed variable expression, expecting '}' for modifier "O" of variable "NUMBERS" with value "eight five four nine one seven six ten three two"
-make: Unclosed variable expression, expecting '}' for modifier "On" of variable "NUMBERS" with value "ten two three four five six seven eight nine one"
-make: Unclosed variable expression, expecting '}' for modifier "Onr" of variable "NUMBERS" with value "ten two three four five six seven eight nine one"
+make: Bad modifier ":OX" for variable "WORDS"
+make: "varmod-order.mk" line 14: Undefined variable "${WORDS:OX"
+make: Bad modifier ":OxXX" for variable "WORDS"
+make: "varmod-order.mk" line 17: Undefined variable "${WORDS:Ox"
+make: Unclosed variable expression, expecting '}' for modifier "O" of variable "WORDS" with value "eight five four nine one seven six ten three two"
+make: Unclosed variable expression, expecting '}' for modifier "On" of variable "NUMBERS" with value "1 2 3 4 5 6 7 8 9 10"
+make: Unclosed variable expression, expecting '}' for modifier "Onr" of variable "NUMBERS" with value "10 9 8 7 6 5 4 3 2 1"
 make: Bad modifier ":Oxn" for variable "NUMBERS"
-make: "varmod-order.mk" line 28: Malformed conditional (${NUMBERS:Oxn})
+make: "varmod-order.mk" line 29: Malformed conditional (${NUMBERS:Oxn})
 make: Bad modifier ":On_typo" for variable "NUMBERS"
-make: "varmod-order.mk" line 38: Malformed conditional (${NUMBERS:On_typo})
+make: "varmod-order.mk" line 39: Malformed conditional (${NUMBERS:On_typo})
 make: Bad modifier ":Onr_typo" for variable "NUMBERS"
-make: "varmod-order.mk" line 47: Malformed conditional (${NUMBERS:Onr_typo})
+make: "varmod-order.mk" line 48: Malformed conditional (${NUMBERS:Onr_typo})
 make: Bad modifier ":Orn_typo" for variable "NUMBERS"
-make: "varmod-order.mk" line 56: Malformed conditional (${NUMBERS:Orn_typo})
+make: "varmod-order.mk" line 57: Malformed conditional (${NUMBERS:Orn_typo})
 make: Bad modifier ":Onn" for variable "NUMBERS"
-make: "varmod-order.mk" line 67: Malformed conditional (${NUMBERS:Onn})
+make: "varmod-order.mk" line 68: Malformed conditional (${NUMBERS:Onn})
 make: Bad modifier ":Onrr" for variable "NUMBERS"
-make: "varmod-order.mk" line 76: Malformed conditional (${NUMBERS:Onrr})
+make: "varmod-order.mk" line 77: Malformed conditional (${NUMBERS:Onrr})
 make: Bad modifier ":Orrn" for variable "NUMBERS"
-make: "varmod-order.mk" line 85: Malformed conditional (${NUMBERS:Orrn})
+make: "varmod-order.mk" line 86: Malformed conditional (${NUMBERS:Orrn})
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 9899613c3a53 -r e3ddbaa02a26 usr.bin/make/unit-tests/varmod-order.mk
--- a/usr.bin/make/unit-tests/varmod-order.mk   Tue Aug 03 01:44:10 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-order.mk   Tue Aug 03 04:46:49 2021 +0000
@@ -1,22 +1,23 @@
-# $NetBSD: varmod-order.mk,v 1.6 2021/07/31 20:55:46 rillig Exp $
+# $NetBSD: varmod-order.mk,v 1.7 2021/08/03 04:46:49 rillig Exp $
 #
 # Tests for the :O variable modifier and its variants, which either sort the
 # words of the value or shuffle them.
 
-NUMBERS=       one two three four five six seven eight nine ten
+WORDS=         one two three four five six seven eight nine ten
+NUMBERS=       8 5 4 9 1 7 6 10 3 2    # in English alphabetical order
 
-.if ${NUMBERS:O} != "eight five four nine one seven six ten three two"
-.  error ${NUMBERS:O}
+.if ${WORDS:O} != "eight five four nine one seven six ten three two"
+.  error ${WORDS:O}
 .endif
 
 # Unknown modifier "OX"
-_:=    ${NUMBERS:OX}
+_:=    ${WORDS:OX}
 
 # Unknown modifier "OxXX"
-_:=    ${NUMBERS:OxXX}
+_:=    ${WORDS:OxXX}
 
 # Missing closing brace, to cover the error handling code.
-_:=    ${NUMBERS:O
+_:=    ${WORDS:O
 _:=    ${NUMBERS:On
 _:=    ${NUMBERS:Onr
 



Home | Main Index | Thread Index | Old Index