mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 19:52:37 +01:00
bats: Refactor resolve_link, abs_dirname
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.4s) from the current test suite. Before the change: 46 tests, 0 failures real 0m4.392s user 0m2.489s sys 0m1.467s After the change: real 0m3.980s user 0m2.312s sys 0m1.233s
This commit is contained in:
parent
6beea07a0b
commit
cdc55ad7ea
17
libexec/bats
17
libexec/bats
|
@ -26,18 +26,29 @@ help() {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BATS_READLINK=
|
||||||
|
|
||||||
resolve_link() {
|
resolve_link() {
|
||||||
$(type -p greadlink readlink | head -1) "$1"
|
if [[ -z "$BATS_READLINK" ]]; then
|
||||||
|
if command -v 'greadlink' >/dev/null; then
|
||||||
|
BATS_READLINK='greadlink'
|
||||||
|
elif command -v 'readlink' >/dev/null; then
|
||||||
|
BATS_READLINK='readlink'
|
||||||
|
else
|
||||||
|
BATS_READLINK='true'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
"$BATS_READLINK" "$1" || return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local cwd="$(pwd)"
|
local cwd="$PWD"
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
while [ -n "$path" ]; do
|
||||||
cd "${path%/*}"
|
cd "${path%/*}"
|
||||||
local name="${path##*/}"
|
local name="${path##*/}"
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name")"
|
||||||
done
|
done
|
||||||
|
|
||||||
pwd
|
pwd
|
||||||
|
|
Loading…
Reference in New Issue
Block a user