Skip to content

Commit

Permalink
test: expand is_os capabilites
Browse files Browse the repository at this point in the history
Use is_os over multiple helper functions such as iswin() and uname()
to gather all platform detection functionality in a simple, single
function.
  • Loading branch information
dundargoc committed Nov 11, 2022
1 parent 69507c0 commit ebacb16
Show file tree
Hide file tree
Showing 56 changed files with 253 additions and 250 deletions.
4 changes: 2 additions & 2 deletions test/functional/api/proc_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local funcs = helpers.funcs
local iswin = helpers.iswin
local neq = helpers.neq
local nvim_argv = helpers.nvim_argv
local request = helpers.request
local retry = helpers.retry
local NIL = helpers.NIL
local is_os = helpers.is_os

describe('API', function()
before_each(clear)
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('API', function()
it('returns process info', function()
local pid = funcs.getpid()
local pinfo = request('nvim_get_proc', pid)
eq((iswin() and 'nvim.exe' or 'nvim'), pinfo.name)
eq((is_os('win') and 'nvim.exe' or 'nvim'), pinfo.name)
eq(pid, pinfo.pid)
eq('number', type(pinfo.ppid))
neq(pid, pinfo.ppid)
Expand Down
9 changes: 4 additions & 5 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ local exec = helpers.exec
local eval = helpers.eval
local expect = helpers.expect
local funcs = helpers.funcs
local iswin = helpers.iswin
local meths = helpers.meths
local matches = helpers.matches
local pesc = helpers.pesc
Expand Down Expand Up @@ -399,7 +398,7 @@ describe('API', function()
end)

it('returns shell |:!| output', function()
local win_lf = iswin() and '\r' or ''
local win_lf = is_os('win') and '\r' or ''
eq(':!echo foo\r\n\nfoo'..win_lf..'\n', nvim('command_output', [[!echo foo]]))
end)

Expand Down Expand Up @@ -2124,7 +2123,7 @@ describe('API', function()
pty='?',
}
local event = meths.get_var("opened_event")
if not iswin() then
if not is_os('win') then
info.pty = event.info.pty
neq(nil, string.match(info.pty, "^/dev/"))
end
Expand All @@ -2140,7 +2139,7 @@ describe('API', function()
stream = 'job',
id = 4,
argv = (
iswin() and {
is_os('win') and {
eval('&shell'),
'/s',
'/c',
Expand All @@ -2162,7 +2161,7 @@ describe('API', function()
-- :terminal with args + stopped process.
eq(1, eval('jobstop(&channel)'))
eval('jobwait([&channel], 1000)') -- Wait.
expected2.pty = (iswin() and '?' or '') -- pty stream was closed.
expected2.pty = (is_os('win') and '?' or '') -- pty stream was closed.
eq(expected2, eval('nvim_get_chan_info(&channel)'))
end)
end)
Expand Down
28 changes: 14 additions & 14 deletions test/functional/autocmd/dirchanged_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local lfs = require('lfs')
local h = require('test.functional.helpers')(after_each)
local helpers = require('test.functional.helpers')(after_each)

local clear = h.clear
local command = h.command
local eq = h.eq
local eval = h.eval
local request = h.request
local iswin = h.iswin
local clear = helpers.clear
local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local request = helpers.request
local is_os = helpers.is_os

describe('autocmd DirChanged and DirChangedPre', function()
local curdir = string.gsub(lfs.currentdir(), '\\', '/')
Expand All @@ -21,8 +21,8 @@ describe('autocmd DirChanged and DirChangedPre', function()
curdir .. '\\XTEST-FUNCTIONAL-AUTOCMD-DIRCHANGED.DIR3',
}

setup(function() for _, dir in pairs(dirs) do h.mkdir(dir) end end)
teardown(function() for _, dir in pairs(dirs) do h.rmdir(dir) end end)
setup(function() for _, dir in pairs(dirs) do helpers.mkdir(dir) end end)
teardown(function() for _, dir in pairs(dirs) do helpers.rmdir(dir) end end)

before_each(function()
clear()
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('autocmd DirChanged and DirChangedPre', function()
eq(1, eval('g:cdprecount'))
eq(1, eval('g:cdcount'))

if iswin() then
if is_os('win') then
command('lcd '..win_dirs[1])
eq({}, eval('g:evpre'))
eq({}, eval('g:ev'))
Expand All @@ -182,7 +182,7 @@ describe('autocmd DirChanged and DirChangedPre', function()
eq(2, eval('g:cdprecount'))
eq(2, eval('g:cdcount'))

if iswin() then
if is_os('win') then
command('tcd '..win_dirs[2])
eq({}, eval('g:evpre'))
eq({}, eval('g:ev'))
Expand All @@ -204,7 +204,7 @@ describe('autocmd DirChanged and DirChangedPre', function()
eq(3, eval('g:cdprecount'))
eq(3, eval('g:cdcount'))

if iswin() then
if is_os('win') then
command('cd '..win_dirs[3])
eq({}, eval('g:evpre'))
eq({}, eval('g:ev'))
Expand All @@ -229,7 +229,7 @@ describe('autocmd DirChanged and DirChangedPre', function()
eq(4, eval('g:cdprecount'))
eq(4, eval('g:cdcount'))

if iswin() then
if is_os('win') then
command('split '..win_dirs[1]..'/baz')
eq({}, eval('g:evpre'))
eq({}, eval('g:ev'))
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('autocmd DirChanged and DirChangedPre', function()
eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event

if iswin() then
if is_os('win') then
command('tabnew') -- tab 3
eq(9, eval('g:cdprecount')) -- same CWD, no DirChangedPre event
eq(9, eval('g:cdcount')) -- same CWD, no DirChanged event
Expand Down
8 changes: 4 additions & 4 deletions test/functional/autocmd/termxx_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local ok = helpers.ok
local feed = helpers.feed
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
local iswin = helpers.iswin
local is_os = helpers.is_os

describe('autocmd TermClose', function()
before_each(function()
Expand Down Expand Up @@ -47,15 +47,15 @@ describe('autocmd TermClose', function()
end)

it('triggers when long-running terminal job gets stopped', function()
nvim('set_option', 'shell', iswin() and 'cmd.exe' or 'sh')
nvim('set_option', 'shell', is_os('win') and 'cmd.exe' or 'sh')
command('autocmd TermClose * let g:test_termclose = 23')
command('terminal')
command('call jobstop(b:terminal_job_id)')
retry(nil, nil, function() eq(23, eval('g:test_termclose')) end)
end)

it('kills job trapping SIGTERM', function()
if iswin() then return end
if is_os('win') then return end
nvim('set_option', 'shell', 'sh')
nvim('set_option', 'shellcmdflag', '-c')
command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
Expand All @@ -75,7 +75,7 @@ describe('autocmd TermClose', function()
end)

it('kills PTY job trapping SIGHUP and SIGTERM', function()
if iswin() then return end
if is_os('win') then return end
nvim('set_option', 'shell', 'sh')
nvim('set_option', 'shellcmdflag', '-c')
command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
Expand Down
4 changes: 1 addition & 3 deletions test/functional/core/channels_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local helpers = require('test.functional.helpers')(after_each)
local uname = helpers.uname
local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq,
helpers.eval, helpers.next_msg, helpers.ok, helpers.source
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
Expand Down Expand Up @@ -178,8 +177,7 @@ describe('channels', function()

command("call chansend(id, 'incomplet\004')")

local is_bsd = not not string.find(uname(), 'bsd')
local bsdlike = is_bsd or is_os('mac')
local bsdlike = is_os('bsd') or is_os('mac')
local extra = bsdlike and "^D\008\008" or ""
expect_twoline(id, "stdout",
"incomplet"..extra, "[1, ['incomplet'], 'stdin']", true)
Expand Down
6 changes: 3 additions & 3 deletions test/functional/core/fileio_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ local read_file = helpers.read_file
local tmpname = helpers.tmpname
local trim = helpers.trim
local currentdir = helpers.funcs.getcwd
local iswin = helpers.iswin
local assert_alive = helpers.assert_alive
local expect_exit = helpers.expect_exit
local write_file = helpers.write_file
local Screen = require('test.functional.ui.screen')
local feed_command = helpers.feed_command
local isCI = helpers.isCI
local is_os = helpers.is_os

describe('fileio', function()
before_each(function()
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('fileio', function()

-- Backup filename = fullpath, separators replaced with "%".
local backup_file_name = string.gsub(currentdir()..'/Xtest_startup_file1',
iswin() and '[:/\\]' or '/', '%%') .. '~'
is_os('win') and '[:/\\]' or '/', '%%') .. '~'
local foo_contents = trim(read_file('Xtest_backupdir/'..backup_file_name))
local foobar_contents = trim(read_file('Xtest_startup_file1'))

Expand Down Expand Up @@ -306,7 +306,7 @@ describe('tmpdir', function()
end)

-- "…/nvim.<user>/" has wrong permissions:
if iswin() then
if is_os('win') then
return -- TODO(justinmk): need setfperm/getfperm on Windows. #8244
end
os.remove(testlog)
Expand Down
Loading

0 comments on commit ebacb16

Please sign in to comment.