diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2022-06-22 05:51:52 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2022-06-25 08:27:17 -0700 |
commit | f977f9445f7689fc32a136108ff92b3c2137968c (patch) | |
tree | 34c4abe44693550d88221cbd140828d2657dcd7a /test/functional/helpers.lua | |
parent | 0b9664f5240be4d9e9d6882fcd398970fd3a9532 (diff) | |
download | rneovim-f977f9445f7689fc32a136108ff92b3c2137968c.tar.gz rneovim-f977f9445f7689fc32a136108ff92b3c2137968c.tar.bz2 rneovim-f977f9445f7689fc32a136108ff92b3c2137968c.zip |
refactor(tests): introduce testprg()
Also:
- Add a describe('shell :!') section to system_spec.
- Make the test for #16271 work on systems without powershell.
Diffstat (limited to 'test/functional/helpers.lua')
-rw-r--r-- | test/functional/helpers.lua | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 2018f80052..0c616e73fb 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -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() |