Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Fix abs_dirname #224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ resolve_link() {
}

abs_dirname() {
local cwd="$(pwd)"
local path="$1"
local save_cwd="$PWD"
local cd_path name

while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
cd_path="${path%/*}"
if [[ "$cd_path" != "$path" ]]; then
cd "$cd_path"
fi
name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
cd "$cwd"
echo "$PWD"
cd "$save_cwd"
}

PREFIX="$1"
Expand Down
14 changes: 9 additions & 5 deletions libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ resolve_link() {
}

abs_dirname() {
local cwd="$(pwd)"
local path="$1"
local save_cwd="$PWD"
local cd_path name

while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
cd_path="${path%/*}"
if [[ "$cd_path" != "$path" ]]; then
cd "$cd_path"
fi
name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
cd "$cwd"
echo "$PWD"
cd "$save_cwd"
}

expand_path() {
Expand Down
10 changes: 10 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,13 @@ fixtures bats
[ $status -eq 0 ]
[ "${lines[1]}" = "ok 1 loop_func" ]
}

@test "abs_dirname with symlink to same current directory" {
cd "$TMP"
ln -s $(which bats) bats
ln -s bats bats-linked
run ./bats-linked "$FIXTURE_ROOT/loop_keep_IFS.bats"
[ $status -eq 0 ]
expected_lines=("1..1" "ok 1 loop_func")
[ "${lines}" = "${expected_lines}" ]
}