Skip to content

Commit d3137a2

Browse files
committed
Added tests for leading spaces (trailing spaces don't work in Linux, so don't test them).
1 parent 7958430 commit d3137a2

File tree

5 files changed

+49
-36
lines changed

5 files changed

+49
-36
lines changed

tests/test_allvirtualenv.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ oneTimeSetUp() {
1010
source "$test_dir/../virtualenvwrapper.sh"
1111
mkvirtualenv test1 >/dev/null 2>&1
1212
mkvirtualenv test2 >/dev/null 2>&1
13-
mkvirtualenv " env with space " >/dev/null 2>&1
13+
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
14+
# and work with virtualenv on OSX, but error out on Linux.
15+
mkvirtualenv " env with space" >/dev/null 2>&1
1416
deactivate
1517
}
1618

@@ -29,8 +31,7 @@ tearDown () {
2931
test_allvirtualenv_all() {
3032
assertTrue "Did not find test1" "allvirtualenv pwd | grep -q 'test1$'"
3133
assertTrue "Did not find test2" "allvirtualenv pwd | grep -q 'test2$'"
32-
allvirtualenv pwd
33-
assertTrue "Did not find ' env with space '" "allvirtualenv pwd | grep -q ' env with space '"
34+
assertTrue "Did not find ' env with space'" "allvirtualenv pwd | grep -q ' env with space'"
3435
}
3536

3637
test_allvirtualenv_spaces() {

tests/test_cd.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ oneTimeSetUp() {
99
unset VIRTUAL_ENV
1010
source "$test_dir/../virtualenvwrapper.sh"
1111
mkvirtualenv cd-test >/dev/null 2>&1
12-
mkvirtualenv "env with space" >/dev/null 2>&1
12+
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
13+
# and work with virtualenv on OSX, but error out on Linux.
14+
mkvirtualenv " env with space" >/dev/null 2>&1
1315
deactivate
1416
}
1517

@@ -40,7 +42,7 @@ test_cdvirtual() {
4042
}
4143

4244
test_cdvirtual_space_in_name() {
43-
workon "env with space"
45+
workon " env with space"
4446
start_dir="$(pwd)"
4547
cdvirtualenv
4648
assertSame "$VIRTUAL_ENV" "$(pwd)"
@@ -59,7 +61,7 @@ test_cdsitepackages () {
5961
}
6062

6163
test_cdsitepackages_space_in_name () {
62-
workon "env with space"
64+
workon " env with space"
6365
start_dir="$(pwd)"
6466
cdsitepackages
6567
pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)

tests/test_ls.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ test_lsvirtualenv_space_in_workon_home () {
7676
}
7777

7878
test_lsvirtualenv_space_in_env_name () {
79-
mkvirtualenv " env with space "
79+
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
80+
# and work with virtualenv on OSX, but error out on Linux.
81+
mkvirtualenv " env with space"
8082
lsvirtualenv -b >"$WORKON_HOME/output" 2>&1
81-
assertTrue "Did not see expected message in \"$output\"" "cat \"$WORKON_HOME/output\" | grep -q ' env with space '"
83+
assertTrue "Did not see expected message in \"$output\"" "cat \"$WORKON_HOME/output\" | grep -q ' env with space'"
8284
}
8385

8486

tests/test_mkvirtualenv.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ test_create() {
2929
}
3030

3131
test_create_space_in_name() {
32-
mkvirtualenv "env with space" >/dev/null 2>&1
33-
assertTrue "Environment directory was not created" "[ -d \"$WORKON_HOME/env with space\" ]"
32+
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
33+
# and work with virtualenv on OSX, but error out on Linux.
34+
mkvirtualenv " env with space" >/dev/null 2>&1
35+
assertTrue "Environment directory was not created" "[ -d \"$WORKON_HOME/ env with space\" ]"
3436
for hook in postactivate predeactivate postdeactivate
3537
do
36-
assertTrue "$hook was not created" "[ -f \"$WORKON_HOME/env with space/bin/$hook\" ]"
37-
assertFalse "$hook is executable" "[ -x \"$WORKON_HOME/env with space/bin/$hook\" ]"
38+
assertTrue "$hook was not created" "[ -f \"$WORKON_HOME/ env with space/bin/$hook\" ]"
39+
assertFalse "$hook is executable" "[ -x \"$WORKON_HOME/ env with space/bin/$hook\" ]"
3840
done
3941
assertTrue virtualenvwrapper_verify_active_environment
4042
env_name=$(basename "$VIRTUAL_ENV")
41-
assertSame "env with space" "$env_name"
43+
assertSame " env with space" "$env_name"
4244
}
4345

4446
test_activates () {

tests/test_workon.sh

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ oneTimeSetUp() {
77
rm -rf "$WORKON_HOME"
88
mkdir -p "$WORKON_HOME"
99
source "$test_dir/../virtualenvwrapper.sh"
10-
mkvirtualenv "env1" >/dev/null 2>&1
11-
mkvirtualenv "env2" >/dev/null 2>&1
12-
mkvirtualenv "env with space" >/dev/null 2>&1
13-
deactivate >/dev/null 2>&1
10+
mkvirtualenv "test1" >/dev/null 2>&1
11+
mkvirtualenv "test2" >/dev/null 2>&1
12+
# Only test with leading and internal spaces. Directory names with trailing spaces are legal,
13+
# and work with virtualenv on OSX, but error out on Linux.
14+
mkvirtualenv " env with space" >/dev/null 2>&1
15+
deactivate >/dev/null 2>&1
1416
}
1517

1618
oneTimeTearDown() {
@@ -27,9 +29,9 @@ tearDown () {
2729
}
2830

2931
test_workon () {
30-
workon env1
32+
workon test1
3133
assertTrue virtualenvwrapper_verify_active_environment
32-
assertSame "env1" $(basename "$VIRTUAL_ENV")
34+
assertSame "test1" $(basename "$VIRTUAL_ENV")
3335
}
3436

3537
test_workon_activate_hooks () {
@@ -39,15 +41,15 @@ test_workon_activate_hooks () {
3941
echo "echo GLOBAL ${t}activate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/${t}activate"
4042
chmod +x "$WORKON_HOME/${t}activate"
4143

42-
echo "#!/bin/sh" > "$WORKON_HOME/env2/bin/${t}activate"
43-
echo "echo ENV ${t}activate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/env1/bin/${t}activate"
44-
chmod +x "$WORKON_HOME/env1/bin/${t}activate"
44+
echo "#!/bin/sh" > "$WORKON_HOME/test2/bin/${t}activate"
45+
echo "echo ENV ${t}activate >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/test1/bin/${t}activate"
46+
chmod +x "$WORKON_HOME/test1/bin/${t}activate"
4547
done
4648

4749
rm -f "$TMPDIR/catch_output"
4850
touch "$TMPDIR/catch_output"
4951

50-
workon env1
52+
workon test1
5153

5254
output=$(cat "$TMPDIR/catch_output")
5355
expected="GLOBAL preactivate
@@ -59,27 +61,29 @@ ENV postactivate"
5961

6062
for t in pre post
6163
do
62-
rm -f "$WORKON_HOME/env1/bin/${t}activate"
64+
rm -f "$WORKON_HOME/test1/bin/${t}activate"
6365
rm -f "$WORKON_HOME/${t}activate"
6466
done
6567
}
6668

6769
test_virtualenvwrapper_show_workon_options () {
6870
mkdir "$WORKON_HOME/not_env"
69-
(cd "$WORKON_HOME"; ln -s env1 link_env)
71+
(cd "$WORKON_HOME"; ln -s test1 link_env)
7072
envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ')
71-
assertSame "env with space env1 env2 link_env " "$envs"
73+
# On OSX there are two trailing spaces, on Linux one, so compare substring
74+
assertSame " env with space link_env test1 test2 " "${envs:0:37}"
7275
rmdir "$WORKON_HOME/not_env"
7376
rm -f "$WORKON_HOME/link_env"
7477
}
7578

7679
test_virtualenvwrapper_show_workon_options_grep_options () {
7780
mkdir "$WORKON_HOME/not_env"
78-
(cd "$WORKON_HOME"; ln -s env1 link_env)
81+
(cd "$WORKON_HOME"; ln -s test1 link_env)
7982
export GREP_OPTIONS="--count"
8083
envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ')
8184
unset GREP_OPTIONS
82-
assertSame "env with space env1 env2 link_env " "$envs"
85+
# On OSX there are two trailing spaces, on Linux one, so compare substring
86+
assertSame " env with space link_env test1 test2 " "${envs:0:37}"
8387
rmdir "$WORKON_HOME/not_env"
8488
rm -f "$WORKON_HOME/link_env"
8589
}
@@ -95,15 +99,17 @@ test_virtualenvwrapper_show_workon_options_chpwd () {
9599
}
96100
mkdir "$WORKON_HOME/not_env"
97101
envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ')
98-
assertSame "env with space env1 env2 " "$envs"
102+
# On OSX there are two trailing spaces, on Linux one, so compare substring
103+
assertSame " env with space test1 test2 " "${envs:0:28}"
99104
rmdir "$WORKON_HOME/not_env"
100105
rm -f "$WORKON_HOME/link_env"
101106
}
102107

103108
test_virtualenvwrapper_show_workon_options_no_envs () {
104109
old_home="$WORKON_HOME"
105110
export WORKON_HOME=${TMPDIR:-/tmp}/$$
106-
envs=$(virtualenvwrapper_show_workon_options 2>/dev/null | tr '\n' ' ')
111+
envs=$(virtualenvwrapper_show_workon_options 2>/dev/null\
112+
| tr '\n' '' 2>/dev/null | tr ' ' '' 2>/dev/null)
107113
assertSame "" "$envs"
108114
export WORKON_HOME="$old_home"
109115
}
@@ -118,25 +124,25 @@ test_no_workon_home () {
118124
}
119125

120126
test_workon_dot () {
121-
cd $WORKON_HOME/env1
127+
cd $WORKON_HOME/test1
122128
workon .
123129
assertTrue virtualenvwrapper_verify_active_environment
124-
assertSame "env1" $(basename "$VIRTUAL_ENV")
130+
assertSame "test1" $(basename "$VIRTUAL_ENV")
125131
}
126132

127133
test_workon_dot_with_space () {
128-
cd $WORKON_HOME/"env with space"
134+
cd $WORKON_HOME/" env with space"
129135
workon .
130136
assertTrue virtualenvwrapper_verify_active_environment
131137
env_name=$(basename "$VIRTUAL_ENV")
132-
assertSame "env with space" "$env_name"
138+
assertSame " env with space" "$env_name"
133139
}
134140

135141
test_workon_with_space () {
136-
workon "env with space"
142+
workon " env with space"
137143
assertTrue virtualenvwrapper_verify_active_environment
138144
env_name=$(basename "$VIRTUAL_ENV")
139-
assertSame "env with space" "$env_name"
145+
assertSame " env with space" "$env_name"
140146
}
141147

142148
. "$test_dir/shunit2"

0 commit comments

Comments
 (0)