Skip to content

Commit 6625ba3

Browse files
koronchrisbra
authored andcommitted
patch 9.1.2050: tests: Test_cd_completion may fail
Problem: tests: Test_cd_completion() may fail depending on the contents of the root directory of the current drive on Windows. readdir() may return a directory that cannot "cd" to, causing this test to fail. An example of such a directory is "System Volume Information" which only admin can "cd" to. Solution: When determining the directory to use for testing, use the directory that we actually "cd" to successfully. In addition, directories with '$' in their names are also excluded, as they are considered environment variables during completion and do not work as expected. Example: "$RECYCLE.BIN" (Muraoka Taro). closes: #19078 Signed-off-by: Muraoka Taro <koron.kaoriya@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4a9967b commit 6625ba3

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/testdir/test_cd.vim

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,42 @@ func Test_cd_completion()
224224

225225
if has('win32')
226226
" Test Windows absolute path completion
227+
let saved_cwd = getcwd()
228+
227229
" Retrieve a suitable dir in the current drive
228-
let dir = readdir('/', 'isdirectory("/" .. v:val) && len(v:val) > 2')[-1]
230+
for d in readdir('/', 'isdirectory("/" .. v:val) && len(v:val) > 2')
231+
" Paths containing '$' such as "$RECYCLE.BIN" are skipped because
232+
" they are considered environment variables and completion does not
233+
" work.
234+
if d =~ '\V$'
235+
continue
236+
endif
237+
" Skip directories that we don't have permission to "cd" into by
238+
" actually "cd"ing into them and making sure they don't fail.
239+
" Directory "System Volume Information" is an example of this.
240+
try
241+
call chdir('/' .. d)
242+
let dir = d
243+
" Yay! We found a suitable dir!
244+
break
245+
catch /:E472:/
246+
" Just skip directories where "cd" fails
247+
continue
248+
finally
249+
call chdir(saved_cwd)
250+
endtry
251+
endfor
252+
if !exists('dir')
253+
throw 'Skipped: no testable directories found in the current drive root'
254+
endif
255+
229256
" Get partial path
230257
let partial = dir[0:-2]
231-
" Get the current drive letter
232-
let old = chdir('/' . dir)
258+
" Get the current drive letter and full path of the target dir
259+
call chdir('/' .. dir)
233260
let full = getcwd()
234261
let drive = full[0]
235-
call chdir(old)
262+
call chdir(saved_cwd)
236263

237264
for cmd in ['cd', 'chdir', 'lcd', 'lchdir', 'tcd', 'tchdir']
238265
for sep in [ '/', '\']

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2050,
737739
/**/
738740
2049,
739741
/**/

0 commit comments

Comments
 (0)