Home | History | Annotate | Line # | Download | only in unit-tests
varmod-order-shuffle.mk revision 1.3
      1 # $NetBSD: varmod-order-shuffle.mk,v 1.3 2020/08/16 20:43:01 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 NUMBERS=	one two three four five six seven eight nine ten
     11 
     12 # Note that 1 in every 10! trials two independently generated
     13 # randomized orderings will be the same.  The test framework doesn't
     14 # support checking probabilistic output, so we accept that each of the
     15 # 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
     16 # lets the whole test fail once in 1.209.600 runs, on average.
     17 
     18 # Create two shuffles using the := assignment operator.
     19 shuffled1:=	${NUMBERS:Ox}
     20 shuffled2:=	${NUMBERS:Ox}
     21 .if ${shuffled1} == ${shuffled2}
     22 .error ${shuffled1} == ${shuffled2}
     23 .endif
     24 
     25 # Sorting the list before shuffling it has no effect.
     26 shuffled1:=	${NUMBERS:O:Ox}
     27 shuffled2:=	${NUMBERS:O:Ox}
     28 .if ${shuffled1} == ${shuffled2}
     29 .error ${shuffled1} == ${shuffled2}
     30 .endif
     31 
     32 # Sorting after shuffling must produce the original numbers.
     33 sorted:=	${NUMBERS:Ox:O}
     34 .if ${sorted} != ${NUMBERS:O}
     35 .error ${sorted} != ${NUMBERS:O}
     36 .endif
     37 
     38 all:
     39 	@:;
     40