File tree Expand file tree Collapse file tree 4 files changed +44
-14
lines changed Expand file tree Collapse file tree 4 files changed +44
-14
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
3838describe () {
39- cyan " TEST $* "
39+ echo " $* "
40+ }
41+
42+ context () {
43+ echo
44+ echo " $* "
4045}
4146
4247fail () {
43- red " FAIL $* "
48+ red " FAILED $* "
4449 exit 1
4550}
4651
4752pass () {
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+
89112if diff --help | grep -- --color > /dev/null 2>&1 ; then
90113 diff_cmd=" diff --unified --color=always"
91114else
Original file line number Diff line number Diff line change @@ -8,13 +8,20 @@ PATH="$PATH:../"
88# Update me
99cli=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...
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ created spec/tmp/test/approve
33
44Edit your tests in test/approve and then run:
55
6- $ ./ test/approve"
6+ $ test/approve
77
88Docs: https://github.com/DannyBen/approvals.bash
99
You can’t perform that action at this time.
0 commit comments