1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/env bash
- set -e
- set -u
- set -o pipefail
- source "${BASH_SOURCE%/*}/assertions.sh"
- test_get_absolute_path() {
- local current_dir=${1:?}
- local relative_dir=${2:?}
- source "${BASH_SOURCE%/*}/../src/utils/functions.sh"
- get_absolute_path "$current_dir" "$relative_dir"
- }
- test_get_absolute_path_old() {
- assert_equal \
- "test_get_absolute_path" \
- "/glux" \
- "$(test_get_absolute_path "/" "glux")"
- assert_equal \
- "test_get_absolute_path" \
- "/foo/bar/." \
- "$(test_get_absolute_path "/foo/bar" ".")"
- assert_equal \
- "test_get_absolute_path" \
- "/foo/bar/glux" \
- "$(test_get_absolute_path "/foo/bar" "glux")"
- }
- test_get_absolute_path_new() {
- source "${BASH_SOURCE%/*}/../src/utils/functions.sh"
- local beg_dir=${1:?}
- test "$(get_absolute_path_better "/")" == "/" || \
- echo "root path failed"
- test "$(get_absolute_path_better ".")" == "$(pwd)" || \
- echo "current directory failed"
- test "$(get_absolute_path_better "..")" == "$(dirname "$(pwd)")" || \
- echo "parent directory failed"
- test "$(get_absolute_path_better "./test_get_absolute_path")" == "$(pwd)/test_get_absolute_path" || \
- echo "path to this file failed"
- test "$(get_absolute_path_better "../README.org")" == "$(dirname "$(pwd)")/README.org" || \
- echo "path to sibling file failed"
- echo "INFO: Expect output to stderr:"
- test "$(get_absolute_path_better)" == "" || echo "no input failed"
- test "$(get_absolute_path_better "")" == "" || echo "empty string failed"
- test "$(get_absolute_path_better "/probably_no_such_path")" == "" || echo "bad path failed"
- if [[ "$beg_dir" != "$(pwd)" ]]; then
- echo "WARNING: We changed directories"
- fi
- }
- test_get_absolute_path_main() {
- echo "${FUNCNAME[0]}"
- test_get_absolute_path_old
- test_get_absolute_path_new "$(pwd)"
- }
- test_get_absolute_path_main
|