aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/varmod-order-shuffle.mk
blob: e9898600355a3d50a43efb426deb9080e7068394 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# $NetBSD: varmod-order-shuffle.mk,v 1.8 2023/02/26 06:08:06 rillig Exp $
#
# Tests for the :Ox variable modifier, which returns the words of the
# variable, shuffled.
#
# The variable modifier :Ox is available since 2005-06-01.
#
# As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
# This makes the random numbers completely predictable since the only other
# part of make that uses random numbers is the 'randomize-targets' mode, which
# is off by default.
#
# Tags: probabilistic

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
# 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:=	${WORDS:Ox}
shuffled2:=	${WORDS:Ox}
.if ${shuffled1} == ${shuffled2}
.  error ${shuffled1} == ${shuffled2}
.endif

# Sorting the list before shuffling it has no effect.
shuffled1:=	${WORDS:O:Ox}
shuffled2:=	${WORDS:O:Ox}
.if ${shuffled1} == ${shuffled2}
.  error ${shuffled1} == ${shuffled2}
.endif

# Sorting after shuffling must produce the original numbers.
sorted:=	${WORDS:Ox:O}
.if ${sorted} != ${WORDS:O}
.  error ${sorted} != ${WORDS:O}
.endif

all: