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 () {
24
24
test_tempfile () {
25
25
filename=$( virtualenvwrapper_tempfile hook)
26
26
assertTrue " Filename is empty" " [ ! -z \" $filename \" ]"
27
+ assertTrue " File doesn't exist" " [ -f \" $filename \" ]"
27
28
rm -f $filename
28
29
comparable_tmpdir=$( echo $tmplocation | sed ' s|/$||' )
29
30
comparable_dirname=$( dirname $filename | sed ' s|/$||' )
30
31
assertSame " Temporary directory \" $tmplocation \" and path not the same for $filename " " $comparable_tmpdir " " $comparable_dirname "
31
32
assertTrue " virtualenvwrapper-hook not in filename." " echo $filename | grep virtualenvwrapper-hook"
32
33
}
33
34
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
+
34
54
test_no_such_tmpdir () {
35
55
old_tmpdir=" $TMPDIR "
36
56
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 {
130
130
function virtualenvwrapper_tempfile {
131
131
# Note: the 'X's must come last
132
132
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 " ]
135
137
then
136
138
echo " ERROR: virtualenvwrapper could not create a temporary file name." 1>&2
137
139
return 1
138
140
fi
139
- trap " \rm -f '$file ' >/dev/null 2>&1" EXIT
140
141
echo $file
141
142
return 0
142
143
}
143
144
144
145
# Run the hooks
145
146
function 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
+
152
152
if [ -z " $VIRTUALENVWRAPPER_LOG_DIR " ]
153
153
then
154
154
echo " ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
155
+ \r m -f " $hook_script "
155
156
return 1
156
157
fi
157
158
" $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
@@ -162,12 +163,13 @@ function virtualenvwrapper_run_hook {
162
163
if [ ! -f " $hook_script " ]
163
164
then
164
165
echo " ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script " 1>&2
166
+ \r m -f " $hook_script "
165
167
return 2
166
168
fi
167
169
# cat "$hook_script"
168
170
source " $hook_script "
169
171
fi
170
- \r m -f " $hook_script " > /dev/null 2>&1
172
+ \r m -f " $hook_script "
171
173
return $result
172
174
}
173
175
You can’t perform that action at this time.
0 commit comments