Skip to content

Commit

Permalink
test: create is table to get information on current system
Browse files Browse the repository at this point in the history
There are currently many ancillary functions to detect information about
the test environments such as platform or whether it's being run on a CI
service.

Having a single `is` table with all necessary information on reduces
cognitive load, as one doesn't need to keep track of multiple functions
such as `iswin()`, `is_os('bsd')` and `isCI()` in order to get
information on current system. It also helps with discoverability as
language servers can easily find and complete static table values.
  • Loading branch information
dundargoc committed Nov 11, 2022
1 parent 0d7cc5e commit 2e9ff99
Show file tree
Hide file tree
Showing 59 changed files with 311 additions and 305 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 = helpers.is

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 = helpers.is
local assert_alive = helpers.assert_alive

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

it('cancels stale events on channel close', function()
if isCI() then
if is.ci.any then
pending('hangs on CI #14083 #15251')
return
elseif helpers.skip_fragile(pending) then
Expand Down
15 changes: 7 additions & 8 deletions test/functional/api/vim_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ 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
local mkdir_p = helpers.mkdir_p
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
local is_os = helpers.is_os
local is = helpers.is
local parse_context = helpers.parse_context
local request = helpers.request
local rmdir = helpers.rmdir
Expand Down Expand Up @@ -324,7 +323,7 @@ describe('API', function()
nvim('command', 'w')
local f = io.open(fname)
ok(f ~= nil)
if is_os('win') then
if is.os.win then
eq('testing\r\napi\r\n', f:read('*a'))
else
eq('testing\napi\n', f:read('*a'))
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 Expand Up @@ -2324,7 +2323,7 @@ describe('API', function()
end)

local it_maybe_pending = it
if helpers.isCI() and os.getenv('CONFIGURATION') == 'MSVC_32' then
if helpers.is.ci.any and os.getenv('CONFIGURATION') == 'MSVC_32' then
-- For "works with &opt" (flaky on MSVC_32), but not easy to skip alone. #10241
it_maybe_pending = pending
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 = helpers.is

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 = helpers.is

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
6 changes: 2 additions & 4 deletions test/functional/core/channels_spec.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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
local sleep = helpers.sleep
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
local set_session = helpers.set_session
local nvim_prog = helpers.nvim_prog
local is_os = helpers.is_os
local is = helpers.is
local retry = helpers.retry
local expect_twostreams = helpers.expect_twostreams
local assert_alive = helpers.assert_alive
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
15 changes: 7 additions & 8 deletions test/functional/core/fileio_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ 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 = helpers.is

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

it('backup #9709', function()
if isCI('cirrus') then
if is.ci.cirrus then
pending('FIXME: cirrus')
end
clear({ args={ '-i', 'Xtest_startup_shada',
Expand All @@ -111,7 +110,7 @@ describe('fileio', function()
end)

it('backup with full path #11214', function()
if isCI('cirrus') then
if is.ci.cirrus then
pending('FIXME: cirrus')
end
clear()
Expand All @@ -126,7 +125,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 @@ -135,7 +134,7 @@ describe('fileio', function()
end)

it('backup symlinked files #11349', function()
if isCI('cirrus') then
if is.ci.cirrus then
pending('FIXME: cirrus')
end
clear()
Expand All @@ -159,7 +158,7 @@ describe('fileio', function()


it('backup symlinked files in first avialable backupdir #11349', function()
if isCI('cirrus') then
if is.ci.cirrus then
pending('FIXME: cirrus')
end
clear()
Expand Down Expand Up @@ -306,7 +305,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 2e9ff99

Please sign in to comment.