1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 11:42:33 +01:00

preprocess: Use printf -v in encode_name

This commit is contained in:
Mike Bland 2017-02-15 11:01:34 -05:00
parent cf9a3b8af4
commit 741c414d6a
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B

View File

@ -4,6 +4,7 @@ set -e
encode_name() { encode_name() {
local name="$1" local name="$1"
local result="test_" local result="test_"
local hex_code
if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
name="${name//_/-5f}" name="${name//_/-5f}"
@ -21,12 +22,13 @@ encode_name() {
elif [[ "$char" =~ [[:alnum:]] ]]; then elif [[ "$char" =~ [[:alnum:]] ]]; then
result+="$char" result+="$char"
else else
result+="$(printf -- "-%02x" \'"$char")" printf -v 'hex_code' -- "-%02x" \'"$char"
result+="$hex_code"
fi fi
done done
fi fi
echo "$result" printf -v "$2" '%s' "$result"
} }
tests=() tests=()
@ -40,7 +42,7 @@ while IFS= read -r line; do
quoted_name="${BASH_REMATCH[1]}" quoted_name="${BASH_REMATCH[1]}"
body="${BASH_REMATCH[2]}" body="${BASH_REMATCH[2]}"
name="$(eval echo "$quoted_name")" name="$(eval echo "$quoted_name")"
encoded_name="$(encode_name "$name")" encode_name "$name" 'encoded_name'
tests["${#tests[@]}"]="$encoded_name" tests["${#tests[@]}"]="$encoded_name"
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}" echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
else else