diff --git a/README.adoc b/README.adoc index 98e5208..c6270ff 100644 --- a/README.adoc +++ b/README.adoc @@ -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 @@ -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 @@ -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 } @@ -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 ... ``` diff --git a/bash_unit b/bash_unit index 6e07e97..525cb97 100755 --- a/bash_unit +++ b/bash_unit @@ -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() { @@ -314,7 +322,7 @@ tap_format() { echo "# Running tests in $test_file" } notify_test_starting() { - echo -n + : } notify_test_pending() { local test="$1" @@ -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) @@ -411,4 +425,12 @@ do ) failure=$(( $? || failure)) done + +if ((failure)) +then + notify_suites_failed +else + notify_suites_succeded +fi + exit $failure diff --git a/tests/test_cli.sh b/tests/test_cli.sh index 1377d26..2713155 100644 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -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 ; } @@ -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" } @@ -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() { @@ -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" } diff --git a/tests/test_core.sh b/tests/test_core.sh index 718b82d..70700fc 100644 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -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 ; } } diff --git a/tests/test_doc.sh b/tests/test_doc.sh index 76cc1ed..3ecb767 100644 --- a/tests/test_doc.sh +++ b/tests/test_doc.sh @@ -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 @@ -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"