Skip to content

Commit 070a2b3

Browse files
committed
- Update approvals.bash (bashly add test) to v0.3.2
1 parent 72cdcfa commit 070a2b3

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

lib/bashly/libraries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test:
3737
post_install_message: |
3838
Edit your tests in !txtgrn!test/approve!txtrst! and then run:
3939
40-
!txtpur!$ ./test/approve!txtrst!"
40+
!txtpur!$ test/approve!txtrst!
4141
4242
Docs: !undblu!https://github.com/DannyBen/approvals.bash
4343

lib/bashly/templates/test/approvals.bash

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# approvals.bash v0.2.7
1+
# approvals.bash v0.3.2
22
#
33
# Interactive approval testing for Bash.
44
# https://github.com/DannyBen/approvals.bash
@@ -26,7 +26,7 @@ approve() {
2626
fi
2727

2828
if [[ "$(printf "%b" "$actual")" = "$(printf "%b" "$expected")" ]]; then
29-
green "PASS $cmd"
29+
pass "$cmd"
3030
else
3131
echo "--- [$(blue "diff: $cmd")] ---"
3232
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n" ) | tail -n +4
@@ -36,16 +36,21 @@ approve() {
3636
}
3737

3838
describe() {
39-
cyan "TEST $*"
39+
echo " $*"
40+
}
41+
42+
context() {
43+
echo
44+
echo "$*"
4045
}
4146

4247
fail() {
43-
red "FAIL $*"
48+
red " FAILED $*"
4449
exit 1
4550
}
4651

4752
pass() {
48-
green "PASS $*"
53+
green " approved: $*"
4954
return 0
5055
}
5156

@@ -86,6 +91,24 @@ user_approval() {
8691
fi
8792
}
8893

94+
onexit() {
95+
exitcode=$?
96+
if [[ "$exitcode" == 0 ]]; then
97+
green "\nFinished successfully"
98+
else
99+
red "\nFinished with failures"
100+
fi
101+
exit $exitcode
102+
}
103+
104+
onerror() {
105+
fail "Caller: $(caller)"
106+
}
107+
108+
set -e
109+
trap 'onexit' EXIT
110+
trap 'onerror' ERR
111+
89112
if diff --help | grep -- --color > /dev/null 2>&1; then
90113
diff_cmd="diff --unified --color=always"
91114
else

lib/bashly/templates/test/approve

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ PATH="$PATH:../"
88
# Update me
99
cli=download
1010

11-
# Tests
12-
describe "root command"
13-
approve "$cli"
14-
approve "$cli --help"
11+
# Tests (context and describe are optional)
12+
context "when DEBUG is on"
13+
export DEBUG=1
1514

16-
describe "some other command"
17-
approve "$cli other"
18-
approve "$cli other --help"
15+
describe "root command"
16+
# for commands that fail (like without parameters), we add || 0
17+
approve "$cli" || 0
18+
approve "$cli --help"
19+
20+
context "when DEBUG is off"
21+
unset DEBUG
22+
23+
describe "some other command"
24+
approve "$cli other" || 0
25+
approve "$cli other --help"
1926

2027
# ...more tests...

spec/approvals/cli/add/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ created spec/tmp/test/approve
33

44
Edit your tests in test/approve and then run:
55

6-
$ ./test/approve"
6+
$ test/approve
77

88
Docs: https://github.com/DannyBen/approvals.bash
99

0 commit comments

Comments
 (0)