Files
neovim/test/functional/options/shell_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

80 lines
2.0 KiB
Lua

local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it = t.describe, t.it
local eq = t.eq
local is_os = t.is_os
local skip = t.skip
local api = n.api
local clear = n.clear
describe("'shell…' option defaults based on $SHELL #28384", function()
---@param sh string
---@param shcf string
---@param sp string
---@param srr string
---@param sxq string
---@param ssl boolean
local function expect(sh, shcf, sp, srr, sxq, ssl)
local opt = { sh = sh, shcf = shcf, sp = sp, srr = srr, sxq = sxq, ssl = ssl }
for k, v in pairs(opt) do
eq(v, api.nvim_get_option_info2(k, {}).default)
end
end
it('cmd.exe', function()
skip(not is_os('win'), 'N/A: only works on Windows')
clear()
expect('cmd.exe', '/s /c', '2>&1| tee', '>%s 2>&1', '"', false)
end)
it('powershell(PowerShell 5.x)', function()
t.skip(not is_os('win'), 'N/A: only works on Windows')
clear {
env = { SHELL = 'powershell' },
}
expect('powershell', '-Command', '2>&1| tee', '>%s 2>&1', '', true)
end)
it('pwsh(PowerShell 7.x)', function()
clear {
env = { SHELL = 'pwsh' },
}
expect('pwsh', '-c', '2>&1| tee', '>%s 2>&1', '', true)
end)
it('csh', function()
clear {
env = { SHELL = 'csh' },
}
expect('csh', '-c', '|& tee', '>&', '', true)
end)
it('bash', function()
clear {
env = { SHELL = 'bash' },
}
expect('bash', '-c', '2>&1| tee', '>%s 2>&1', '', true)
end)
it('unknown', function()
clear {
env = { SHELL = 'unknown' },
}
expect(
'unknown',
'-c',
not is_os('win') and '| tee' or '2>&1| tee',
not is_os('win') and '>' or '>%s 2>&1',
'',
not is_os('win') and true or false
)
end)
it('if the path contains spaces', function()
clear {
env = { SHELL = ('%s/foo bar/bash'):format(n.nvim_dir) },
}
expect(('"%s/foo bar/bash"'):format(n.nvim_dir), '-c', '2>&1| tee', '>%s 2>&1', '', true)
end)
end)