8
8
" automated test suite of the miscellaneous Vim scripts. Right now the
9
9
" coverage is not very high yet, but this will improve over time.
10
10
11
+ let s: use_dll = 0
12
+ let s: can_use_dll = xolox#misc#os#can_use_dll ()
13
+
11
14
function ! xolox#misc#tests#run () " {{{1
12
15
" Run the automated test suite of the miscellaneous Vim scripts. To be used
13
16
" interactively. Intended to be safe to execute irrespective of context.
@@ -23,12 +26,27 @@ function! xolox#misc#tests#run() " {{{1
23
26
call xolox#misc#test#summarize ()
24
27
endfunction
25
28
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
+
26
44
" Tests for autoload/xolox/misc/escape.vim {{{1
27
45
28
46
function ! s: test_string_escaping ()
29
47
call xolox#misc#test#wrap (' xolox#misc#tests#pattern_escaping' )
30
48
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' )
32
50
endfunction
33
51
34
52
function ! xolox#misc#tests#pattern_escaping () " {{{2
@@ -47,9 +65,15 @@ endfunction
47
65
function ! xolox#misc#tests#shell_escaping () " {{{2
48
66
" Test escaping of shell arguments with `xolox#misc#escape#shell()`.
49
67
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' ])
51
70
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 ]))
53
77
endfunction
54
78
55
79
" Tests for autoload/xolox/misc/list.vim {{{1
@@ -136,10 +160,11 @@ endfunction
136
160
137
161
function ! s: test_command_execution ()
138
162
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' )
143
168
endfunction
144
169
145
170
function ! xolox#misc#tests#finding_vim_on_the_search_path () " {{{2
@@ -155,18 +180,30 @@ endfunction
155
180
function ! xolox#misc#tests#synchronous_command_execution () " {{{2
156
181
" Test basic functionality of synchronous command execution with
157
182
" `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 })
159
184
call xolox#misc#test#assert_same_type ({}, result)
160
185
call xolox#misc#test#assert_equals (0 , result[' exit_code' ])
161
186
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
163
200
endfunction
164
201
165
202
function ! xolox#misc#tests#synchronous_command_execution_with_raising_of_errors () " {{{2
166
203
" Test raising of errors during synchronous command execution with
167
204
" `xolox#misc#os#exec()`.
168
205
try
169
- call xolox#misc#os#exec ({' command' : ' exit 1' })
206
+ call xolox#misc#os#exec ({' command' : ' exit 1' , ' use_dll ' : s: use_dll })
170
207
call xolox#misc#test#assert_true (0 )
171
208
catch
172
209
call xolox#misc#test#assert_true (1 )
@@ -177,7 +214,7 @@ function! xolox#misc#tests#synchronous_command_execution_without_raising_errors(
177
214
" Test synchronous command execution without raising of errors with
178
215
" `xolox#misc#os#exec()`.
179
216
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 })
181
218
call xolox#misc#test#assert_true (1 )
182
219
call xolox#misc#test#assert_equals (42 , result[' exit_code' ])
183
220
catch
@@ -186,20 +223,23 @@ function! xolox#misc#tests#synchronous_command_execution_without_raising_errors(
186
223
endfunction
187
224
188
225
function ! 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 })
195
236
call xolox#misc#test#assert_same_type ({}, result)
196
237
" Make sure the command is really executed.
197
238
let timeout = localtime () + 30
198
- while ! filereadable (tempfile ) && localtime () < timeout
239
+ while ! isdirectory (expected_directory ) && localtime () < timeout
199
240
sleep 500 m
200
241
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))
203
243
endfunction
204
244
205
245
" Tests for autoload/xolox/misc/str.vim {{{1
0 commit comments