Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plan to tap output #131

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 24 additions & 15 deletions bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
GREP="$(type -P grep)"
RM="$(type -P rm)"
SHUF="$(type -P sort) -R"
TEMPFILE="$(pwd)/$$.tmp"

fail() {
local message=${1:-}
Expand Down Expand Up @@ -185,16 +186,6 @@
"$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
Expand Down Expand Up @@ -263,6 +254,7 @@
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
(
Expand All @@ -273,7 +265,10 @@
exit $status
)
failure=$(( $? || failure))
((test_count++))
done
echo "${test_count}" > "${TEMPFILE}"

return $failure
}

Expand Down Expand Up @@ -455,10 +450,12 @@
"$SED" 's:^:# :' | color "$YELLOW"
}
notify_suites_succeded() {
:
local message="$1"
echo "1..$message"
}
notify_suites_failed() {
:
local message="$1"
echo "1..$message"
}
}

Expand All @@ -477,6 +474,16 @@
}
}

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=""
Expand Down Expand Up @@ -540,6 +547,7 @@

#run tests received as parameters
failure=0
echo 0 > "${TEMPFILE}"
for test_file in "$@"
do
notify_suite_starting "$test_file"
Expand All @@ -562,12 +570,13 @@
)
failure=$(( $? || failure))
done

if ((failure))
then
notify_suites_failed
notify_suites_failed $(cat "${TEMPFILE}")

Check failure on line 576 in bash_unit

View workflow job for this annotation

GitHub Actions / pre-commit

notify_suites_failed $(cat "${TEMPFILE}") ^------------------^ SC2046 (warning): Quote this to prevent word splitting.
else
notify_suites_succeded
notify_suites_succeded $(cat "${TEMPFILE}")

Check failure on line 578 in bash_unit

View workflow job for this annotation

GitHub Actions / pre-commit

notify_suites_succeded $(cat "${TEMPFILE}") ^------------------^ SC2046 (warning): Quote this to prevent word splitting.
fi

unlink $TEMPFILE

Check failure on line 581 in bash_unit

View workflow job for this annotation

GitHub Actions / pre-commit

unlink $TEMPFILE ^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.
exit $failure
24 changes: 12 additions & 12 deletions tests/test_tap_format
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
test_ok() {
assert true
Expand All @@ -27,8 +27,8 @@ test_tap_format_for_one_failing_test() {
"\
# Running tests in code
not ok - test_not_ok
# code:2:test_not_ok()\
" \
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
test_not_ok() {
assert false
Expand All @@ -41,8 +41,8 @@ test_tap_format_for_one_pending_test() {
assert_equals \
"\
# Running tests in code
ok - pending_not_yet_implemented # todo test to be written\
" \
ok - pending_not_yet_implemented # todo test to be written
1..0" \
"$(bash_unit_out_for_code <<EOF
pending_not_yet_implemented() {
assert false
Expand All @@ -58,8 +58,8 @@ test_tap_format_for_failing_test_with_stdout_stderr_outputs() {
not ok - test_not_ok
# out> message on stdout
# err> message on stderr
# code:2:test_not_ok()\
" \
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
test_not_ok() {
assert_fails "echo message on stdout ; echo message on stderr >&2"
Expand All @@ -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 <<EOF
test_not_ok() {
assert_fails true "obvious failure"
Expand All @@ -91,8 +91,8 @@ test_multi_lines_assertion_message_is_tap_formatted() {
not ok - test_not_ok
# obvious failure
# on multiple lines
# code:2:test_not_ok()\
" \
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
test_not_ok() {
assert_fails true "obvious failure\non multiple lines"
Expand Down
Loading