1 # $NetBSD: varmod-order-shuffle.mk,v 1.7 2021/08/03 04:46:49 rillig Exp $
3 # Tests for the :Ox variable modifier, which returns the words of the
6 # The variable modifier :Ox is available since 2005-06-01.
8 # As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
9 # This makes the random numbers completely predictable since there is no other
10 # part of make that uses random numbers.
14 WORDS= one two three four five six seven eight nine ten
16 # Note that 1 in every 10! trials two independently generated
17 # randomized orderings will be the same. The test framework doesn't
18 # support checking probabilistic output, so we accept that each of the
19 # 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
20 # lets the whole test fail once in 1.209.600 runs, on average.
22 # Create two shuffles using the := assignment operator.
23 shuffled1:= ${WORDS:Ox}
24 shuffled2:= ${WORDS:Ox}
25 .if ${shuffled1} == ${shuffled2}
26 . error ${shuffled1} == ${shuffled2}
29 # Sorting the list before shuffling it has no effect.
30 shuffled1:= ${WORDS:O:Ox}
31 shuffled2:= ${WORDS:O:Ox}
32 .if ${shuffled1} == ${shuffled2}
33 . error ${shuffled1} == ${shuffled2}
36 # Sorting after shuffling must produce the original numbers.
37 sorted:= ${WORDS:Ox:O}
38 .if ${sorted} != ${WORDS:O}
39 . error ${sorted} != ${WORDS:O}