diff src/testdir/test_environ.vim @ 28459:52ef65c0637f v8.2.4754

patch 8.2.4754: using cached values after unsetting some environment variables Commit: https://github.com/vim/vim/commit/7714231bb5b15f7c85453f3945c108478de1d08a Author: LemonBoy <thatlemon@gmail.com> Date: Fri Apr 15 20:50:46 2022 +0100 patch 8.2.4754: using cached values after unsetting some environment variables Problem: Still using cached values after unsetting some known environment variables. Solution: Take care of the side effects. (closes #10194)
author Bram Moolenaar <Bram@vim.org>
date Fri, 15 Apr 2022 22:00:03 +0200
parents 68115baaf9e4
children e3ab1d0f2ef9
line wrap: on
line diff
--- a/src/testdir/test_environ.vim
+++ b/src/testdir/test_environ.vim
@@ -28,6 +28,26 @@ func Test_setenv()
   call assert_equal(v:null, getenv('TEST ENV'))
 endfunc
 
+func Test_special_env()
+  " The value for $HOME is cached internally by Vim, ensure the value is up to
+  " date.
+  let orig_ENV = $HOME
+
+  let $HOME = 'foo'
+  call assert_equal('foo', expand('~'))
+  " old $HOME value is kept until a new one is set
+  unlet $HOME
+  call assert_equal('foo', expand('~'))
+
+  call setenv('HOME', 'bar')
+  call assert_equal('bar', expand('~'))
+  " old $HOME value is kept until a new one is set
+  call setenv('HOME', v:null)
+  call assert_equal('bar', expand('~'))
+
+  let $HOME = orig_ENV
+endfunc
+
 func Test_external_env()
   call setenv('FOO', 'HelloWorld')
   if has('win32')