2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2024-09-15 03:28:14 -07:00
|
|
|
local tt = require('test.functional.testterm')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local assert_log = t.assert_log
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local expect_exit = n.expect_exit
|
|
|
|
local request = n.request
|
2022-05-23 21:44:15 -07:00
|
|
|
|
|
|
|
describe('log', function()
|
2022-06-01 11:28:14 -07:00
|
|
|
local testlog = 'Xtest_logging'
|
2022-05-23 21:44:15 -07:00
|
|
|
|
|
|
|
after_each(function()
|
2022-06-01 11:28:14 -07:00
|
|
|
expect_exit(command, 'qa!')
|
2024-10-30 17:04:51 -07:00
|
|
|
vim.uv.sleep(10) -- Wait for Nvim to fully exit
|
2022-06-01 11:28:14 -07:00
|
|
|
os.remove(testlog)
|
2022-05-23 21:44:15 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('skipped before log_init', function()
|
|
|
|
-- This test is for _visibility_: adjust as needed, after checking for regression.
|
|
|
|
--
|
|
|
|
-- During startup some components may try to log before logging is setup.
|
|
|
|
-- That should be uncommon (ideally never)--and if there are MANY such
|
|
|
|
-- calls, that needs investigation.
|
|
|
|
clear()
|
|
|
|
eq(0, request('nvim__stats').log_skip)
|
|
|
|
clear { env = { CDPATH = '~doesnotexist' } }
|
|
|
|
assert(request('nvim__stats').log_skip <= 13)
|
|
|
|
end)
|
|
|
|
|
2024-09-11 17:25:00 -07:00
|
|
|
it('TUI client name is "ui"', function()
|
|
|
|
local function setup(env)
|
|
|
|
clear()
|
|
|
|
-- Start Nvim with builtin UI.
|
|
|
|
local screen = tt.setup_child_nvim({
|
|
|
|
'-u',
|
|
|
|
'NONE',
|
|
|
|
'-i',
|
|
|
|
'NONE',
|
|
|
|
'--cmd',
|
|
|
|
n.nvim_set,
|
|
|
|
}, {
|
|
|
|
env = env,
|
|
|
|
})
|
|
|
|
screen:expect([[
|
|
|
|
{1: } |
|
|
|
|
~ |*4
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Without $NVIM parent.
|
|
|
|
setup({
|
|
|
|
NVIM = '',
|
|
|
|
NVIM_LISTEN_ADDRESS = '',
|
|
|
|
NVIM_LOG_FILE = testlog,
|
|
|
|
__NVIM_TEST_LOG = '1',
|
|
|
|
})
|
|
|
|
-- Example:
|
|
|
|
-- ERR 2024-09-11T16:40:02.421 ui.47056 ui_client_run:165: test log message
|
|
|
|
assert_log(' ui%.%d+% +ui_client_run:%d+: test log message', testlog, 100)
|
|
|
|
|
|
|
|
-- With $NVIM parent.
|
|
|
|
setup({
|
|
|
|
NVIM_LOG_FILE = testlog,
|
|
|
|
__NVIM_TEST_LOG = '1',
|
|
|
|
})
|
|
|
|
-- Example:
|
|
|
|
-- ERR 2024-09-11T16:41:17.539 ui/c/T2.47826.0 ui_client_run:165: test log message
|
|
|
|
local tid = _G._nvim_test_id
|
|
|
|
assert_log(' ui/c/' .. tid .. '%.%d+%.%d +ui_client_run:%d+: test log message', testlog, 100)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('formats messages with session name or test id', function()
|
2022-05-23 21:44:15 -07:00
|
|
|
-- Examples:
|
2024-09-11 17:25:00 -07:00
|
|
|
-- ERR 2024-09-11T16:44:33.794 T3.49429.0 server_init:58: test log message
|
|
|
|
-- ERR 2024-09-11T16:44:33.823 c/T3.49429.0 server_init:58: test log message
|
2022-05-23 21:44:15 -07:00
|
|
|
|
|
|
|
clear({
|
|
|
|
env = {
|
2022-06-01 11:28:14 -07:00
|
|
|
NVIM_LOG_FILE = testlog,
|
|
|
|
-- TODO: remove this after nvim_log #7062 is merged.
|
2022-05-23 21:44:15 -07:00
|
|
|
__NVIM_TEST_LOG = '1',
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2022-05-23 21:44:15 -07:00
|
|
|
})
|
|
|
|
|
2022-06-01 11:28:14 -07:00
|
|
|
local tid = _G._nvim_test_id
|
2023-01-16 16:12:59 -07:00
|
|
|
assert_log(tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100)
|
2022-05-23 21:44:15 -07:00
|
|
|
|
|
|
|
exec_lua([[
|
|
|
|
local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict())
|
2024-09-11 17:25:00 -07:00
|
|
|
vim.fn.jobwait({ j1 }, 5000)
|
2022-05-23 21:44:15 -07:00
|
|
|
]])
|
|
|
|
|
2024-09-11 17:25:00 -07:00
|
|
|
-- Child Nvim spawned by jobstart() prepends "c/" to parent name.
|
|
|
|
assert_log('c/' .. tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100)
|
2022-05-23 21:44:15 -07:00
|
|
|
end)
|
|
|
|
end)
|