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

bats: Convert abs_dirname to use printf -v

Under Bash 3.2.57(1)-release and 4.4.12(1)-release on a MacBook Pro with
a 2.9GHz Intel Core i5 CPU and 8GB 1867MHz DDR3 RAM, this shaves off
O(0.1s) from the current test suite.

Before the change:

  46 tests, 0 failures

  real    0m3.983s
  user    0m2.320s
  sys     0m1.241s

After the change:

  real    0m3.861s
  user    0m2.276s
  sys     0m1.174s
This commit is contained in:
Mike Bland 2017-03-16 12:25:17 -04:00
parent cdc55ad7ea
commit daf76c27c1
No known key found for this signature in database
GPG Key ID: 5121C73A6E07384B

View File

@ -51,7 +51,7 @@ abs_dirname() {
path="$(resolve_link "$name")"
done
pwd
printf -v "$2" -- '%s' "$PWD"
cd "$cwd"
}
@ -63,9 +63,12 @@ expand_path() {
} || echo "$1"
}
BATS_LIBEXEC="$(abs_dirname "$0")"
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
export BATS_CWD="$(abs_dirname .)"
abs_dirname "$0" 'BATS_LIBEXEC'
abs_dirname "$BATS_LIBEXEC" 'BATS_PREFIX'
abs_dirname '.' 'BATS_CWD'
export BATS_PREFIX
export BATS_CWD
export PATH="$BATS_LIBEXEC:$PATH"
options=()