11#! /usr/bin/env bash
22
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" ;
465
476# ####################
487# Begin Script Body #
@@ -52,11 +11,11 @@ declare -a errors=();
5211
5312log ' info' ' ### Testing symlink functionality' ;
5413
55- TFENV_BIN_DIR=' /tmp/tfenv-test ' ;
56- log ' info' " ## Creating/clearing ${TFENV_BIN_DIR} "
57- rm -rf " ${TFENV_BIN_DIR} " && mkdir " ${TFENV_BIN_DIR} " ;
58- log ' info' " ## Symlinking ${PWD } /bin/* into ${TFENV_BIN_DIR} " ;
59- ln -s " ${PWD } " /bin/* " ${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 ;
17+ log ' info' " ## Symlinking ${TFENV_ROOT } /bin/* into ${TFENV_BIN_DIR} " ;
18+ ln -s " ${TFENV_ROOT } " /bin/* " ${TFENV_BIN_DIR} " ;
6019
6120cleanup || log ' error' ' Cleanup failed?!' ;
6221
0 commit comments