1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-09-29 20:48:27 +02:00

exec-test: Use printf -v in bats_trim_filename

This commit is contained in:
Mike Bland 2017-02-15 10:01:32 -05:00
parent 39440c5782
commit eaa151fb69
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B
2 changed files with 5 additions and 8 deletions

View File

@ -127,7 +127,7 @@ bats_print_stack_trace() {
for frame in "$@"; do
bats_frame_filename "$frame" 'filename'
filename="$(bats_trim_filename "$filename")"
bats_trim_filename "$filename" 'filename'
bats_frame_lineno "$frame" 'lineno'
if [ $index -eq 1 ]; then
@ -203,13 +203,10 @@ bats_strip_string() {
}
bats_trim_filename() {
local filename="$1"
local length="${#BATS_CWD}"
if [ "${filename:0:length+1}" = "${BATS_CWD}/" ]; then
echo "${filename:length+1}"
if [[ "$1" =~ ^${BATS_CWD}/ ]]; then
printf -v "$2" '%s' "${1#$BATS_CWD/}"
else
echo "$filename"
printf -v "$2" '%s' "$1"
fi
}

View File

@ -1,6 +1,6 @@
fixtures() {
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "$FIXTURE_ROOT")"
bats_trim_filename "$FIXTURE_ROOT" 'RELATIVE_FIXTURE_ROOT'
}
setup() {