|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -set -uo pipefail; |
4 | | - |
5 | | -#################################### |
6 | | -# Ensure we can execute standalone # |
7 | | -#################################### |
8 | | - |
9 | | -function early_death() { |
10 | | - echo "[FATAL] ${0}: ${1}" >&2; |
11 | | - exit 1; |
12 | | -}; |
13 | | - |
14 | | -if [ -z "${TFENV_ROOT:-""}" ]; then |
15 | | - # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac |
16 | | - readlink_f() { |
17 | | - local target_file="${1}"; |
18 | | - local file_name; |
19 | | - |
20 | | - while [ "${target_file}" != "" ]; do |
21 | | - cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT"; |
22 | | - file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT"; |
23 | | - target_file="$(readlink "${file_name}")"; |
24 | | - done; |
25 | | - |
26 | | - echo "$(pwd -P)/${file_name}"; |
27 | | - }; |
28 | | - |
29 | | - TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; |
30 | | - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; |
31 | | -else |
32 | | - TFENV_ROOT="${TFENV_ROOT%/}"; |
33 | | -fi; |
34 | | -export TFENV_ROOT; |
35 | | - |
36 | | -if [ -n "${TFENV_HELPERS:-""}" ]; then |
37 | | - log 'debug' 'TFENV_HELPERS is set, not sourcing helpers again'; |
38 | | -else |
39 | | - [ "${TFENV_DEBUG:-0}" -gt 0 ] && echo "[DEBUG] Sourcing helpers from ${TFENV_ROOT}/lib/helpers.sh"; |
40 | | - if source "${TFENV_ROOT}/lib/helpers.sh"; then |
41 | | - log 'debug' 'Helpers sourced successfully'; |
42 | | - else |
43 | | - early_death "Failed to source helpers from ${TFENV_ROOT}/lib/helpers.sh"; |
44 | | - fi; |
45 | | -fi; |
| 3 | +# Source common test setup |
| 4 | +source "$(dirname "${0}")/test_common.sh"; |
46 | 5 |
|
47 | 6 | ##################### |
48 | 7 | # Begin Script Body # |
49 | 8 | ##################### |
50 | 9 |
|
51 | | -export PATH="${TFENV_ROOT}/bin:${PATH}"; |
52 | | - |
53 | 10 | declare -a errors=(); |
54 | 11 |
|
55 | 12 | log 'info' '### Testing symlink functionality'; |
56 | 13 |
|
57 | | -TFENV_BIN_DIR='/tmp/tfenv-test'; |
58 | | -log 'info' "## Creating/clearing ${TFENV_BIN_DIR}" |
59 | | -rm -rf "${TFENV_BIN_DIR}" && mkdir "${TFENV_BIN_DIR}"; |
| 14 | +TFENV_BIN_DIR="$(mktemp -d)"; |
| 15 | +log 'info' "## Using temporary directory ${TFENV_BIN_DIR}"; |
| 16 | +trap 'rm -rf "${TFENV_BIN_DIR}"' EXIT; |
60 | 17 | log 'info' "## Symlinking ${TFENV_ROOT}/bin/* into ${TFENV_BIN_DIR}"; |
61 | 18 | ln -s "${TFENV_ROOT}"/bin/* "${TFENV_BIN_DIR}"; |
62 | 19 |
|
|
0 commit comments