Skip to content

Commit 8e12d55

Browse files
committed
- Update Approvals.bash to v0.5.1
1 parent b7165ed commit 8e12d55

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

lib/bashly/libraries/test/approvals.bash

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# approvals.bash v0.5.0
1+
# approvals.bash v0.5.1
22
#
33
# Interactive approval testing for Bash.
44
# https://github.com/DannyBen/approvals.bash
@@ -54,6 +54,10 @@ context() {
5454
printf "$context_string\n" "$*"
5555
}
5656

57+
it() {
58+
printf "$it_string\n" "$*"
59+
}
60+
5761
fail() {
5862
printf "$fail_string\n" "$*"
5963
exit 1
@@ -72,29 +76,57 @@ expect_exit_code() {
7276
fi
7377
}
7478

75-
bold() { printf "\e[1m%b\e[0m\n" "$*"; }
76-
blue() { printf "\e[34m%b\e[0m\n" "$*"; }
77-
cyan() { printf "\e[36m%b\e[0m\n" "$*"; }
78-
green() { printf "\e[32m%b\e[0m\n" "$*"; }
79-
magenta() { printf "\e[35m%b\e[0m\n" "$*"; }
80-
red() { printf "\e[31m%b\e[0m\n" "$*"; }
81-
yellow() { printf "\e[33m%b\e[0m\n" "$*"; }
82-
8379
# Private
8480

81+
print_in_color() {
82+
local color="$1"
83+
shift
84+
if [[ -z ${NO_COLOR+x} ]]; then
85+
printf "$color%b\e[0m\n" "$*"
86+
else
87+
printf "%b\n" "$*"
88+
fi
89+
}
90+
91+
red() { print_in_color "\e[31m" "$*"; }
92+
green() { print_in_color "\e[32m" "$*"; }
93+
yellow() { print_in_color "\e[33m" "$*"; }
94+
blue() { print_in_color "\e[34m" "$*"; }
95+
magenta() { print_in_color "\e[35m" "$*"; }
96+
cyan() { print_in_color "\e[36m" "$*"; }
97+
bold() { print_in_color "\e[1m" "$*"; }
98+
underlined() { print_in_color "\e[4m" "$*"; }
99+
red_bold() { print_in_color "\e[1;31m" "$*"; }
100+
green_bold() { print_in_color "\e[1;32m" "$*"; }
101+
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
102+
blue_bold() { print_in_color "\e[1;34m" "$*"; }
103+
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
104+
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
105+
red_underlined() { print_in_color "\e[4;31m" "$*"; }
106+
green_underlined() { print_in_color "\e[4;32m" "$*"; }
107+
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
108+
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
109+
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
110+
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }
111+
85112
user_approval() {
86113
local cmd="$1"
87114
local actual="$2"
88115
local approval_file="$3"
89116

90-
if [[ -v CI || -v GITHUB_ACTIONS ]]; then
117+
if [[ -v CI || -v GITHUB_ACTIONS ]] && [[ -z "${AUTO_APPROVE+x}" ]]; then
91118
fail "$cmd"
92119
fi
93120

94-
echo
95-
printf "$approval_string"
96-
response=$(bash -c "read -n 1 key; echo \$key")
97-
printf "\b%.s" $(seq 1 $((${#approval_string} + 1)))
121+
if [[ -v AUTO_APPROVE ]]; then
122+
response=a
123+
else
124+
echo
125+
printf "$approval_string"
126+
response=$(bash -c "read -n 1 key; echo \$key")
127+
printf "\b%.s" $(seq 1 $((${#approval_string} + 1)))
128+
fi
129+
98130
if [[ $response =~ [Aa] ]]; then
99131
printf "%b\n" "$actual" >"$approval_file"
100132
pass "$cmd"
@@ -122,14 +154,15 @@ set -e
122154
trap 'onexit' EXIT
123155
trap 'onerror' ERR
124156

125-
describe_string="$(blue ▌ describe) %s"
126-
context_string="$(magenta ▌ context) %s"
127-
fail_string=" $(red FAILED) %s"
157+
describe_string="$(bold ▌ describe) %s"
158+
context_string="$(bold ▌ context) %s"
159+
it_string="$(bold ▌ it) %s"
160+
fail_string=" $(red_bold failed) %s"
128161
pass_string=" $(green approved) %s"
129162
exit_success_string="$(green ▌ exit) $(bold %s finished successfully)"
130-
exit_failed_string="$(red ▌ exit) $(bold %s finished with errors)"
131-
new_diff_string="────┤ $(yellow new): $(bold %s)) ├────"
132-
changed_diff_string="────┤ $(cyan changed): $(bold %s)) ├────"
163+
exit_failed_string="$(red_bold ▌ exit) $(bold %s finished with errors)"
164+
new_diff_string="────┤ $(yellow new): $(bold %s) ├────"
165+
changed_diff_string="────┤ $(blue changed): $(bold %s) ├────"
133166
approval_string="[A]pprove? "
134167

135168
if diff --help | grep -- --color >/dev/null 2>&1; then

0 commit comments

Comments
 (0)