88" automated test suite of the miscellaneous Vim scripts. Right now the
99" coverage is not very high yet, but this will improve over time.
1010
11+ let s: use_dll = 0
12+ let s: can_use_dll = xolox#misc#os#can_use_dll ()
13+
1114function ! xolox#misc#tests#run () " {{{1
1215 " Run the automated test suite of the miscellaneous Vim scripts. To be used
1316 " interactively. Intended to be safe to execute irrespective of context.
@@ -23,12 +26,27 @@ function! xolox#misc#tests#run() " {{{1
2326 call xolox#misc#test#summarize ()
2427endfunction
2528
29+ function ! s: wrap_exec_test (function )
30+ " Wrapper for tests that use xolox#misc#os#exec(). If we're on Windows and
31+ " the vim-shell plug-in is installed, the test will be run twice: Once with
32+ " vim-shell disabled and once with vim-shell enabled. This makes sure that
33+ " all code paths are tested as much as possible.
34+ call xolox#misc#msg#debug (" vim-misc %s: Temporarily disabling vim-shell so we can test vim-misc .." , g: xolox #misc#version )
35+ let s: use_dll = 0
36+ call xolox#misc#test#wrap (a: function )
37+ if s: can_use_dll
38+ call xolox#misc#msg#debug (" vim-misc %s: Re-enabling vim-shell so we can test that as well .." , g: xolox #misc#version )
39+ let s: use_dll = 1
40+ call xolox#misc#test#wrap (a: function )
41+ endif
42+ endfunction
43+
2644" Tests for autoload/xolox/misc/escape.vim {{{1
2745
2846function ! s: test_string_escaping ()
2947 call xolox#misc#test#wrap (' xolox#misc#tests#pattern_escaping' )
3048 call xolox#misc#test#wrap (' xolox#misc#tests#substitute_escaping' )
31- call xolox#misc#test#wrap (' xolox#misc#tests#shell_escaping' )
49+ call s: wrap_exec_test (' xolox#misc#tests#shell_escaping' )
3250endfunction
3351
3452function ! xolox#misc#tests#pattern_escaping () " {{{2
@@ -47,9 +65,15 @@ endfunction
4765function ! xolox#misc#tests#shell_escaping () " {{{2
4866 " Test escaping of shell arguments with `xolox#misc#escape#shell()`.
4967 let expected_value = ' this < is > a | very " scary ^ string '' indeed'
50- let result = xolox#misc#os#exec ({' command' : g: xolox #misc#test#echo . ' ' . xolox#misc#escape#shell (expected_value)})
68+ let result = xolox#misc#os#exec ({' command' : g: xolox #misc#test#echo . ' ' . xolox#misc#escape#shell (expected_value), ' use_dll' : s: use_dll })
69+ call xolox#misc#test#assert_equals (0 , result[' exit_code' ])
5170 call xolox#misc#test#assert_equals (0 , result[' exit_code' ])
52- call xolox#misc#test#assert_equals ([expected_value], result[' stdout' ])
71+ call xolox#misc#test#assert_same_type ([], result[' stdout' ])
72+ call xolox#misc#test#assert_equals (1 , len (result[' stdout' ]))
73+ " XXX On Windows using system() there's a trailing space I can't explain.
74+ " However the point of this test was to show that all characters pass
75+ " through unharmed, so for now I'll just ignore the space :-)
76+ call xolox#misc#test#assert_equals (expected_value, xolox#misc#str#trim (result[' stdout' ][0 ]))
5377endfunction
5478
5579" Tests for autoload/xolox/misc/list.vim {{{1
@@ -136,10 +160,11 @@ endfunction
136160
137161function ! s: test_command_execution ()
138162 call xolox#misc#test#wrap (' xolox#misc#tests#finding_vim_on_the_search_path' )
139- call xolox#misc#test#wrap (' xolox#misc#tests#synchronous_command_execution' )
140- call xolox#misc#test#wrap (' xolox#misc#tests#synchronous_command_execution_with_raising_of_errors' )
141- call xolox#misc#test#wrap (' xolox#misc#tests#synchronous_command_execution_without_raising_errors' )
142- call xolox#misc#test#wrap (' xolox#misc#tests#asynchronous_command_execution' )
163+ call s: wrap_exec_test (' xolox#misc#tests#synchronous_command_execution' )
164+ call s: wrap_exec_test (' xolox#misc#tests#synchronous_command_execution_with_stderr' )
165+ call s: wrap_exec_test (' xolox#misc#tests#synchronous_command_execution_with_raising_of_errors' )
166+ call s: wrap_exec_test (' xolox#misc#tests#synchronous_command_execution_without_raising_errors' )
167+ call s: wrap_exec_test (' xolox#misc#tests#asynchronous_command_execution' )
143168endfunction
144169
145170function ! xolox#misc#tests#finding_vim_on_the_search_path () " {{{2
@@ -155,18 +180,30 @@ endfunction
155180function ! xolox#misc#tests#synchronous_command_execution () " {{{2
156181 " Test basic functionality of synchronous command execution with
157182 " `xolox#misc#os#exec()`.
158- let result = xolox#misc#os#exec ({' command' : printf (' %s output && %s errors >&2 ' , g: xolox #misc#test#echo , g: xolox #misc#test# echo ) })
183+ let result = xolox#misc#os#exec ({' command' : printf (' %s output' , g: xolox #misc#test#echo ), ' use_dll ' : s: use_dll })
159184 call xolox#misc#test#assert_same_type ({}, result)
160185 call xolox#misc#test#assert_equals (0 , result[' exit_code' ])
161186 call xolox#misc#test#assert_equals ([' output' ], result[' stdout' ])
162- call xolox#misc#test#assert_equals ([' errors' ], result[' stderr' ])
187+ endfunction
188+
189+ function ! xolox#misc#tests#synchronous_command_execution_with_stderr () " {{{2
190+ " Test basic functionality of synchronous command execution with
191+ " `xolox#misc#os#exec()` including the standard error stream (not available
192+ " on Windows when vim-shell is not installed).
193+ if ! (xolox#misc#os#is_win () && ! s: use_dll )
194+ let result = xolox#misc#os#exec ({' command' : printf (' %s output && %s errors >&2' , g: xolox #misc#test#echo , g: xolox #misc#test#echo ), ' use_dll' : s: use_dll })
195+ call xolox#misc#test#assert_same_type ({}, result)
196+ call xolox#misc#test#assert_equals (0 , result[' exit_code' ])
197+ call xolox#misc#test#assert_equals ([' output' ], result[' stdout' ])
198+ call xolox#misc#test#assert_equals ([' errors' ], result[' stderr' ])
199+ endif
163200endfunction
164201
165202function ! xolox#misc#tests#synchronous_command_execution_with_raising_of_errors () " {{{2
166203 " Test raising of errors during synchronous command execution with
167204 " `xolox#misc#os#exec()`.
168205 try
169- call xolox#misc#os#exec ({' command' : ' exit 1' })
206+ call xolox#misc#os#exec ({' command' : ' exit 1' , ' use_dll ' : s: use_dll })
170207 call xolox#misc#test#assert_true (0 )
171208 catch
172209 call xolox#misc#test#assert_true (1 )
@@ -177,7 +214,7 @@ function! xolox#misc#tests#synchronous_command_execution_without_raising_errors(
177214 " Test synchronous command execution without raising of errors with
178215 " `xolox#misc#os#exec()`.
179216 try
180- let result = xolox#misc#os#exec ({' command' : ' exit 42' , ' check' : 0 })
217+ let result = xolox#misc#os#exec ({' command' : ' exit 42' , ' check' : 0 , ' use_dll ' : s: use_dll })
181218 call xolox#misc#test#assert_true (1 )
182219 call xolox#misc#test#assert_equals (42 , result[' exit_code' ])
183220 catch
@@ -186,20 +223,23 @@ function! xolox#misc#tests#synchronous_command_execution_without_raising_errors(
186223endfunction
187224
188225function ! xolox#misc#tests#asynchronous_command_execution () " {{{2
189- " Test basic functionality of asynchronous command execution with
190- " `xolox#misc#os#exec()`.
191- let tempfile = tempname ()
192- let expected_value = string (localtime ())
193- let command = g: xolox #misc#test#echo . ' ' . xolox#misc#escape#shell (expected_value) . ' > ' . tempfile
194- let result = xolox#misc#os#exec ({' command' : command , ' async' : 1 })
226+ " Test the basic functionality of asynchronous command execution with
227+ " `xolox#misc#os#exec()`. This runs the external command `mkdir` and tests
228+ " that the side effect of creating the directory takes place. This might
229+ " seem like a peculiar choice, but it's one of the few 100% portable
230+ " commands (Windows + UNIX) that doesn't involve input/output streams.
231+ let temporary_directory = xolox#misc#path#tempdir ()
232+ let random_name = printf (' %i' , localtime ())
233+ let expected_directory = xolox#misc#path#merge (temporary_directory, random_name)
234+ let command = ' mkdir ' . xolox#misc#escape#shell (expected_directory)
235+ let result = xolox#misc#os#exec ({' command' : command , ' async' : 1 , ' use_dll' : s: use_dll })
195236 call xolox#misc#test#assert_same_type ({}, result)
196237 " Make sure the command is really executed.
197238 let timeout = localtime () + 30
198- while ! filereadable (tempfile ) && localtime () < timeout
239+ while ! isdirectory (expected_directory ) && localtime () < timeout
199240 sleep 500 m
200241 endwhile
201- call xolox#misc#test#assert_true (filereadable (tempfile))
202- call xolox#misc#test#assert_equals ([expected_value], readfile (tempfile))
242+ call xolox#misc#test#assert_true (isdirectory (expected_directory))
203243endfunction
204244
205245" Tests for autoload/xolox/misc/str.vim {{{1
0 commit comments