Skip to content

Commit

Permalink
Distinguish skipped tests from pending tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrange committed Feb 21, 2024
1 parent bf95a3a commit 38882d1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
26 changes: 13 additions & 13 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ _(by the way, the documentation you are reading is itself tested with bash-unit)
skip tests which name matches the given pattern.
You can specify several patterns by repeating this option
for each pattern.
Tests will appear in *bash_unit* output as _pending_.
Tests will appear in *bash_unit* output as _skipped_.
(see also _skip_if_)

*-r*::
Expand Down Expand Up @@ -207,24 +207,24 @@ Overall result: SUCCESS
```

You can combine the _-p_ option with _-s_ to skip some of the tests. This option accepts a pattern
as parameter and mark as pending any test function which matches this pattern.
as parameter and mark as skipped any test function which matches this pattern.

```test
./bash_unit -p fail_fails -p assert -s no -s status tests/test_core.sh
```

```output
Running tests in tests/test_core.sh
Running test_assert_equals_fails_when_not_equal ... PENDING
Running test_assert_matches_fails_when_not_matching ... PENDING
Running test_assert_no_diff_fails_when_diff ... PENDING
Running test_assert_no_diff_succeeds_when_no_diff ... PENDING
Running test_assert_not_equals_fails_when_equal ... PENDING
Running test_assert_not_equals_succeeds_when_not_equal ... PENDING
Running test_assert_not_matches_fails_when_matching ... PENDING
Running test_assert_not_matches_succeed_when_not_matching ... PENDING
Running test_assert_status_code_fails ... PENDING
Running test_assert_status_code_succeeds ... PENDING
Running test_assert_equals_fails_when_not_equal ... SKIPPED
Running test_assert_matches_fails_when_not_matching ... SKIPPED
Running test_assert_no_diff_fails_when_diff ... SKIPPED
Running test_assert_no_diff_succeeds_when_no_diff ... SKIPPED
Running test_assert_not_equals_fails_when_equal ... SKIPPED
Running test_assert_not_equals_succeeds_when_not_equal ... SKIPPED
Running test_assert_not_matches_fails_when_matching ... SKIPPED
Running test_assert_not_matches_succeed_when_not_matching ... SKIPPED
Running test_assert_status_code_fails ... SKIPPED
Running test_assert_status_code_succeeds ... SKIPPED
Running test_assert_equals_succeed_when_equal ... SUCCESS
Running test_assert_fails ... SUCCESS
Running test_assert_fails_fails ... SUCCESS
Expand Down Expand Up @@ -642,7 +642,7 @@ test_darwin_proc_does_not_exist() {
will output, on a Linux system:

```output
Running test_darwin_proc_does_not_exist ... PENDING
Running test_darwin_proc_does_not_exist ... SKIPPED
Running test_linux_proc_exists ... SUCCESS
```

Expand Down
19 changes: 14 additions & 5 deletions bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ run_tests() {
for skipped_test in $(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -E "$skip_pattern" | "$SED" -e 's: .*::')
do
notify_test_starting "$skipped_test"
notify_test_pending "$skipped_test"
notify_test_skipped "$skipped_test"
done
local tests_to_run="$(set | "$GREP" -E '^test.* \(\)' | "$GREP" -E "$test_pattern" | "$GREP" -v -E "$skip_pattern" | "$SED" -e 's: .*::' | maybe_shuffle)"
else
Expand Down Expand Up @@ -363,7 +363,10 @@ text_format() {
echo -n "PENDING" | pretty_warning
echo
}

notify_test_skipped() {
echo -n "SKIPPED" | pretty_warning
echo
}
notify_test_succeeded() {
echo -n "SUCCESS" | pretty_success
echo
Expand Down Expand Up @@ -406,7 +409,13 @@ tap_format() {
local test="$1"
echo -n "ok" | pretty_warning -
echo -n "$test" | color "$BLUE"
echo " # skip test to be written" | color "$YELLOW"
echo " # todo test to be written" | color "$YELLOW"
}
notify_test_skipped() {
local test="$1"
echo -n "ok" | pretty_warning -
echo -n "$test" | color "$BLUE"
echo " # skip test not run" | color "$YELLOW"
}
notify_test_succeeded() {
local test="$1"
Expand Down Expand Up @@ -440,7 +449,7 @@ tap_format() {
skip_if() {
local condition="$1"
local pattern="$2"
if eval $condition >/dev/null 2>&1
if eval "$condition" >/dev/null 2>&1
then
skip_pattern="${skip_pattern}${skip_pattern_separator}${pattern}"
skip_pattern_separator="|"
Expand All @@ -452,7 +461,7 @@ test_pattern=""
test_pattern_separator=""
skip_pattern=""
skip_pattern_separator=""
randomise=0
randomize=0
while getopts "vp:s:f:r" option
do
case "$option" in
Expand Down
2 changes: 1 addition & 1 deletion getting_started/tests/test_skipping
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ test_darwin_proc_does_not_exist() {
}
test_another_test_to_run_only_on_darwin() {
assert "mkdir -p /tmp/foo/bar"
}
}
4 changes: 2 additions & 2 deletions tests/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ test_skipped_tests_appear_in_output() {

assert_equals "\
Running tests in test_file
Running test_three ... PENDING
Running test_two ... PENDING
Running test_three ... SKIPPED
Running test_two ... SKIPPED
Running test_one ... SUCCESS
Overall result: SUCCESS" \
"$bash_unit_output"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tap_format
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_tap_format_for_one_pending_test() {
assert_equals \
"\
# Running tests in code
ok - pending_not_yet_implemented # skip test to be written\
ok - pending_not_yet_implemented # todo test to be written\
" \
"$(bash_unit_out_for_code <<EOF
pending_not_yet_implemented() {
Expand Down

0 comments on commit 38882d1

Please sign in to comment.