Skip to content

Commit 9f30ada

Browse files
hjkatzjasonamyers
authored andcommitted
Merged in hjkatz/virtualenvwrapper/fix/workon_deactivate_and_tests (pull request #70)
Fix bug with workon deactivate typeset -f ; Add test_workon_deactivate_hooks Approved-by: Harrison Katz <[email protected]> Approved-by: Jason Myers <[email protected]>
2 parents 36b8050 + 2b96467 commit 9f30ada

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

tests/test_workon.sh

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setUp () {
2525
}
2626

2727
tearDown () {
28-
deactivate >/dev/null 2>&1
28+
deactivate >/dev/null 2>&1
2929
}
3030

3131
test_workon () {
@@ -50,22 +50,55 @@ test_workon_activate_hooks () {
5050
touch "$TMPDIR/catch_output"
5151

5252
workon test1
53-
53+
5454
output=$(cat "$TMPDIR/catch_output")
5555
expected="GLOBAL preactivate
5656
ENV preactivate
5757
GLOBAL postactivate
5858
ENV postactivate"
5959

6060
assertSame "$expected" "$output"
61-
61+
6262
for t in pre post
6363
do
6464
rm -f "$WORKON_HOME/test1/bin/${t}activate"
6565
rm -f "$WORKON_HOME/${t}activate"
6666
done
6767
}
6868

69+
test_workon_deactivate_hooks () {
70+
for t in pre post
71+
do
72+
echo "#!/bin/sh" > "$WORKON_HOME/${t}deactivate"
73+
echo "echo GLOBAL ${t}deactivate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/${t}deactivate"
74+
chmod +x "$WORKON_HOME/${t}deactivate"
75+
76+
echo "#!/bin/sh" > "$WORKON_HOME/test2/bin/${t}deactivate"
77+
echo "echo ENV ${t}deactivate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/test1/bin/${t}deactivate"
78+
chmod +x "$WORKON_HOME/test1/bin/${t}deactivate"
79+
done
80+
81+
rm -f "$TMPDIR/catch_output"
82+
touch "$TMPDIR/catch_output"
83+
84+
workon test1
85+
workon test2
86+
87+
output=$(cat "$TMPDIR/catch_output")
88+
expected="ENV predeactivate
89+
GLOBAL predeactivate
90+
ENV postdeactivate
91+
GLOBAL postdeactivate"
92+
93+
assertSame "$expected" "$output"
94+
95+
for t in pre post
96+
do
97+
rm -f "$WORKON_HOME/test1/bin/${t}deactivate"
98+
rm -f "$WORKON_HOME/${t}deactivate"
99+
done
100+
}
101+
69102
test_virtualenvwrapper_show_workon_options () {
70103
mkdir "$WORKON_HOME/not_env"
71104
(cd "$WORKON_HOME"; ln -s test1 link_env)

virtualenvwrapper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ function workon {
755755
type deactivate >/dev/null 2>&1
756756
if [ $? -eq 0 ]
757757
then
758-
type deactivate | grep 'typeset env_postdeactivate_hook' >/dev/null 2>&1
758+
typeset -f deactivate | grep 'typeset env_postdeactivate_hook' >/dev/null 2>&1
759759
if [ $? -eq 0 ]
760760
then
761761
deactivate

0 commit comments

Comments
 (0)