2019-07-30 02:55:55 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local clear = helpers.clear
|
|
|
|
local eq = helpers.eq
|
|
|
|
local environ = helpers.funcs.environ
|
2019-07-30 02:37:39 -07:00
|
|
|
local exists = helpers.funcs.exists
|
2021-01-10 17:46:25 -07:00
|
|
|
local system = helpers.funcs.system
|
|
|
|
local nvim_prog = helpers.nvim_prog
|
|
|
|
local command = helpers.command
|
|
|
|
local eval = helpers.eval
|
|
|
|
local setenv = helpers.funcs.setenv
|
2019-07-30 02:55:55 -07:00
|
|
|
|
2019-07-30 02:37:39 -07:00
|
|
|
describe('environment variables', function()
|
|
|
|
it('environ() handles empty env variable', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
clear({ env = { EMPTY_VAR = '' } })
|
|
|
|
eq('', environ()['EMPTY_VAR'])
|
2019-07-30 02:55:55 -07:00
|
|
|
eq(nil, environ()['DOES_NOT_EXIST'])
|
|
|
|
end)
|
2019-09-11 04:48:09 -07:00
|
|
|
|
2019-07-30 02:37:39 -07:00
|
|
|
it('exists() handles empty env variable', function()
|
2024-01-02 18:09:18 -07:00
|
|
|
clear({ env = { EMPTY_VAR = '' } })
|
2019-08-10 02:48:36 -07:00
|
|
|
eq(1, exists('$EMPTY_VAR'))
|
2019-07-30 02:37:39 -07:00
|
|
|
eq(0, exists('$DOES_NOT_EXIST'))
|
|
|
|
end)
|
2019-07-30 02:55:55 -07:00
|
|
|
end)
|
2021-01-10 17:46:25 -07:00
|
|
|
|
|
|
|
describe('empty $HOME', function()
|
|
|
|
local original_home = os.getenv('HOME')
|
|
|
|
|
2023-04-27 00:51:44 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2021-01-10 17:46:25 -07:00
|
|
|
-- recover $HOME after each test
|
|
|
|
after_each(function()
|
|
|
|
if original_home ~= nil then
|
|
|
|
setenv('HOME', original_home)
|
|
|
|
end
|
|
|
|
os.remove('test_empty_home')
|
|
|
|
os.remove('./~')
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function tilde_in_cwd()
|
|
|
|
-- get files in cwd
|
|
|
|
command("let test_empty_home_cwd_files = split(globpath('.', '*'), '\n')")
|
|
|
|
-- get the index of the file named '~'
|
|
|
|
command('let test_empty_home_tilde_index = index(test_empty_home_cwd_files, "./~")')
|
|
|
|
return eval('test_empty_home_tilde_index') ~= -1
|
|
|
|
end
|
|
|
|
|
|
|
|
local function write_and_test_tilde()
|
2024-01-02 18:09:18 -07:00
|
|
|
system({
|
|
|
|
nvim_prog,
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--headless',
|
|
|
|
'-c',
|
|
|
|
'write test_empty_home',
|
|
|
|
'+q',
|
|
|
|
})
|
2021-01-10 17:46:25 -07:00
|
|
|
eq(false, tilde_in_cwd())
|
|
|
|
end
|
|
|
|
|
|
|
|
it("'~' folder not created in cwd if $HOME and related env not defined", function()
|
2024-01-02 18:09:18 -07:00
|
|
|
command('unlet $HOME')
|
2021-01-10 17:46:25 -07:00
|
|
|
write_and_test_tilde()
|
|
|
|
|
|
|
|
command("let $HOMEDRIVE='C:'")
|
|
|
|
command("let $USERPROFILE='C:\\'")
|
|
|
|
write_and_test_tilde()
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
command('unlet $HOMEDRIVE')
|
2021-01-10 17:46:25 -07:00
|
|
|
write_and_test_tilde()
|
|
|
|
|
2024-01-02 18:09:18 -07:00
|
|
|
command('unlet $USERPROFILE')
|
2021-01-10 17:46:25 -07:00
|
|
|
write_and_test_tilde()
|
|
|
|
|
|
|
|
command("let $HOME='%USERPROFILE%'")
|
|
|
|
command("let $USERPROFILE='C:\\'")
|
|
|
|
write_and_test_tilde()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("'~' folder not created in cwd if writing a file with invalid $HOME", function()
|
|
|
|
setenv('HOME', '/path/does/not/exist')
|
|
|
|
write_and_test_tilde()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("'~' folder not created in cwd if writing a file with $HOME=''", function()
|
|
|
|
command("let $HOME=''")
|
|
|
|
write_and_test_tilde()
|
|
|
|
end)
|
|
|
|
end)
|