Only temporarily replace TMPDIR if it's defined to be an empty string

This commit is contained in:
w0rp 2018-07-16 08:45:55 +01:00
parent 6e1a5d4189
commit fcd62342d5
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
2 changed files with 24 additions and 6 deletions

View file

@ -280,7 +280,7 @@ endfunction
function! ale#util#Tempname() abort function! ale#util#Tempname() abort
let l:clear_tempdir = 0 let l:clear_tempdir = 0
if has('unix') && empty($TMPDIR) if exists('$TMPDIR') && empty($TMPDIR)
let l:clear_tempdir = 1 let l:clear_tempdir = 1
let $TMPDIR = '/tmp' let $TMPDIR = '/tmp'
endif endif
@ -290,7 +290,6 @@ function! ale#util#Tempname() abort
finally finally
if l:clear_tempdir if l:clear_tempdir
let $TMPDIR = '' let $TMPDIR = ''
silent! unlet! $TMPDIR
endif endif
endtry endtry

View file

@ -1,13 +1,32 @@
Before: Before:
Save $TMPDIR let g:exists = exists('$TMPDIR')
let g:old_value = $TMPDIR
After: After:
Restore if g:exists
let $TMPDIR = g:old_value
else
silent! unlet! $TMPDIR
endif
Execute(ale#util#Tempname should create files in /tmp if $TMPDIR isn't set): unlet! g:exists
unlet! g:old_value
Execute(ale#util#Tempname shouldn't set $TMPDIR to an empty string if it isn't set):
" You can't run this test twice on old Vim versions.
if has('unix')
Assert ale#util#Tempname() =~# '^/tmp'
Assert !exists('$TMPDIR'), '$TMPDIR exists where it shouldn''t'
endif
Execute(ale#util#Tempname shouldn't replace $TMPDIR and reset them to an empty string.):
if has('unix') if has('unix')
let $TMPDIR = '' let $TMPDIR = ''
Assert ale#util#Tempname() =~# '^/tmp' Assert ale#util#Tempname() =~# '^/tmp'
" We should unlet the environment variable again.
if !has('nvim')
Assert exists('$TMPDIR'), '$TMPDIR doesn''t exist where it should'
endif
AssertEqual '', $TMPDIR AssertEqual '', $TMPDIR
endif endif