diff --git a/bash_unit b/bash_unit index 4699fcc..2454c7f 100755 --- a/bash_unit +++ b/bash_unit @@ -34,6 +34,7 @@ SED="$(type -P sed)" GREP="$(type -P grep)" RM="$(type -P rm)" SHUF="$(type -P sort) -R" +TEMPFILE="$(pwd)/$$.tmp" fail() { local message=${1:-} @@ -185,16 +186,6 @@ assert_no_diff() { "$message expected '${actual}' to be identical to '${expected}' but was different" } -skip_if() { - local condition="$1" - local pattern="$2" - if eval "$condition" >/dev/null 2>&1 - then - skip_pattern="${skip_pattern}${skip_pattern_separator}${pattern}" - skip_pattern_separator="|" - fi -} - fake() { local command=$1 shift @@ -263,6 +254,7 @@ run_tests() { local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)" fi + test_count=$(cat "${TEMPFILE}") for test in $tests_to_run do ( @@ -273,7 +265,10 @@ run_tests() { exit $status ) failure=$(( $? || failure)) + ((test_count++)) done + echo "${test_count}" > "${TEMPFILE}" + return $failure } @@ -455,10 +450,12 @@ tap_format() { "$SED" 's:^:# :' | color "$YELLOW" } notify_suites_succeded() { - : + local message="$1" + echo "1..$message" } notify_suites_failed() { - : + local message="$1" + echo "1..$message" } } @@ -477,6 +474,16 @@ quiet_mode() { } } +skip_if() { + local condition="$1" + local pattern="$2" + if eval "$condition" >/dev/null 2>&1 + then + skip_pattern="${skip_pattern}${skip_pattern_separator}${pattern}" + skip_pattern_separator="|" + fi +} + output_format=text verbosity=normal test_pattern="" @@ -540,6 +547,7 @@ fi #run tests received as parameters failure=0 +echo 0 > "${TEMPFILE}" for test_file in "$@" do notify_suite_starting "$test_file" @@ -562,12 +570,13 @@ do ) failure=$(( $? || failure)) done - + if ((failure)) then - notify_suites_failed + notify_suites_failed $(cat "${TEMPFILE}") else - notify_suites_succeded + notify_suites_succeded $(cat "${TEMPFILE}") fi +unlink $TEMPFILE exit $failure diff --git a/tests/test_tap_format b/tests/test_tap_format index 65b59b5..e7d641e 100644 --- a/tests/test_tap_format +++ b/tests/test_tap_format @@ -12,8 +12,8 @@ test_tap_format_for_one_succesfull_test() { assert_equals \ "\ # Running tests in code -ok - test_ok\ -" \ +ok - test_ok +1..1" \ "$(bash_unit_out_for_code < message on stdout # err> message on stderr -# code:2:test_not_ok()\ -" \ +# code:2:test_not_ok() +1..1" \ "$(bash_unit_out_for_code <&2" @@ -74,8 +74,8 @@ test_assertion_message_is_tap_formatted() { # Running tests in code not ok - test_not_ok # obvious failure -# code:2:test_not_ok()\ -" \ +# code:2:test_not_ok() +1..1" \ "$(bash_unit_out_for_code <