xref: /freebsd/contrib/bmake/unit-tests/varmod-order-shuffle.mk (revision 96fbe51956c9df8bdb8317413b1c487b14e4ee68)
1# $NetBSD: varmod-order-shuffle.mk,v 1.6 2020/11/09 20:16:33 rillig Exp $
2#
3# Tests for the :Ox variable modifier, which returns the words of the
4# variable, shuffled.
5#
6# The variable modifier :Ox is available since 2005-06-01.
7#
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.
11#
12# Tags: probabilistic
13
14NUMBERS=	one two three four five six seven eight nine ten
15
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.
21
22# Create two shuffles using the := assignment operator.
23shuffled1:=	${NUMBERS:Ox}
24shuffled2:=	${NUMBERS:Ox}
25.if ${shuffled1} == ${shuffled2}
26.  error ${shuffled1} == ${shuffled2}
27.endif
28
29# Sorting the list before shuffling it has no effect.
30shuffled1:=	${NUMBERS:O:Ox}
31shuffled2:=	${NUMBERS:O:Ox}
32.if ${shuffled1} == ${shuffled2}
33.  error ${shuffled1} == ${shuffled2}
34.endif
35
36# Sorting after shuffling must produce the original numbers.
37sorted:=	${NUMBERS:Ox:O}
38.if ${sorted} != ${NUMBERS:O}
39.  error ${sorted} != ${NUMBERS:O}
40.endif
41
42all:
43	@:;
44