diff options
author | Melissa Xie <melissa@thoughtbot.com> | 2014-11-14 14:46:29 -0500 |
---|---|---|
committer | Mike Burns <mike@mike-burns.com> | 2014-11-17 14:44:18 -0800 |
commit | f29b24cf13ca5f141b8386614b353d75fedd71b9 (patch) | |
tree | 748f9a6da2feebf033fd0b991745d610149a9ded | |
parent | fbd4f8c544f7cdd4f2052dff1435f059accf2d47 (diff) |
Manually resolve symlinks in test helpers
Mac OS X's `readlink` command does not support the same options as GNU,
FreeBSD, and other operating systems, nor does it support canonicalizing
symlink resolutions.
In place of `readlink`, we're going to borrow [this] suggested
implementation from the community.
[this]:
http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
-rw-r--r-- | NEWS.md.in | 2 | ||||
-rw-r--r-- | test/helper.sh | 21 |
2 files changed, 22 insertions, 1 deletions
@@ -1,5 +1,7 @@ rcm (@PACKAGE_VERSION@) unstable; urgency=low + * BUGFIX: Use custom function instead of `readlink` to resolve symlinks in + test helpers (Melissa Xie). * Show usage information when given bad arguments (Mike Burns). -- Mike Burns <mburns@thoughtbot.com> Fri, 09 May 2014 14:17:49 +0200 diff --git a/test/helper.sh b/test/helper.sh index 539e270..86ff989 100644 --- a/test/helper.sh +++ b/test/helper.sh @@ -25,9 +25,28 @@ refute() { return 0 } +resolved_path() { + local original_path="$1" + local actual_path="$original_path" + local actual_basename="$(basename "$original_path")" + + cd "$(dirname "$original_path")" + + while [ -L "$actual_basename" ]; do + actual_path="$(readlink "$actual_basename")" + actual_basename="$(basename "$actual_path")" + + cd "$(dirname "$actual_path")" + done + + local current_directory="$(pwd -P)" + + printf "%s/%s\n" "$current_directory" "$actual_basename" +} + assert_linked() { local from="$1" to="$2" - local resolved="$(readlink -f "$from")" + local resolved="$(resolved_path "$from")" assert "$from should be a symlink" -h "$from" assert "$from should resolve to $to, resolved to $resolved" "$resolved" = "$to" |