vim-patch:8.0.1017: test for MS-Windows $HOME always passes

Problem:    Test for MS-Windows $HOME always passes.
Solution:   Rename the test function.  Make the test pass.
dde6034111

Assume $HOME contains the literal absolute path.
Nested environment variable expansion is unsupported.
This commit is contained in:
Jan Edmund Lazo 2018-06-06 00:10:17 -04:00
parent 5ed0975ea2
commit 30bba7a10c

View File

@ -38,76 +38,73 @@ func CheckHomeIsInSubprocessEnvironment(exp)
endfunc endfunc
func CheckHome(exp, ...) func CheckHome(exp, ...)
"call assert_equal(a:exp, $HOME) call assert_equal(a:exp, $HOME)
"call assert_equal(a:exp, expand('~', ':p')) call assert_equal(a:exp, expand('~', ':p'))
if !a:0 if !a:0
call CheckHomeIsMissingFromSubprocessEnvironment() call CheckHomeIsMissingFromSubprocessEnvironment()
else else
call CheckHomeIsInSubprocessEnvironment(a:exp) call CheckHomeIsInSubprocessEnvironment(a:1)
endif endif
endfunc endfunc
func TestWindowsHome() func Test_WindowsHome()
command! -nargs=* SaveEnv call <SID>save_env(<f-args>) command! -nargs=* SaveEnv call <SID>save_env(<f-args>)
command! -nargs=* RestoreEnv call <SID>restore_env() command! -nargs=* RestoreEnv call <SID>restore_env()
command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>) command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>)
set noshellslash
SaveEnv $HOME $USERPROFILE $HOMEDRIVE $HOMEPATH let save_home = $HOME
SaveEnv $USERPROFILE $HOMEDRIVE $HOMEPATH
try try
RestoreEnv " Normal behavior: use $HOMEDRIVE and $HOMEPATH, ignore $USERPROFILE
UnletEnv $HOME $USERPROFILE $HOMEPATH let $USERPROFILE = 'unused'
let $HOMEDRIVE = 'C:'
call CheckHome('C:\')
RestoreEnv
UnletEnv $HOME $USERPROFILE
let $HOMEDRIVE = 'C:' let $HOMEDRIVE = 'C:'
let $HOMEPATH = '\foobar' let $HOMEPATH = '\foobar'
let $HOME = '' " Force recomputing "homedir"
call CheckHome('C:\foobar') call CheckHome('C:\foobar')
RestoreEnv " Same, but with $HOMEPATH not set
UnletEnv $HOME $HOMEDRIVE $HOMEPATH UnletEnv $HOMEPATH
let $HOME = '' " Force recomputing "homedir"
call CheckHome('C:\')
" Use $USERPROFILE if $HOMEPATH and $HOMEDRIVE are empty
UnletEnv $HOMEDRIVE $HOMEPATH
let $USERPROFILE = 'C:\foo' let $USERPROFILE = 'C:\foo'
let $HOME = '' " Force recomputing "homedir"
call CheckHome('C:\foo') call CheckHome('C:\foo')
RestoreEnv " If $HOME is set the others don't matter
UnletEnv $HOME
let $USERPROFILE = 'C:\foo'
let $HOMEDRIVE = 'C:'
let $HOMEPATH = '\baz'
call CheckHome('C:\foo')
RestoreEnv
let $HOME = 'C:\bar' let $HOME = 'C:\bar'
let $USERPROFILE = 'C:\foo' let $USERPROFILE = 'unused'
let $HOMEDRIVE = 'C:' let $HOMEDRIVE = 'unused'
let $HOMEPATH = '\baz' let $HOMEPATH = 'unused'
call CheckHome('C:\bar', 1) call CheckHome('C:\bar', 'C:\bar')
RestoreEnv " If $HOME contains %USERPROFILE% it is expanded
let $USERPROFILE = 'C:\foo'
let $HOME = '%USERPROFILE%\bar' let $HOME = '%USERPROFILE%\bar'
let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'unused'
let $HOMEDRIVE = 'C:' let $HOMEPATH = 'unused'
let $HOMEPATH = '\baz' " call CheckHome('C:\foo\bar', '%USERPROFILE%\bar')
call CheckHome('%USERPROFILE%\bar', 1)
RestoreEnv " Invalid $HOME is kept
let $USERPROFILE = 'C:\foo'
let $HOME = '%USERPROFILE' let $HOME = '%USERPROFILE'
let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'unused'
let $HOMEDRIVE = 'C:' let $HOMEPATH = 'unused'
let $HOMEPATH = '\baz' call CheckHome('%USERPROFILE', '%USERPROFILE')
call CheckHome('%USERPROFILE', 1)
RestoreEnv " %USERPROFILE% not at start of $HOME is not expanded
let $USERPROFILE = 'unused'
let $HOME = 'C:\%USERPROFILE%' let $HOME = 'C:\%USERPROFILE%'
let $USERPROFILE = 'C:\foo' let $HOMEDRIVE = 'unused'
let $HOMEDRIVE = 'C:' let $HOMEPATH = 'unused'
let $HOMEPATH = '\baz' call CheckHome('C:\%USERPROFILE%', 'C:\%USERPROFILE%')
call CheckHome('C:\%USERPROFILE%', 1)
if has('channel') if has('channel')
RestoreEnv RestoreEnv
UnletEnv $HOME let $HOME = save_home
let env = '' let env = ''
let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}}) let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}})
sleep 1 sleep 1