Skip to content

Commit 4f1053d

Browse files
committed
- Update approvals.bash (bashly add test) to v0.3.3
1 parent a71d313 commit 4f1053d

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

lib/bashly/templates/test/approvals.bash

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# approvals.bash v0.3.2
1+
# approvals.bash v0.3.3
22
#
33
# Interactive approval testing for Bash.
44
# https://github.com/DannyBen/approvals.bash
55
approve() {
66
local expected approval approval_file actual cmd
77
approvals_dir=${APPROVALS_DIR:=approvals}
8-
8+
99
cmd=$1
10-
actual=$(eval "$cmd" 2>&1)
11-
last_exit_code=$?
10+
last_exit_code=0
11+
actual=$(eval "$cmd" 2>&1) || last_exit_code=$?
1212
approval=$(printf "%b" "$cmd" | tr -s -c "[:alnum:]" _)
1313
approval_file="$approvals_dir/${2:-"$approval"}"
1414

@@ -29,28 +29,29 @@ approve() {
2929
pass "$cmd"
3030
else
3131
echo "--- [$(blue "diff: $cmd")] ---"
32-
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n" ) | tail -n +4
32+
$diff_cmd <(printf "%b" "$expected\n") <(printf "%b" "$actual\n") | tail -n +4
3333
echo "--- [$(blue "diff: $cmd")] ---"
3434
user_approval "$cmd" "$actual" "$approval_file"
3535
fi
3636
}
3737

3838
describe() {
39-
echo " $*"
39+
echo
40+
blue "= $*"
4041
}
4142

4243
context() {
4344
echo
44-
echo "$*"
45+
magenta "= $*"
4546
}
4647

4748
fail() {
48-
red " FAILED $*"
49+
red " FAILED: $*"
4950
exit 1
5051
}
5152

5253
pass() {
53-
green " approved: $*"
54+
green " approved: $*"
5455
return 0
5556
}
5657

@@ -79,12 +80,12 @@ user_approval() {
7980
fail "$cmd"
8081
fi
8182

82-
echo
83+
echo
8384
printf "[A]pprove? \n"
8485
response=$(bash -c "read -n 1 key; echo \$key")
8586
printf "\r"
8687
if [[ $response =~ [Aa] ]]; then
87-
printf "%b\n" "$actual" > "$approval_file"
88+
printf "%b\n" "$actual" >"$approval_file"
8889
pass "$cmd"
8990
else
9091
fail "$cmd"
@@ -109,7 +110,7 @@ set -e
109110
trap 'onexit' EXIT
110111
trap 'onerror' ERR
111112

112-
if diff --help | grep -- --color > /dev/null 2>&1; then
113+
if diff --help | grep -- --color >/dev/null 2>&1; then
113114
diff_cmd="diff --unified --color=always"
114115
else
115116
diff_cmd="diff --unified"

lib/bashly/templates/test/approve

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,23 @@
33

44
cd ./test || exit
55
source approvals.bash
6-
PATH="$PATH:../"
76

87
# Update me
9-
cli=download
8+
cli=./download
109

11-
# Tests (context and describe are optional)
10+
# Tests (context, describe and indentation are optional)
1211
context "when DEBUG is on"
1312
export DEBUG=1
1413

1514
describe "root command"
16-
# for commands that fail (like without parameters), we add || 0
17-
approve "$cli" || 0
15+
approve "$cli"
1816
approve "$cli --help"
1917

2018
context "when DEBUG is off"
2119
unset DEBUG
2220

2321
describe "some other command"
24-
approve "$cli other" || 0
22+
approve "$cli other"
2523
approve "$cli other --help"
2624

2725
# ...more tests...

0 commit comments

Comments
 (0)