Skip to content

Commit bbe31a3

Browse files
committed
Double quote to prevent globbing and word splitting
1 parent 969de74 commit bbe31a3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

bash_unit

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ fail() {
3030
local stdout=$2
3131
local stderr=$3
3232

33-
notify_test_failed $__bash_unit_current_test__ "$message"
34-
[[ ! -z $stdout ]] && [ -s $stdout ] && notify_stdout < $stdout
35-
[[ ! -z $stderr ]] && [ -s $stderr ] && notify_stderr < $stderr
33+
notify_test_failed "$__bash_unit_current_test__" "$message"
34+
[[ ! -z $stdout ]] && [ -s "$stdout" ] && notify_stdout < "$stdout"
35+
[[ ! -z $stderr ]] && [ -s "$stderr" ] && notify_stderr < "$stderr"
3636

3737
stacktrace | notify_stack
3838
exit 1
@@ -76,13 +76,13 @@ _assert_expression() {
7676
(
7777
local stdout=$(mktemp)
7878
local stderr=$(mktemp)
79-
trap "rm -f $stdout $stderr" EXIT
79+
trap "rm -f \"$stdout\" \"$stderr\"" EXIT
8080

8181
local status
82-
eval "($assertion)" >$stdout 2>$stderr && status=$? || status=$?
83-
if ! eval $condition
82+
eval "($assertion)" >"$stdout" 2>"$stderr" && status=$? || status=$?
83+
if ! eval "$condition"
8484
then
85-
fail "$(eval echo $message)" $stdout $stderr
85+
fail "$(eval echo $message)" "$stdout" "$stderr"
8686
fi
8787
) || exit $?
8888
}
@@ -132,7 +132,7 @@ stacktrace() {
132132

133133
run_test_suite() {
134134
local failure=0
135-
for test in $(set | grep -E '^test.* ()' | grep -E "$test_pattern" | sed -e 's: .*::')
135+
for test in $(set | grep -E '^test.* \(\)' | grep -E "$test_pattern" | sed -e 's: .*::')
136136
do
137137
(
138138
local status=0
@@ -204,7 +204,7 @@ pretty_failure() {
204204

205205
text_format() {
206206
notify_suite_starting() {
207-
test_file="$1"
207+
local test_file="$1"
208208
echo "Running tests in $test_file"
209209
}
210210
notify_test_starting() {
@@ -234,7 +234,7 @@ text_format() {
234234

235235
tap_format() {
236236
notify_suite_starting() {
237-
test_file="$1"
237+
local test_file="$1"
238238
echo "# Running tests in $test_file"
239239
}
240240
notify_test_starting() {

tests/test_bash_unit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ test_one_test_should_stop_when_assert_fails() {
224224
}
225225

226226
test_bash_unit_changes_cwd_to_current_test_file_directory() {
227-
assert "ls ../tests/$(basename $BASH_SOURCE)" \
227+
assert "ls ../tests/$(basename "$BASH_SOURCE")" \
228228
"bash_unit should change current working directory to match the directory of the currenlty running test"
229229
}
230230

tests/test_doc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ function _next_quote_section() {
6262
'
6363
}
6464

65-
cd $(dirname $0)
65+
cd "$(dirname "$0")"
6666
prepare_tests

0 commit comments

Comments
 (0)