xref: /freebsd/contrib/bmake/unit-tests/varmod-order-shuffle.mk (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1# $NetBSD: varmod-order-shuffle.mk,v 1.7 2021/08/03 04:46:49 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
14WORDS=		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:=	${WORDS:Ox}
24shuffled2:=	${WORDS:Ox}
25.if ${shuffled1} == ${shuffled2}
26.  error ${shuffled1} == ${shuffled2}
27.endif
28
29# Sorting the list before shuffling it has no effect.
30shuffled1:=	${WORDS:O:Ox}
31shuffled2:=	${WORDS:O:Ox}
32.if ${shuffled1} == ${shuffled2}
33.  error ${shuffled1} == ${shuffled2}
34.endif
35
36# Sorting after shuffling must produce the original numbers.
37sorted:=	${WORDS:Ox:O}
38.if ${sorted} != ${WORDS:O}
39.  error ${sorted} != ${WORDS:O}
40.endif
41
42all:
43