File tree Expand file tree Collapse file tree 2 files changed +32
-10
lines changed
Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,33 @@ setUp () {
2424test_tempfile () {
2525 filename=$( virtualenvwrapper_tempfile hook)
2626 assertTrue " Filename is empty" " [ ! -z \" $filename \" ]"
27+ assertTrue " File doesn't exist" " [ -f \" $filename \" ]"
2728 rm -f $filename
2829 comparable_tmpdir=$( echo $tmplocation | sed ' s|/$||' )
2930 comparable_dirname=$( dirname $filename | sed ' s|/$||' )
3031 assertSame " Temporary directory \" $tmplocation \" and path not the same for $filename " " $comparable_tmpdir " " $comparable_dirname "
3132 assertTrue " virtualenvwrapper-hook not in filename." " echo $filename | grep virtualenvwrapper-hook"
3233}
3334
35+ test_bad_mktemp () {
36+ # All of the following bogus mktemp programs should cause
37+ # virtualenvwrapper_tempfile to return non-zero status
38+ mktemp_nonzero () { return 1; }
39+ mktemp_empty_string () { return 0; }
40+ mktemp_missing_executable () { /foo/bar/baz/qux 2> /dev/null; } # returns status 127
41+ mktemp_missing_result () { echo /foo/bar/baz/qux; }
42+
43+ for mktemp_func in mktemp_nonzero mktemp_empty_string \
44+ mktemp_missing_executable mktemp_missing_result
45+ do
46+ mktemp () { $mktemp_func " $@ " ; }
47+ filename=$( virtualenvwrapper_tempfile hook)
48+ assertSame " ($mktemp_func ) Unexpected exit code $? " " 1" " $? "
49+ done
50+
51+ unset -f mktemp
52+ }
53+
3454test_no_such_tmpdir () {
3555 old_tmpdir=" $TMPDIR "
3656 export TMPDIR=" $tmplocation /does-not-exist"
Original file line number Diff line number Diff line change @@ -130,28 +130,29 @@ function virtualenvwrapper_verify_workon_home {
130130function virtualenvwrapper_tempfile {
131131 # Note: the 'X's must come last
132132 typeset suffix=${1:- hook}
133- typeset file=" ` \m ktemp -t virtualenvwrapper-$suffix -XXXXXXXXXX` "
134- if [ $? -ne 0 ]
133+ typeset file
134+
135+ file=" ` \m ktemp -t virtualenvwrapper-$suffix -XXXXXXXXXX` "
136+ if [ $? -ne 0 ] || [ -z " $file " ] || [ ! -f " $file " ]
135137 then
136138 echo " ERROR: virtualenvwrapper could not create a temporary file name." 1>&2
137139 return 1
138140 fi
139- trap " \rm -f '$file ' >/dev/null 2>&1" EXIT
140141 echo $file
141142 return 0
142143}
143144
144145# Run the hooks
145146function virtualenvwrapper_run_hook {
146- typeset hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) "
147- if [ -z " $hook_script " ]
148- then
149- echo " ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
150- return 1
151- fi
147+ typeset hook_script
148+ typeset result
149+
150+ hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) " || return 1
151+
152152 if [ -z " $VIRTUALENVWRAPPER_LOG_DIR " ]
153153 then
154154 echo " ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
155+ \r m -f " $hook_script "
155156 return 1
156157 fi
157158 " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
@@ -162,12 +163,13 @@ function virtualenvwrapper_run_hook {
162163 if [ ! -f " $hook_script " ]
163164 then
164165 echo " ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script " 1>&2
166+ \r m -f " $hook_script "
165167 return 2
166168 fi
167169 # cat "$hook_script"
168170 source " $hook_script "
169171 fi
170- \r m -f " $hook_script " > /dev/null 2>&1
172+ \r m -f " $hook_script "
171173 return $result
172174}
173175
You can’t perform that action at this time.
0 commit comments