Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Running tests in tests/test_core.sh
Running test_fake_echo_stdin_when_no_params ... SUCCESS
Running test_fake_exports_faked_in_subshells ... SUCCESS
Running test_fake_transmits_params_to_fake_code ... SUCCESS
Overall result: SUCCESS
```

You might also want to run only specific tests, you may do so with the
Expand All @@ -133,6 +134,7 @@ Running tests in tests/test_core.sh
Running test_assert_status_code_succeeds ... SUCCESS
Running test_assert_succeeds ... SUCCESS
Running test_fail_fails ... SUCCESS
Overall result: SUCCESS
```

*bash_unit* supports the http://testanything.org/[Test Anything Protocol] so you can ask for a tap formatted
Expand Down Expand Up @@ -597,7 +599,7 @@ With bash, the result code of a pipeline equals the result code of the last comm

An alternative may be to activate bash _pipefail_ option but this may introduce unwanted side effects. We can also simply not output anything in __ps_ so that _grep_ fails:

```test
```shell
code() {
ps a | grep apache
}
Expand All @@ -619,7 +621,7 @@ bad, don't do that.

Moreover, *assert_equals* output is captured by _ps_ and this just messes with the display of our test results:

```output
```shell
Running test_code_gives_ps_appropriate_parameters ...
```

Expand Down
26 changes: 24 additions & 2 deletions bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ text_format() {
notify_stack() {
color "$YELLOW"
}
notify_suites_succeded() {
echo -n "Overall result: SUCCESS" | pretty_success
echo
}
notify_suites_failed() {
echo -n "Overall result: FAILURE" | pretty_failure
echo
}
}

tap_format() {
Expand All @@ -314,7 +322,7 @@ tap_format() {
echo "# Running tests in $test_file"
}
notify_test_starting() {
echo -n
:
}
notify_test_pending() {
local test="$1"
Expand Down Expand Up @@ -343,13 +351,19 @@ tap_format() {
notify_stack() {
"$SED" 's:^:# :' | color "$YELLOW"
}
notify_suites_succeded() {
:
}
notify_suites_failed() {
:
}
}

output_format=text
test_pattern=""
separator=""
randomise=0
while getopts "vp:f:r" option
while getopts "vp:f:or" option
do
case "$option" in
p)
Expand Down Expand Up @@ -411,4 +425,12 @@ do
)
failure=$(( $? || failure))
done

if ((failure))
then
notify_suites_failed
else
notify_suites_succeded
fi

exit $failure
12 changes: 8 additions & 4 deletions tests/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ test_run_all_tests_even_in_case_of_failure() {
Running tests in code
Running test_fails ... FAILURE
code:2:test_fails()
Running test_succeed ... SUCCESS\
Running test_succeed ... SUCCESS
Overall resultcode: FAILURE\
" \
"$(bash_unit_out_for_code << EOF
function test_succeed() { assert true ; }
Expand Down Expand Up @@ -42,7 +43,8 @@ test_run_all_file_parameters() {
Running tests in test_file
Running test_one ... SUCCESS
Running tests in test_file
Running test_two ... SUCCESS\
Running test_two ... SUCCESS
Overall result: SUCCESS\
" \
"$bash_unit_output"
}
Expand All @@ -57,7 +59,8 @@ test_run_only_tests_that_match_pattern() {
assert_equals "\
Running tests in test_file
Running test_one ... SUCCESS
Running tests in test_file" "$bash_unit_output"
Running tests in test_file
Overall result: SUCCESS" "$bash_unit_output"
}

test_do_not_run_pending_tests() {
Expand All @@ -77,7 +80,8 @@ test_pending_tests_appear_in_output() {
assert_equals "\
Running tests in test_file
Running pending_should_not_run ... PENDING
Running todo_should_not_run ... PENDING" \
Running todo_should_not_run ... PENDING
Overall result: SUCCESS" \
"$bash_unit_output"
}

Expand Down
2 changes: 2 additions & 0 deletions tests/test_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,6 @@ mute() {
notify_stack () { echo -n ; }
notify_stdout () { echo -n ; }
notify_stderr () { echo -n ; }
notify_suites_succeded () { echo -n ; }
notify_suites_failed () { echo -n ; }
}
23 changes: 18 additions & 5 deletions tests/test_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ prepare_tests() {

while grep -E '^'"$TEST_PATTERN"'$' $remaining >/dev/null
do
block=$(($block+1))
((++block))
run_doc_test $remaining $swap |& sed '$a\' > $test_output$block
doc_to_output $remaining $swap > $expected_output$block
eval 'function test_block_'"$block"'() {
eval 'function test_block_'"$(printf %02d $block)"'() {
assert "diff -u '"$expected_output$block"' '"$test_output$block"'"
}'
done
Expand All @@ -32,12 +32,25 @@ prepare_tests() {
function run_doc_test() {
local remaining="$1"
local swap="$2"
$BASH_UNIT <(
cat "$remaining" | _next_code "$swap"
) | tail -n +2 | sed -e 's:/dev/fd/[0-9]*:doc:g'
$BASH_UNIT <(cat "$remaining" | _next_code "$swap") \
| clean_bash_unit_running_header \
| clean_bash_pseudo_files_name \
| clean_bash_unit_overall_result
cat "$swap" > "$remaining"
}

function clean_bash_unit_running_header() {
tail -n +2
}

function clean_bash_pseudo_files_name() {
sed -e 's:/dev/fd/[0-9]*:doc:g'
}

function clean_bash_unit_overall_result() {
sed '$d'
}

function doc_to_output() {
local remaining="$1"
local swap="$2"
Expand Down