@@ -7,9 +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- 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
1316}
1417
1518oneTimeTearDown () {
@@ -26,9 +29,9 @@ tearDown () {
2629}
2730
2831test_workon () {
29- workon env1
32+ workon test1
3033 assertTrue virtualenvwrapper_verify_active_environment
31- assertSame " env1 " $( basename " $VIRTUAL_ENV " )
34+ assertSame " test1 " $( basename " $VIRTUAL_ENV " )
3235}
3336
3437test_workon_activate_hooks () {
@@ -38,15 +41,15 @@ test_workon_activate_hooks () {
3841 echo " echo GLOBAL ${t} activate >> \" $TMPDIR /catch_output\" " >> " $WORKON_HOME /${t} activate"
3942 chmod +x " $WORKON_HOME /${t} activate"
4043
41- echo " #!/bin/sh" > " $WORKON_HOME /env2 /bin/${t} activate"
42- echo " echo ENV ${t} activate >> \" $TMPDIR /catch_output\" " >> " $WORKON_HOME /env1 /bin/${t} activate"
43- 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"
4447 done
4548
4649 rm -f " $TMPDIR /catch_output"
4750 touch " $TMPDIR /catch_output"
4851
49- workon env1
52+ workon test1
5053
5154 output=$( cat " $TMPDIR /catch_output" )
5255 expected=" GLOBAL preactivate
@@ -58,27 +61,29 @@ ENV postactivate"
5861
5962 for t in pre post
6063 do
61- rm -f " $WORKON_HOME /env1 /bin/${t} activate"
64+ rm -f " $WORKON_HOME /test1 /bin/${t} activate"
6265 rm -f " $WORKON_HOME /${t} activate"
6366 done
6467}
6568
6669test_virtualenvwrapper_show_workon_options () {
6770 mkdir " $WORKON_HOME /not_env"
68- (cd " $WORKON_HOME " ; ln -s env1 link_env)
71+ (cd " $WORKON_HOME " ; ln -s test1 link_env)
6972 envs=$( virtualenvwrapper_show_workon_options | tr ' \n' ' ' )
70- assertSame " 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} "
7175 rmdir " $WORKON_HOME /not_env"
7276 rm -f " $WORKON_HOME /link_env"
7377}
7478
7579test_virtualenvwrapper_show_workon_options_grep_options () {
7680 mkdir " $WORKON_HOME /not_env"
77- (cd " $WORKON_HOME " ; ln -s env1 link_env)
81+ (cd " $WORKON_HOME " ; ln -s test1 link_env)
7882 export GREP_OPTIONS=" --count"
7983 envs=$( virtualenvwrapper_show_workon_options | tr ' \n' ' ' )
8084 unset GREP_OPTIONS
81- assertSame " 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} "
8287 rmdir " $WORKON_HOME /not_env"
8388 rm -f " $WORKON_HOME /link_env"
8489}
@@ -94,15 +99,17 @@ test_virtualenvwrapper_show_workon_options_chpwd () {
9499 }
95100 mkdir " $WORKON_HOME /not_env"
96101 envs=$( virtualenvwrapper_show_workon_options | tr ' \n' ' ' )
97- assertSame " 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} "
98104 rmdir " $WORKON_HOME /not_env"
99105 rm -f " $WORKON_HOME /link_env"
100106}
101107
102108test_virtualenvwrapper_show_workon_options_no_envs () {
103109 old_home=" $WORKON_HOME "
104110 export WORKON_HOME=${TMPDIR:-/ tmp} /$$
105- envs=$( virtualenvwrapper_show_workon_options 2> /dev/null | tr ' \n' ' ' )
111+ # On OSX there is a space and on Linux there is not, so strip all spaces
112+ envs=$( virtualenvwrapper_show_workon_options 2> /dev/null | sed ' s/\n //g' )
106113 assertSame " " " $envs "
107114 export WORKON_HOME=" $old_home "
108115}
@@ -117,10 +124,25 @@ test_no_workon_home () {
117124}
118125
119126test_workon_dot () {
120- cd $WORKON_HOME /env1
127+ cd $WORKON_HOME /test1
128+ workon .
129+ assertTrue virtualenvwrapper_verify_active_environment
130+ assertSame " test1" $( basename " $VIRTUAL_ENV " )
131+ }
132+
133+ test_workon_dot_with_space () {
134+ cd $WORKON_HOME /" env with space"
121135 workon .
122136 assertTrue virtualenvwrapper_verify_active_environment
123- assertSame " env1" $( basename " $VIRTUAL_ENV " )
137+ env_name=$( basename " $VIRTUAL_ENV " )
138+ assertSame " env with space" " $env_name "
139+ }
140+
141+ test_workon_with_space () {
142+ workon " env with space"
143+ assertTrue virtualenvwrapper_verify_active_environment
144+ env_name=$( basename " $VIRTUAL_ENV " )
145+ assertSame " env with space" " $env_name "
124146}
125147
126148. " $test_dir /shunit2"
0 commit comments