Mercurial > vim
view src/testdir/test_windows_home.vim @ 12265:03e4be2e3d53 v8.0.1012
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
commit https://github.com/vim/vim/commit/48340b62e812dc9280f621a2eb6db76d43555c66
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 29 22:08:53 2017 +0200
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Problem: MS-Windows: Problem with $HOME when is was set internally.
Solution: Only use the $HOME default internally. (Yasuhiro Matsumoto, closes
#2013)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 29 Aug 2017 22:15:05 +0200 |
parents | |
children | 67bc88591ede |
line wrap: on
line source
" Test for $HOME on Windows. if !has('win32') finish endif let s:env = {} func s:restore_env() for i in keys(s:env) exe 'let ' . i . '=s:env["' . i . '"]' endfor endfunc func s:save_env(...) for i in a:000 exe 'let s:env["' . i . '"]=' . i endfor endfunc func s:unlet_env(...) for i in a:000 exe 'let ' . i . '=""' endfor endfunc func CheckHomeIsMissingFromSubprocessEnvironment() silent! let out = system('set') let env = filter(split(out, "\n"), 'v:val=~"^HOME="') call assert_equal(0, len(env)) endfunc func CheckHomeIsInSubprocessEnvironment(exp) silent! let out = system('set') let env = filter(split(out, "\n"), 'v:val=~"^HOME="') let home = len(env) == 0 ? "" : substitute(env[0], '[^=]\+=', '', '') call assert_equal(a:exp, home) endfunc func CheckHome(exp, ...) "call assert_equal(a:exp, $HOME) "call assert_equal(a:exp, expand('~', ':p')) if !a:0 call CheckHomeIsMissingFromSubprocessEnvironment() else call CheckHomeIsInSubprocessEnvironment(a:exp) endif endfunc func TestWindowsHome() command! -nargs=* SaveEnv call <SID>save_env(<f-args>) command! -nargs=* RestoreEnv call <SID>restore_env() command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>) SaveEnv $HOME $USERPROFILE $HOMEDRIVE $HOMEPATH try RestoreEnv UnletEnv $HOME $USERPROFILE $HOMEPATH let $HOMEDRIVE = 'C:' call CheckHome('C:\') RestoreEnv UnletEnv $HOME $USERPROFILE let $HOMEDRIVE = 'C:' let $HOMEPATH = '\foobar' call CheckHome('C:\foobar') RestoreEnv UnletEnv $HOME $HOMEDRIVE $HOMEPATH let $USERPROFILE = 'C:\foo' call CheckHome('C:\foo') RestoreEnv UnletEnv $HOME let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'C:' let $HOMEPATH = '\baz' call CheckHome('C:\foo') RestoreEnv let $HOME = 'C:\bar' let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'C:' let $HOMEPATH = '\baz' call CheckHome('C:\bar', 1) RestoreEnv let $HOME = '%USERPROFILE%\bar' let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'C:' let $HOMEPATH = '\baz' call CheckHome('%USERPROFILE%\bar', 1) RestoreEnv let $HOME = '%USERPROFILE' let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'C:' let $HOMEPATH = '\baz' call CheckHome('%USERPROFILE', 1) RestoreEnv let $HOME = 'C:\%USERPROFILE%' let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'C:' let $HOMEPATH = '\baz' call CheckHome('C:\%USERPROFILE%', 1) if has('channel') RestoreEnv UnletEnv $HOME let env = '' let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}}) sleep 1 let env = filter(split(env, "\n"), 'v:val=="HOME"') let home = len(env) == 0 ? "" : env[0] call assert_equal('', home) endif finally RestoreEnv delcommand SaveEnv delcommand RestoreEnv delcommand UnletEnv endtry endfunc