xref: /freebsd/contrib/bmake/unit-tests/varmod-order-shuffle.mk (revision 36d6566e5985030fd2f1100bd9c1387bbe0bd290)
1# $NetBSD: varmod-order-shuffle.mk,v 1.5 2020/10/24 08:46:08 rillig Exp $
2#
3# Tests for the :Ox variable modifier, which returns the words of the
4# variable, shuffled.
5#
6# As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
7# This makes the random numbers completely predictable since there is no other
8# part of make that uses random numbers.
9#
10# Tags: probabilistic
11
12NUMBERS=	one two three four five six seven eight nine ten
13
14# Note that 1 in every 10! trials two independently generated
15# randomized orderings will be the same.  The test framework doesn't
16# support checking probabilistic output, so we accept that each of the
17# 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
18# lets the whole test fail once in 1.209.600 runs, on average.
19
20# Create two shuffles using the := assignment operator.
21shuffled1:=	${NUMBERS:Ox}
22shuffled2:=	${NUMBERS:Ox}
23.if ${shuffled1} == ${shuffled2}
24.  error ${shuffled1} == ${shuffled2}
25.endif
26
27# Sorting the list before shuffling it has no effect.
28shuffled1:=	${NUMBERS:O:Ox}
29shuffled2:=	${NUMBERS:O:Ox}
30.if ${shuffled1} == ${shuffled2}
31.  error ${shuffled1} == ${shuffled2}
32.endif
33
34# Sorting after shuffling must produce the original numbers.
35sorted:=	${NUMBERS:Ox:O}
36.if ${sorted} != ${NUMBERS:O}
37.  error ${sorted} != ${NUMBERS:O}
38.endif
39
40all:
41	@:;
42