forked from tfutils/tfenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_symlink.sh
executable file
·83 lines (65 loc) · 2.5 KB
/
test_symlink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
set -uo pipefail;
####################################
# Ensure we can execute standalone #
####################################
function early_death() {
echo "[FATAL] ${0}: ${1}" >&2;
exit 1;
};
if [ -z "${TFENV_ROOT:-""}" ]; then
# http:https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
readlink_f() {
local target_file="${1}";
local file_name;
while [ "${target_file}" != "" ]; do
cd "$(dirname ${target_file})" || early_death "Failed to 'cd \$(dirname ${target_file})' while trying to determine TFENV_ROOT";
file_name="$(basename "${target_file}")" || early_death "Failed to 'basename \"${target_file}\"' while trying to determine TFENV_ROOT";
target_file="$(readlink "${file_name}")";
done;
echo "$(pwd -P)/${file_name}";
};
TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)";
[ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT";
else
TFENV_ROOT="${TFENV_ROOT%/}";
fi;
export TFENV_ROOT;
if [ -n "${TFENV_HELPERS:-""}" ]; then
log 'debug' 'TFENV_HELPERS is set, not sourcing helpers again';
else
[ "${TFENV_DEBUG:-0}" -gt 0 ] && echo "[DEBUG] Sourcing helpers from ${TFENV_ROOT}/lib/helpers.sh";
if source "${TFENV_ROOT}/lib/helpers.sh"; then
log 'debug' 'Helpers sourced successfully';
else
early_death "Failed to source helpers from ${TFENV_ROOT}/lib/helpers.sh";
fi;
fi;
#####################
# Begin Script Body #
#####################
declare -a errors=();
log 'info' '### Testing symlink functionality';
TFENV_BIN_DIR='/tmp/tfenv-test';
log 'info' "## Creating/clearing ${TFENV_BIN_DIR}"
rm -rf "${TFENV_BIN_DIR}" && mkdir "${TFENV_BIN_DIR}";
log 'info' "## Symlinking ${PWD}/bin/* into ${TFENV_BIN_DIR}";
ln -s "${PWD}"/bin/* "${TFENV_BIN_DIR}";
cleanup || log 'error' 'Cleanup failed?!';
log 'info' '## Installing 0.8.2';
${TFENV_BIN_DIR}/tfenv install 0.8.2 || error_and_proceed 'Install failed';
log 'info' '## Using 0.8.2';
${TFENV_BIN_DIR}/tfenv use 0.8.2 || error_and_proceed 'Use failed';
log 'info' '## Check-Version for 0.8.2';
check_active_version 0.8.2 || error_and_proceed 'Version check failed';
if [ "${#errors[@]}" -gt 0 ]; then
log 'warn' '===== The following symlink tests failed =====';
for error in "${errors[@]}"; do
log 'warn' "\t${error}";
done;
log 'error' 'Symlink test failure(s)';
exit 1;
else
log 'info' 'All symlink tests passed.';
fi;
exit 0;