refactor(tests): introduce testprg()

Also:
- Add a describe('shell :!') section to system_spec.
- Make the test for #16271 work on systems without powershell.
This commit is contained in:
Justin M. Keyes
2022-06-22 05:51:52 -07:00
parent 0b9664f524
commit f977f9445f
22 changed files with 117 additions and 105 deletions

View File

@@ -515,9 +515,17 @@ function module.has_powershell()
return module.eval('executable("'..(iswin() and 'powershell' or 'pwsh')..'")') == 1
end
function module.set_shell_powershell()
local shell = iswin() and 'powershell' or 'pwsh'
assert(module.has_powershell())
--- Sets Nvim shell to powershell.
---
--- @param fake (boolean) If true, a fake will be used if powershell is not
--- found on the system.
--- @returns true if powershell was found on the system, else false.
function module.set_shell_powershell(fake)
local found = module.has_powershell()
if not fake then
assert(found)
end
local shell = found and (iswin() and 'powershell' or 'pwsh') or module.testprg('pwsh-test')
local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin()
and {'alias:cat', 'alias:echo', 'alias:sleep'}
@@ -529,6 +537,7 @@ function module.set_shell_powershell()
let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait'
]])
return found
end
function module.nvim(method, ...)
@@ -784,11 +793,21 @@ function module.get_pathsep()
return iswin() and '\\' or '/'
end
--- Gets the filesystem root dir, namely "/" or "C:/".
function module.pathroot()
local pathsep = package.config:sub(1,1)
return iswin() and (module.nvim_dir:sub(1,2)..pathsep) or '/'
end
--- Gets the full `…/build/bin/{name}` path of a test program produced by
--- `test/functional/fixtures/CMakeLists.txt`.
---
--- @param name (string) Name of the test program.
function module.testprg(name)
local ext = module.iswin() and '.exe' or ''
return ('%s/%s%s'):format(module.nvim_dir, name, ext)
end
-- Returns a valid, platform-independent Nvim listen address.
-- Useful for communicating with child instances.
function module.new_pipename()