File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ bash_unit - bash unit testing enterprise edition framework for professionals!
1212
1313== Synopsis
1414
15- *bash_unit* [-f tap] [-p <pattern>] [test_file]
15+ *bash_unit* [-f tap] [-p <pattern>] [-r] [ test_file]
1616
1717== Description
1818
@@ -36,6 +36,12 @@ _(by the way, the documentation you are reading is itself tested with bash-unit)
3636 You can specify several patterns by repeating this option
3737 for each pattern.
3838
39+ *-r*::
40+ executes test cases in random order.
41+ Only affects the order within a test file (files are always
42+ executed in the order in which they are specified on the
43+ command line).
44+
3945*-f* _output_format_::
4046 specify an alternative output format.
4147 The only supported value is *tap*.
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ CAT="$(which cat)"
3030SED=" $( which sed) "
3131GREP=" $( which grep) "
3232RM=" $( which rm) "
33+ SHUF=" $( which shuf) "
3334
3435fail () {
3536 local message=${1:- }
@@ -162,6 +163,10 @@ run_setup_suite() {
162163 fi
163164}
164165
166+ maybe_shuffle () {
167+ (( randomise)) && $SHUF || $CAT
168+ }
169+
165170run_tests () {
166171 local failure=0
167172
@@ -172,7 +177,7 @@ run_tests() {
172177 done
173178
174179
175- for test in $( set | " $GREP " -E ' ^test.* \(\)' | " $GREP " -E " $test_pattern " | " $SED " -e ' s: .*::' )
180+ for test in $( set | " $GREP " -E ' ^test.* \(\)' | " $GREP " -E " $test_pattern " | " $SED " -e ' s: .*::' | maybe_shuffle )
176181 do
177182 (
178183 local status=0
@@ -201,10 +206,11 @@ run_teardown_suite() {
201206
202207usage () {
203208 echo " $1 " >&2
204- echo " $0 [-f <output format>] [-p <pattern1>] [-p <pattern2>] ... <test_file1> <test_file2> ..." >&2
209+ echo " $0 [-f <output format>] [-p <pattern1>] [-p <pattern2>] [-r] ... <test_file1> <test_file2> ..." >&2
205210 echo >&2
206211 echo " Runs tests in test files that match <pattern>s" >&2
207212 echo " <output format> is optional only supported value is tap" >&2
213+ echo " -r to execute test cases in random order" >&2
208214 echo " -v to get current version information" >&2
209215 echo " See https://github.com/pgrange/bash_unit" >&2
210216 exit 1
@@ -342,7 +348,8 @@ tap_format() {
342348output_format=text
343349test_pattern=" "
344350separator=" "
345- while getopts " vp:f:" option
351+ randomise=0
352+ while getopts " vp:f:r" option
346353do
347354 case " $option " in
348355 p)
352359 f)
353360 output_format=" ${OPTARG} "
354361 ;;
362+ r)
363+ randomise=1
364+ ;;
355365 v)
356366 echo " bash_unit $VERSION "
357367 exit
You can’t perform that action at this time.
0 commit comments