From 6ace450571087815c51fbb8dc813aeebc17c525a Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 22:31:39 +0100 Subject: [PATCH 1/7] test: bashunit_with_multiple_failing_tests --- tests/acceptance/bashunit_fail_test.sh | 9 +++++++++ .../test_bashunit_with_multiple_failing_tests.sh | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index 7e7a1ea2..d887db72 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -44,6 +44,15 @@ function test_bashunit_when_a_test_fail_simple_output_option() { assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)" } +function test_bashunit_with_multiple_failing_tests() { + local test_file=./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh + + # shellcheck disable=SC2317 + assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)" + # shellcheck disable=SC2317 + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)" +} + function test_different_simple_snapshots_matches() { todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } diff --git a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh new file mode 100644 index 00000000..39eaed5e --- /dev/null +++ b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +function test_assert_same() { + assert_same 1 1 +} + +function test_assert_failing() { + assert_same 1 0 + assert_same 2 3 + assert_same 4 5 +} From 23dde3ba0f4e78a343c1e739179e825acfb0adca Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 22:34:33 +0100 Subject: [PATCH 2/7] test: add expected snapshot for test_bashunit_with_multiple_failing_tests --- ...hunit_with_multiple_failing_tests.snapshot | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot diff --git a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot new file mode 100644 index 00000000..459a62bf --- /dev/null +++ b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot @@ -0,0 +1,21 @@ +.F + +There was 1 failure: + +|1) ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh +|✗ Failed: Assert failing +| Expected '1' +| but got  '0' +|[failed]✗ Failed: Assert failing +| Expected '2' +| but got  '3' +|[failed]✗ Failed: Assert failing +| Expected '4' +| but got  '5' + + + +Tests:  1 passed, 1 failed, 2 total +Assertions: 1 passed, 3 failed, 4 total + + Some tests failed  From 6cda9d2cbb92e79b3dd83a31c680b5131ddc8d45 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 23:21:43 +0100 Subject: [PATCH 3/7] feat: add source to log() --- src/globals.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/globals.sh b/src/globals.sh index 7314b978..4e8a7f75 100644 --- a/src/globals.sh +++ b/src/globals.sh @@ -71,5 +71,7 @@ function log() { *) set -- "$level $@"; level="INFO" ;; esac - echo "$(current_timestamp) [$level]: $@" >> "$BASHUNIT_DEV_LOG" + local GRAY='\033[1;30m' + local RESET='\033[0m' + echo -e "$(current_timestamp) [$level]: $@ ${GRAY}#${BASH_SOURCE[1]}:${BASH_LINENO[0]}${RESET}" >> "$BASHUNIT_DEV_LOG" } From e72c8afacc4c95c6e1c7887e3eca91d98399431b Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 23:28:50 +0100 Subject: [PATCH 4/7] fix: multiple failure messages in same test --- src/runner.sh | 4 ++++ .../test_bashunit_with_multiple_failing_tests.sh | 5 ++--- ...st_bashunit_with_multiple_failing_tests.snapshot | 13 +++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/runner.sh b/src/runner.sh index 764b82b8..129bc1c5 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -187,6 +187,10 @@ function runner::run_test() { local type="${subshell_output%%]*}" # Remove everything after "]" type="${type#[}" # Remove the leading "[" local line="${subshell_output#*]}" # Remove everything before and including "]" + + # Replace [failed] with a newline to split failure messages + line=$(echo "$line" | sed 's/\[failed\]/\n/g') + state::print_line "$type" "$line" subshell_output=$line diff --git a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh index 39eaed5e..eed4604b 100644 --- a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh +++ b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh @@ -5,7 +5,6 @@ function test_assert_same() { } function test_assert_failing() { - assert_same 1 0 - assert_same 2 3 - assert_same 4 5 + assert_same 1 2 + assert_same 3 4 } diff --git a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot index 459a62bf..20301312 100644 --- a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot +++ b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot @@ -5,17 +5,14 @@ |1) ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh |✗ Failed: Assert failing | Expected '1' -| but got  '0' -|[failed]✗ Failed: Assert failing -| Expected '2' -| but got  '3' -|[failed]✗ Failed: Assert failing -| Expected '4' -| but got  '5' +| but got  '2' +|✗ Failed: Assert failing +| Expected '3' +| but got  '4' Tests:  1 passed, 1 failed, 2 total -Assertions: 1 passed, 3 failed, 4 total +Assertions: 1 passed, 2 failed, 3 total  Some tests failed  From d4a54e6bf010add6c9faf2101c984d07e4aaaaec Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 23:32:31 +0100 Subject: [PATCH 5/7] fix: skipped and incomplete tests on diff lines --- src/runner.sh | 4 +++- tests/acceptance/bashunit_fail_test.sh | 2 +- ...st_bashunit_with_multiple_failing_tests.sh | 10 ++++++++++ ...hunit_with_multiple_failing_tests.snapshot | 19 ++++++++++++++----- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/runner.sh b/src/runner.sh index 129bc1c5..39c589f6 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -189,7 +189,9 @@ function runner::run_test() { local line="${subshell_output#*]}" # Remove everything before and including "]" # Replace [failed] with a newline to split failure messages - line=$(echo "$line" | sed 's/\[failed\]/\n/g') + line=$(echo "$line" | sed -e 's/\[failed\]/\n/g' \ + -e 's/\[skipped\]/\n/g' \ + -e 's/\[incomplete\]/\n/g') state::print_line "$type" "$line" diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index d887db72..821747a9 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -48,7 +48,7 @@ function test_bashunit_with_multiple_failing_tests() { local test_file=./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh # shellcheck disable=SC2317 - assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)" + assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" # shellcheck disable=SC2317 assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" --simple)" } diff --git a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh index eed4604b..a4ea5377 100644 --- a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh +++ b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh @@ -8,3 +8,13 @@ function test_assert_failing() { assert_same 1 2 assert_same 3 4 } + +function test_assert_todo_and_skip() { + todo "foo" + skip "bar" +} + +function test_assert_skip_and_todo() { + skip "baz" + todo "yei" +} diff --git a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot index 20301312..16777156 100644 --- a/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot +++ b/tests/acceptance/snapshots/bashunit_fail_test_sh.test_bashunit_with_multiple_failing_tests.snapshot @@ -1,4 +1,15 @@ -.F +Running ./tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh +✓ Passed: Assert same +✗ Failed: Assert failing + Expected '1' + but got  '2' +✗ Failed: Assert failing + Expected '3' + but got  '4' +✒ Incomplete: Assert todo and skip foo +↷ Skipped: Assert todo and skip bar +↷ Skipped: Assert skip and todo baz +✒ Incomplete: Assert skip and todo yei There was 1 failure: @@ -10,9 +21,7 @@ | Expected '3' | but got  '4' - - -Tests:  1 passed, 1 failed, 2 total -Assertions: 1 passed, 2 failed, 3 total +Tests:  1 passed, 0 skipped, 2 incomplete, 1 failed, 4 total +Assertions: 1 passed, 2 skipped, 2 incomplete, 2 failed, 7 total  Some tests failed  From ae4fb03a32006ab73d74d4634efec9d29aa5b906 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 23:35:51 +0100 Subject: [PATCH 6/7] docs: update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 922d5ade..f4e266d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## Unreleased +- Fixed name rendered when having `test_test_*` +- Fixed display test with multiple outputs in multiline - Improved output: adding a space between each test file - Removed `BASHUNIT_DEV_MODE` in favor of `BASHUNIT_DEV_LOG` -- Fixed name rendered when having `test_test_*` +- Added source file and line on global dev function `log` ## [0.18.0](https://github.com/TypedDevs/bashunit/compare/0.17.0...0.18.0) - 2024-10-16 From c017f03bbfc7ea257f43bea5003e681614e4990e Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Thu, 5 Dec 2024 23:41:10 +0100 Subject: [PATCH 7/7] docs: update comment on runner.sh --- src/runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.sh b/src/runner.sh index 39c589f6..67706e04 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -188,7 +188,7 @@ function runner::run_test() { type="${type#[}" # Remove the leading "[" local line="${subshell_output#*]}" # Remove everything before and including "]" - # Replace [failed] with a newline to split failure messages + # Replace [type] with a newline to split the messages line=$(echo "$line" | sed -e 's/\[failed\]/\n/g' \ -e 's/\[skipped\]/\n/g' \ -e 's/\[incomplete\]/\n/g')