11'\" t
22.\" Title: bash_unit
33.\" Author: [see the "AUTHOR(S)" section]
4- .\" Generator: Asciidoctor 2.0.13
5- .\" Date: 2021-06-01
4+ .\" Generator: Asciidoctor 2.0.16
5+ .\" Date: 2021-10-14
66.\" Manual: \ \&
77.\" Source: \ \&
88.\" Language: English
99.\"
10- .TH "BASH_UNIT" "1" "2021-06-01 " "\ \& " "\ \& "
10+ .TH "BASH_UNIT" "1" "2021-10-14 " "\ \& " "\ \& "
1111.ie \n( .g .ds Aq \(aq
1212.el .ds Aq '
1313.ss \n[ .ss ] 0
3131bash_unit \- bash unit testing enterprise edition framework for professionals!
3232.SH "SYNOPSIS"
3333.sp
34- \fB bash_unit \fP [\- f tap] [\- p <pattern>] [test_file]
34+ \fB bash_unit \fP [\- f tap] [\- p <pattern>] [\- r] [ test_file]
3535.SH "DESCRIPTION"
3636.sp
3737\fB bash_unit \fP allows you to write unit tests (functions starting with \fB test \fP ),
@@ -55,6 +55,14 @@ You can specify several patterns by repeating this option
5555for each pattern.
5656.RE
5757.sp
58+ \fB \- r \fP
59+ .RS 4
60+ executes test cases in random order.
61+ Only affects the order within a test file (files are always
62+ executed in the order in which they are specified on the
63+ command line).
64+ .RE
65+ .sp
5866\fB \- f \fP \fI output_format \fP
5967.RS 4
6068specify an alternative output format.
@@ -76,26 +84,30 @@ To run tests, simply call \fBbash_unit\fP with all your tests files as parameter
7684.nf
7785.fam C
7886Running tests in tests/test_core.sh
79- Running test_assert_equals_fails_when_not_equal ... SUCCESS
80- Running test_assert_equals_succeed_when_equal ... SUCCESS
81- Running test_assert_fails ... SUCCESS
82- Running test_assert_fails_fails ... SUCCESS
83- Running test_assert_fails_succeeds ... SUCCESS
84- Running test_assert_not_equals_fails_when_equal ... SUCCESS
85- Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS
86- Running test_assert_shows_stderr_on_failure ... SUCCESS
87- Running test_assert_shows_stdout_on_failure ... SUCCESS
88- Running test_assert_status_code_fails ... SUCCESS
89- Running test_assert_status_code_succeeds ... SUCCESS
90- Running test_assert_succeeds ... SUCCESS
91- Running test_fail_fails ... SUCCESS
92- Running test_fail_prints_failure_message ... SUCCESS
93- Running test_fail_prints_where_is_error ... SUCCESS
94- Running test_fake_actually_fakes_the_command ... SUCCESS
95- Running test_fake_can_fake_inline ... SUCCESS
96- Running test_fake_echo_stdin_when_no_params ... SUCCESS
97- Running test_fake_exports_faked_in_subshells ... SUCCESS
98- Running test_fake_transmits_params_to_fake_code ... SUCCESS
87+ Running test_assert_equals_fails_when_not_equal ... SUCCESS ✓
88+ Running test_assert_equals_succeed_when_equal ... SUCCESS ✓
89+ Running test_assert_fails ... SUCCESS ✓
90+ Running test_assert_fails_fails ... SUCCESS ✓
91+ Running test_assert_fails_succeeds ... SUCCESS ✓
92+ Running test_assert_no_diff_fails_when_diff ... SUCCESS ✓
93+ Running test_assert_no_diff_succeeds_when_no_diff ... SUCCESS ✓
94+ Running test_assert_not_equals_fails_when_equal ... SUCCESS ✓
95+ Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS ✓
96+ Running test_assert_shows_stderr_on_failure ... SUCCESS ✓
97+ Running test_assert_shows_stdout_on_failure ... SUCCESS ✓
98+ Running test_assert_status_code_fails ... SUCCESS ✓
99+ Running test_assert_status_code_succeeds ... SUCCESS ✓
100+ Running test_assert_succeeds ... SUCCESS ✓
101+ Running test_bash_unit_changes_cwd_to_current_test_file_directory ... SUCCESS ✓
102+ Running test_fail_fails ... SUCCESS ✓
103+ Running test_fail_prints_failure_message ... SUCCESS ✓
104+ Running test_fail_prints_where_is_error ... SUCCESS ✓
105+ Running test_fake_actually_fakes_the_command ... SUCCESS ✓
106+ Running test_fake_can_fake_inline ... SUCCESS ✓
107+ Running test_fake_echo_stdin_when_no_params ... SUCCESS ✓
108+ Running test_fake_exports_faked_in_subshells ... SUCCESS ✓
109+ Running test_fake_transmits_params_to_fake_code ... SUCCESS ✓
110+ Overall result: SUCCESS ✓
99111.fam
100112.fi
101113.if n .RE
@@ -116,19 +128,22 @@ functions against this pattern.
116128.nf
117129.fam C
118130Running tests in tests/test_core.sh
119- Running test_assert_equals_fails_when_not_equal ... SUCCESS
120- Running test_assert_equals_succeed_when_equal ... SUCCESS
121- Running test_assert_fails ... SUCCESS
122- Running test_assert_fails_fails ... SUCCESS
123- Running test_assert_fails_succeeds ... SUCCESS
124- Running test_assert_not_equals_fails_when_equal ... SUCCESS
125- Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS
126- Running test_assert_shows_stderr_on_failure ... SUCCESS
127- Running test_assert_shows_stdout_on_failure ... SUCCESS
128- Running test_assert_status_code_fails ... SUCCESS
129- Running test_assert_status_code_succeeds ... SUCCESS
130- Running test_assert_succeeds ... SUCCESS
131- Running test_fail_fails ... SUCCESS
131+ Running test_assert_equals_fails_when_not_equal ... SUCCESS ✓
132+ Running test_assert_equals_succeed_when_equal ... SUCCESS ✓
133+ Running test_assert_fails ... SUCCESS ✓
134+ Running test_assert_fails_fails ... SUCCESS ✓
135+ Running test_assert_fails_succeeds ... SUCCESS ✓
136+ Running test_assert_no_diff_fails_when_diff ... SUCCESS ✓
137+ Running test_assert_no_diff_succeeds_when_no_diff ... SUCCESS ✓
138+ Running test_assert_not_equals_fails_when_equal ... SUCCESS ✓
139+ Running test_assert_not_equals_succeeds_when_not_equal ... SUCCESS ✓
140+ Running test_assert_shows_stderr_on_failure ... SUCCESS ✓
141+ Running test_assert_shows_stdout_on_failure ... SUCCESS ✓
142+ Running test_assert_status_code_fails ... SUCCESS ✓
143+ Running test_assert_status_code_succeeds ... SUCCESS ✓
144+ Running test_assert_succeeds ... SUCCESS ✓
145+ Running test_fail_fails ... SUCCESS ✓
146+ Overall result: SUCCESS ✓
132147.fam
133148.fi
134149.if n .RE
@@ -150,26 +165,29 @@ output with the \fI\-f\fP option.
150165.nf
151166.fam C
152167# Running tests in tests/test_core.sh
153- ok \- test_assert_equals_fails_when_not_equal
154- ok \- test_assert_equals_succeed_when_equal
155- ok \- test_assert_fails
156- ok \- test_assert_fails_fails
157- ok \- test_assert_fails_succeeds
158- ok \- test_assert_not_equals_fails_when_equal
159- ok \- test_assert_not_equals_succeeds_when_not_equal
160- ok \- test_assert_shows_stderr_on_failure
161- ok \- test_assert_shows_stdout_on_failure
162- ok \- test_assert_status_code_fails
163- ok \- test_assert_status_code_succeeds
164- ok \- test_assert_succeeds
165- ok \- test_fail_fails
166- ok \- test_fail_prints_failure_message
167- ok \- test_fail_prints_where_is_error
168- ok \- test_fake_actually_fakes_the_command
169- ok \- test_fake_can_fake_inline
170- ok \- test_fake_echo_stdin_when_no_params
171- ok \- test_fake_exports_faked_in_subshells
172- ok \- test_fake_transmits_params_to_fake_code
168+ ok ✓ test_assert_equals_fails_when_not_equal
169+ ok ✓ test_assert_equals_succeed_when_equal
170+ ok ✓ test_assert_fails
171+ ok ✓ test_assert_fails_fails
172+ ok ✓ test_assert_fails_succeeds
173+ ok ✓ test_assert_no_diff_fails_when_diff
174+ ok ✓ test_assert_no_diff_succeeds_when_no_diff
175+ ok ✓ test_assert_not_equals_fails_when_equal
176+ ok ✓ test_assert_not_equals_succeeds_when_not_equal
177+ ok ✓ test_assert_shows_stderr_on_failure
178+ ok ✓ test_assert_shows_stdout_on_failure
179+ ok ✓ test_assert_status_code_fails
180+ ok ✓ test_assert_status_code_succeeds
181+ ok ✓ test_assert_succeeds
182+ ok ✓ test_bash_unit_changes_cwd_to_current_test_file_directory
183+ ok ✓ test_fail_fails
184+ ok ✓ test_fail_prints_failure_message
185+ ok ✓ test_fail_prints_where_is_error
186+ ok ✓ test_fake_actually_fakes_the_command
187+ ok ✓ test_fake_can_fake_inline
188+ ok ✓ test_fake_echo_stdin_when_no_params
189+ ok ✓ test_fake_exports_faked_in_subshells
190+ ok ✓ test_fake_transmits_params_to_fake_code
173191.fam
174192.fi
175193.if n .RE
@@ -316,13 +334,13 @@ It may also be fun to use assert to check for the expected content of a file.
316334.nf
317335.fam C
318336code() {
319- echo \( aq not so cool\( aq > /tmp/the_file
337+ echo \*( Aq not so cool\*( Aq > /tmp/the_file
320338}
321339
322340test_code_write_appropriate_content_in_the_file() {
323341 code
324342
325- assert "diff <(echo \( aq this is cool\( aq ) /tmp/the_file"
343+ assert "diff <(echo \*( Aq this is cool\*( Aq ) /tmp/the_file"
326344}
327345.fam
328346.fi
@@ -360,19 +378,19 @@ If the evaluated expression does not fail, then \fBassert_fail\fP will fail and
360378.nf
361379.fam C
362380code() {
363- echo \( aq not so cool\( aq > /tmp/the_file
381+ echo \*( Aq not so cool\*( Aq > /tmp/the_file
364382}
365383
366384test_code_does_not_write_cool_in_the_file() {
367385 code
368386
369- assert_fails "grep cool /tmp/the_file" "should not write \( aq cool \( aq in /tmp/the_file"
387+ assert_fails "grep cool /tmp/the_file" "should not write \*( Aq cool \*( Aq in /tmp/the_file"
370388}
371389
372390test_code_does_not_write_this_in_the_file() {
373391 code
374392
375- assert_fails "grep this /tmp/the_file" "should not write \( aq this \( aq in /tmp/the_file"
393+ assert_fails "grep this /tmp/the_file" "should not write \*( Aq this \*( Aq in /tmp/the_file"
376394}
377395.fam
378396.fi
@@ -382,7 +400,7 @@ test_code_does_not_write_this_in_the_file() {
382400.nf
383401.fam C
384402 Running test_code_does_not_write_cool_in_the_file ... FAILURE
385- should not write \( aq cool \( aq in /tmp/the_file
403+ should not write \*( Aq cool \*( Aq in /tmp/the_file
386404out> not so cool
387405doc:8:test_code_does_not_write_cool_in_the_file()
388406 Running test_code_does_not_write_this_in_the_file ... SUCCESS
@@ -500,6 +518,42 @@ doc:2:test_obvious_equality_with_assert_not_equals()
500518.fam
501519.fi
502520.if n .RE
521+ .SS "\fB assert_no_diff \fP "
522+ .sp
523+ .if n .RS 4
524+ .nf
525+ .fam C
526+ assert_no_diff <expected> <actual> [message]
527+ .fam
528+ .fi
529+ .if n .RE
530+ .sp
531+ Assert for equality of content between the two files \fI expected \fP and \fI actual \fP .
532+ .sp
533+ .if n .RS 4
534+ .nf
535+ .fam C
536+ test_obvious_diff_with_assert_no_diff(){
537+ assert_no_diff <(echo foo) <(echo bar) "dynamic files should have no difference"
538+ }
539+ test_obvious_equality_with_assert_no_diff(){
540+ assert_no_diff "$0" "$0"
541+ }
542+ .fam
543+ .fi
544+ .if n .RE
545+ .sp
546+ .if n .RS 4
547+ .nf
548+ .fam C
549+ Running test_obvious_diff_with_assert_no_diff ... FAILURE ✗
550+ dynamic files should have no difference
551+ expected \*( Aq /dev/fd/62\*( Aq to be identical to \*( Aq /dev/fd/63\*( Aq but was different
552+ doc:2:test_obvious_diff_with_assert_no_diff()
553+ Running test_obvious_equality_with_assert_no_diff ... SUCCESS ✓
554+ .fam
555+ .fi
556+ .if n .RE
503557.SH "\fB FAKE \fP FUNCTION"
504558.sp
505559.if n .RS 4
@@ -849,7 +903,7 @@ code() {
849903}
850904
851905test_code_gives_ps_appropriate_parameters() {
852- fake ps \( aq echo $FAKE_PARAMS >/tmp/fake_params\( aq
906+ fake ps \*( Aq echo $FAKE_PARAMS >/tmp/fake_params\*( Aq
853907
854908 code || true
855909
@@ -886,7 +940,7 @@ test_get_data_from_fake() {
886940 #Fasten you seat belt ...
887941 coproc cat
888942 exec {test_channel}>&${COPROC[1]}
889- fake ps \( aq echo $FAKE_PARAMS >&$test_channel\( aq
943+ fake ps \*( Aq echo $FAKE_PARAMS >&$test_channel\*( Aq
890944
891945 code || true
892946
0 commit comments