From 65e7178f42d84f2f9d4d8a02a90c8942a368136c Mon Sep 17 00:00:00 2001 From: Neil Davies <36968336+ndavies-om1@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:03:42 -0400 Subject: [PATCH 1/5] Adding plan to TAP output as per tap specs --- bash_unit | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/bash_unit b/bash_unit index 4699fcc..763ed56 100755 --- a/bash_unit +++ b/bash_unit @@ -33,7 +33,8 @@ CAT="$(type -P cat)" SED="$(type -P sed)" GREP="$(type -P grep)" RM="$(type -P rm)" -SHUF="$(type -P sort) -R" +SHUF="$(type -P shuf)" +TEMPFILE=$$.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 From 71763c192af854b893697a30dff836a581a5f520 Mon Sep 17 00:00:00 2001 From: Neil Davies <36968336+ndavies-om1@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:05:35 -0400 Subject: [PATCH 2/5] SHUF --- bash_unit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_unit b/bash_unit index 763ed56..085fbc7 100755 --- a/bash_unit +++ b/bash_unit @@ -33,7 +33,7 @@ CAT="$(type -P cat)" SED="$(type -P sed)" GREP="$(type -P grep)" RM="$(type -P rm)" -SHUF="$(type -P shuf)" +SHUF="$(type -P sort) -R" TEMPFILE=$$.tmp fail() { From cab26fcd743b05bfd9770346b7d25af98e485cdf Mon Sep 17 00:00:00 2001 From: ndavies-om1 Date: Tue, 29 Oct 2024 17:04:57 -0400 Subject: [PATCH 3/5] fixing tests --- bash_unit | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bash_unit b/bash_unit index 085fbc7..8e746ae 100755 --- a/bash_unit +++ b/bash_unit @@ -34,7 +34,7 @@ SED="$(type -P sed)" GREP="$(type -P grep)" RM="$(type -P rm)" SHUF="$(type -P sort) -R" -TEMPFILE=$$.tmp +TEMPFILE="$(pwd)/$$.tmp" fail() { local message=${1:-} @@ -267,7 +267,7 @@ run_tests() { failure=$(( $? || failure)) ((test_count++)) done - echo $test_count > $TEMPFILE + echo "${test_count}" > $TEMPFILE return $failure } @@ -573,9 +573,9 @@ done if ((failure)) then - notify_suites_failed $(cat $TEMPFILE) + notify_suites_failed $(cat "${TEMPFILE}") else - notify_suites_succeded $(cat $TEMPFILE) + notify_suites_succeded $(cat "${TEMPFILE}") fi unlink $TEMPFILE From 1b5c0c788916d8691cbd7f11d704e0701d6aab42 Mon Sep 17 00:00:00 2001 From: ndavies-om1 Date: Wed, 6 Nov 2024 08:53:12 -0500 Subject: [PATCH 4/5] further cleanup --- bash_unit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bash_unit b/bash_unit index 8e746ae..2454c7f 100755 --- a/bash_unit +++ b/bash_unit @@ -254,7 +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) + test_count=$(cat "${TEMPFILE}") for test in $tests_to_run do ( @@ -267,7 +267,7 @@ run_tests() { failure=$(( $? || failure)) ((test_count++)) done - echo "${test_count}" > $TEMPFILE + echo "${test_count}" > "${TEMPFILE}" return $failure } @@ -547,7 +547,7 @@ fi #run tests received as parameters failure=0 -echo 0 > $TEMPFILE +echo 0 > "${TEMPFILE}" for test_file in "$@" do notify_suite_starting "$test_file" From d5df1ff281f85dc0f45c04642b532e97d9627806 Mon Sep 17 00:00:00 2001 From: ndavies-om1 Date: Wed, 6 Nov 2024 09:02:49 -0500 Subject: [PATCH 5/5] fixing tap tests --- tests/test_tap_format | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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 <