summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-16 08:45:55 +0100
committerw0rp <devw0rp@gmail.com>2018-07-16 08:50:34 +0100
commit465db4daa1f3f964d0b0c4146c5c15318b15603e (patch)
tree9e6c6dca914367f7ce8a9e958bda4c0fb34abbe0
parentfb8c09097123f37da69f7e7cd0c814c78547e16e (diff)
downloadale-465db4daa1f3f964d0b0c4146c5c15318b15603e.zip
Only temporarily replace TMPDIR if it's defined to be an empty string
-rw-r--r--autoload/ale/util.vim3
-rw-r--r--test/test_tmpdir_wrapper.vader27
2 files changed, 24 insertions, 6 deletions
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index eb2877b2..fb6dc085 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -280,7 +280,7 @@ endfunction
function! ale#util#Tempname() abort
let l:clear_tempdir = 0
- if has('unix') && empty($TMPDIR)
+ if exists('$TMPDIR') && empty($TMPDIR)
let l:clear_tempdir = 1
let $TMPDIR = '/tmp'
endif
@@ -290,7 +290,6 @@ function! ale#util#Tempname() abort
finally
if l:clear_tempdir
let $TMPDIR = ''
- silent! unlet! $TMPDIR
endif
endtry
diff --git a/test/test_tmpdir_wrapper.vader b/test/test_tmpdir_wrapper.vader
index 4d87061f..151b8943 100644
--- a/test/test_tmpdir_wrapper.vader
+++ b/test/test_tmpdir_wrapper.vader
@@ -1,13 +1,32 @@
Before:
- Save $TMPDIR
+ let g:exists = exists('$TMPDIR')
+ let g:old_value = $TMPDIR
After:
- Restore
+ if g:exists
+ let $TMPDIR = g:old_value
+ else
+ silent! unlet! $TMPDIR
+ endif
+
+ 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 should create files in /tmp if $TMPDIR isn't set):
+Execute(ale#util#Tempname shouldn't replace $TMPDIR and reset them to an empty string.):
if has('unix')
let $TMPDIR = ''
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
endif