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:
parent
cf9a3b8af4
commit
741c414d6a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user