diff --git a/test/old/testdir/test_cd.vim b/test/old/testdir/test_cd.vim index 5d6d4018c4..1b0ef9ef81 100644 --- a/test/old/testdir/test_cd.vim +++ b/test/old/testdir/test_cd.vim @@ -227,15 +227,42 @@ func Test_cd_completion() if has('win32') " Test Windows absolute path completion + let saved_cwd = getcwd() + " Retrieve a suitable dir in the current drive - let dir = readdir('/', 'isdirectory("/" .. v:val) && len(v:val) > 2')[-1] + for d in readdir('/', 'isdirectory("/" .. v:val) && len(v:val) > 2') + " Paths containing '$' such as "$RECYCLE.BIN" are skipped because + " they are considered environment variables and completion does not + " work. + if d =~ '\V$' + continue + endif + " Skip directories that we don't have permission to "cd" into by + " actually "cd"ing into them and making sure they don't fail. + " Directory "System Volume Information" is an example of this. + try + call chdir('/' .. d) + let dir = d + " Yay! We found a suitable dir! + break + catch /:E472:/ + " Just skip directories where "cd" fails + continue + finally + call chdir(saved_cwd) + endtry + endfor + if !exists('dir') + throw 'Skipped: no testable directories found in the current drive root' + endif + " Get partial path let partial = dir[0:-2] - " Get the current drive letter - let old = chdir('/' . dir) + " Get the current drive letter and full path of the target dir + call chdir('/' .. dir) let full = getcwd() let drive = full[0] - call chdir(old) + call chdir(saved_cwd) for cmd in ['cd', 'chdir', 'lcd', 'lchdir', 'tcd', 'tchdir'] for sep in [ '/', '\']