1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 19:52:37 +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() {
local name="$1"
local result="test_"
local hex_code
if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
name="${name//_/-5f}"
@ -21,12 +22,13 @@ encode_name() {
elif [[ "$char" =~ [[:alnum:]] ]]; then
result+="$char"
else
result+="$(printf -- "-%02x" \'"$char")"
printf -v 'hex_code' -- "-%02x" \'"$char"
result+="$hex_code"
fi
done
fi
echo "$result"
printf -v "$2" '%s' "$result"
}
tests=()
@ -40,7 +42,7 @@ while IFS= read -r line; do
quoted_name="${BASH_REMATCH[1]}"
body="${BASH_REMATCH[2]}"
name="$(eval echo "$quoted_name")"
encoded_name="$(encode_name "$name")"
encode_name "$name" 'encoded_name'
tests["${#tests[@]}"]="$encoded_name"
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
else