@@ -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
1618oneTimeTearDown () {
@@ -27,9 +29,9 @@ tearDown () {
2729}
2830
2931test_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
3537test_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
6769test_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
7679test_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
103108test_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
120126test_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
127133test_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
135141test_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