Skip to content

Commit 3829ce8

Browse files
committed
ADD pending and/or todo keywords
Fix #38
1 parent 7805815 commit 3829ce8

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ You may write a *teardown* function that will be exectuted after each test is ru
188188

189189
If you need to set someting up only once for all tests, simply write your code outside any test function, this is a bash script.
190190

191+
If you want to keep an eye on a test not yet implemented, prefix the name of the function by *todo* instead of test.
192+
Test to do are not executed and do not impact the global status of your test suite but are displayed in *bash_unit* output.
193+
191194
*bash_unit* changes the current working directory to the one of the running test file. If you need to access files from your test code, for instance the script under test, use path relative to the test file.
192195

193196
You may need to change the behavior of some commands to create conditions for your code under test to behave as expected. The *fake* function may help you to do that, see bellow.

bash_unit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ stacktrace() {
132132

133133
run_test_suite() {
134134
local failure=0
135+
136+
for pending_test in $(set | grep -E '^(pending|todo).* \(\)' | grep -E "$test_pattern" | sed -e 's: .*::')
137+
do
138+
notify_test_starting "$pending_test"
139+
notify_test_pending "$pending_test"
140+
done
141+
142+
135143
for test in $(set | grep -E '^test.* \(\)' | grep -E "$test_pattern" | sed -e 's: .*::')
136144
do
137145
(
@@ -169,6 +177,10 @@ pretty_success() {
169177
pretty_format "$GREEN" "\u2713" "$1"
170178
}
171179

180+
pretty_warning() {
181+
pretty_format "$YELLOW" "\u2717" "$1"
182+
}
183+
172184
pretty_failure() {
173185
pretty_format "$RED" "\u2717" "$1"
174186
}
@@ -225,6 +237,11 @@ text_format() {
225237
local test="$1"
226238
echo -n "Running $test... " | color "$BLUE"
227239
}
240+
notify_test_pending() {
241+
echo -n "PENDING" | pretty_warning
242+
echo
243+
}
244+
228245
notify_test_succeeded() {
229246
echo -n "SUCCESS" | pretty_success
230247
echo
@@ -254,6 +271,12 @@ tap_format() {
254271
notify_test_starting() {
255272
echo -n
256273
}
274+
notify_test_pending() {
275+
local test="$1"
276+
echo -n "ok" | pretty_warning -
277+
echo -n "$test" | color "$BLUE"
278+
echo " # skip test to be written" | color "$YELLOW"
279+
}
257280
notify_test_succeeded() {
258281
local test="$1"
259282
echo -n "ok" | pretty_success -

tests/test_cli.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ Running test_one... SUCCESS
4949
Running tests in test_file" "$bash_unit_output"
5050
}
5151

52+
test_do_not_run_pending_tests() {
53+
assert "$BASH_UNIT \
54+
<(echo 'pending_should_not_run() { fail ; }
55+
todo_should_not_run() { fail ; }') \
56+
"
57+
}
58+
59+
test_pending_tests_appear_in_output() {
60+
bash_unit_output=$($BASH_UNIT \
61+
<(echo 'pending_should_not_run() { fail ; }
62+
todo_should_not_run() { fail ; }') \
63+
| sed -e 's:/dev/fd/[0-9]*:test_file:' \
64+
)
65+
66+
assert_equals "\
67+
Running tests in test_file
68+
Running pending_should_not_run... PENDING
69+
Running todo_should_not_run... PENDING" \
70+
"$bash_unit_output"
71+
}
72+
5273
test_fails_when_test_file_does_not_exist() {
5374
assert_fail "$BASH_UNIT /not_exist/not_exist"
5475
}

tests/test_tap_format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ EOF
3737
)"
3838
}
3939

40+
test_tap_format_for_one_pending_test() {
41+
assert_equals \
42+
"\
43+
# Running tests in code
44+
ok - pending_not_yet_implemented # skip test to be written\
45+
" \
46+
"$(bash_unit_out_for_code <<EOF
47+
pending_not_yet_implemented() {
48+
assert false
49+
}
50+
EOF
51+
)"
52+
}
53+
4054
test_tap_format_for_failing_test_with_stdout_stderr_outputs() {
4155
assert_equals \
4256
"\

0 commit comments

Comments
 (0)