Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: simplify platform detection #21020

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions test/functional/api/server_notifications_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local eq, clear, eval, command, nvim, next_msg =
local meths = helpers.meths
local exec_lua = helpers.exec_lua
local retry = helpers.retry
local isCI = helpers.isCI
local is_ci = helpers.is_ci
local assert_alive = helpers.assert_alive
local skip = helpers.skip

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('notify', function()
end)

it('cancels stale events on channel close', function()
skip(isCI(), 'hangs on CI #14083 #15251')
skip(is_ci(), 'hangs on CI #14083 #15251')
local catchan = eval("jobstart(['cat'], {'rpc': v:true})")
local catpath = eval('exepath("cat")')
eq({id=catchan, argv={catpath}, stream='job', mode='rpc', client = {}}, exec_lua ([[
Expand Down
2 changes: 1 addition & 1 deletion test/functional/api/server_requests_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('server -> client', function()
pcall(funcs.jobstop, jobid)
end)

if helpers.skip(helpers.iswin()) then return end
if helpers.skip(helpers.is_os('win')) then return end

it('rpc and text stderr can be combined', function()
local status, rv = pcall(funcs.rpcrequest, jobid, 'poll')
Expand Down
11 changes: 5 additions & 6 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 @@ -400,7 +399,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 @@ -2125,7 +2124,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 @@ -2141,7 +2140,7 @@ describe('API', function()
stream = 'job',
id = 4,
argv = (
iswin() and {
is_os('win') and {
eval('&shell'),
'/s',
'/c',
Expand All @@ -2163,7 +2162,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 Expand Up @@ -2724,7 +2723,7 @@ describe('API', function()
eq({}, meths.get_runtime_file("foobarlang/", true))
end)
it('can handle bad patterns', function()
skip(iswin())
skip(is_os('win'))

eq("Vim:E220: Missing }.", pcall_err(meths.get_runtime_file, "{", false))

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
2 changes: 1 addition & 1 deletion test/functional/autocmd/focus_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local nvim_prog = helpers.nvim_prog
local feed_command = helpers.feed_command
local feed_data = thelpers.feed_data

if helpers.skip(helpers.iswin()) then return end
if helpers.skip(helpers.is_os('win')) then return end

describe('autoread TUI FocusGained/FocusLost', function()
local f1 = 'xtest-foo'
Expand Down
4 changes: 2 additions & 2 deletions test/functional/autocmd/signal_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ local command = helpers.command
local eq = helpers.eq
local funcs = helpers.funcs
local next_msg = helpers.next_msg
local iswin = helpers.iswin
local is_os = helpers.is_os
local skip = helpers.skip

if skip(iswin(), 'Only applies to POSIX systems') then return end
if skip(is_os('win'), 'Only applies to POSIX systems') then return end

local function posix_kill(signame, pid)
os.execute('kill -s '..signame..' -- '..pid..' >/dev/null')
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,8 +10,8 @@ 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 skip = helpers.skip
local is_os = helpers.is_os

describe('autocmd TermClose', function()
before_each(function()
Expand Down Expand Up @@ -48,15 +48,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()
skip(iswin())
skip(is_os('win'))
nvim('set_option', 'shell', 'sh')
nvim('set_option', 'shellcmdflag', '-c')
command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
Expand All @@ -76,7 +76,7 @@ describe('autocmd TermClose', function()
end)

it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(iswin())
skip(is_os('win'))
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
9 changes: 3 additions & 6 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 All @@ -12,7 +11,6 @@ local retry = helpers.retry
local expect_twostreams = helpers.expect_twostreams
local assert_alive = helpers.assert_alive
local pcall_err = helpers.pcall_err
local iswin = helpers.iswin
local skip = helpers.skip

describe('channels', function()
Expand Down Expand Up @@ -147,7 +145,7 @@ describe('channels', function()
end

it('can use stdio channel with pty', function()
skip(iswin())
skip(is_os('win'))
source([[
let g:job_opts = {
\ 'on_stdout': function('OnEvent'),
Expand Down Expand Up @@ -180,8 +178,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 All @@ -201,7 +198,7 @@ describe('channels', function()


it('stdio channel can use rpc and stderr simultaneously', function()
skip(iswin())
skip(is_os('win'))
source([[
let g:job_opts = {
\ 'on_stderr': function('OnEvent'),
Expand Down
16 changes: 8 additions & 8 deletions test/functional/core/fileio_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ 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 skip = helpers.skip
local is_os = helpers.is_os
local is_ci = helpers.is_ci

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

it('backup #9709', function()
skip(isCI('cirrus'))
skip(is_ci('cirrus'))
clear({ args={ '-i', 'Xtest_startup_shada',
'--cmd', 'set directory=Xtest_startup_swapdir' } })

Expand All @@ -110,7 +110,7 @@ describe('fileio', function()
end)

it('backup with full path #11214', function()
skip(isCI('cirrus'))
skip(is_ci('cirrus'))
clear()
mkdir('Xtest_backupdir')
command('set backup')
Expand All @@ -123,7 +123,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 All @@ -132,7 +132,7 @@ describe('fileio', function()
end)

it('backup symlinked files #11349', function()
skip(isCI('cirrus'))
skip(is_ci('cirrus'))
clear()

local initial_content = 'foo'
Expand All @@ -154,7 +154,7 @@ describe('fileio', function()


it('backup symlinked files in first avialable backupdir #11349', function()
skip(isCI('cirrus'))
skip(is_ci('cirrus'))
clear()

local initial_content = 'foo'
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('tmpdir', function()
end)

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