summaryrefslogtreecommitdiff
path: root/unit-tests/varmod-order-shuffle.mk
diff options
context:
space:
mode:
Diffstat (limited to 'unit-tests/varmod-order-shuffle.mk')
-rw-r--r--unit-tests/varmod-order-shuffle.mk39
1 files changed, 39 insertions, 0 deletions
diff --git a/unit-tests/varmod-order-shuffle.mk b/unit-tests/varmod-order-shuffle.mk
new file mode 100644
index 0000000000000..b6eb6be4b1bcb
--- /dev/null
+++ b/unit-tests/varmod-order-shuffle.mk
@@ -0,0 +1,39 @@
+# $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
+
+# Sorting after shuffling must produce the original numbers.
+sorted:= ${NUMBERS:Ox:O}
+.if ${sorted} != ${NUMBERS:O}
+.error ${sorted} != ${NUMBERS:O}
+.endif
+
+all:
+ @:;