From eaa151fb698f9fdc3c4e29ab9275f9b9529665bd Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Wed, 15 Feb 2017 10:01:32 -0500 Subject: [PATCH] exec-test: Use printf -v in bats_trim_filename --- libexec/bats-exec-test | 11 ++++------- test/test_helper.bash | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index c9e0a7e..fce77aa 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -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 } diff --git a/test/test_helper.bash b/test/test_helper.bash index 84eee8c..302f743 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -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() {