log_spec.lua (3164B)
1 local t = require('test.testutil') 2 local n = require('test.functional.testnvim')() 3 local tt = require('test.functional.testterm') 4 5 local assert_log = t.assert_log 6 local clear = n.clear 7 local command = n.command 8 local eq = t.eq 9 local exec_lua = n.exec_lua 10 local expect_exit = n.expect_exit 11 local request = n.request 12 13 describe('log', function() 14 local testlog = 'Xtest_logging' 15 16 after_each(function() 17 expect_exit(command, 'qa!') 18 vim.uv.sleep(10) -- Wait for Nvim to fully exit 19 os.remove(testlog) 20 end) 21 22 it('skipped before log_init', function() 23 -- This test is for _visibility_: adjust as needed, after checking for regression. 24 -- 25 -- During startup some components may try to log before logging is setup. 26 -- That should be uncommon (ideally never)--and if there are MANY such 27 -- calls, that needs investigation. 28 clear() 29 eq(0, request('nvim__stats').log_skip) 30 clear { env = { CDPATH = '~doesnotexist' } } 31 assert(request('nvim__stats').log_skip <= 13) 32 end) 33 34 it('TUI client name is "ui"', function() 35 local function setup(env) 36 clear() 37 -- Start Nvim with builtin UI. 38 local screen = tt.setup_child_nvim({ 39 '-u', 40 'NONE', 41 '-i', 42 'NONE', 43 '--cmd', 44 n.nvim_set, 45 }, { 46 env = env, 47 }) 48 screen:expect([[ 49 ^ | 50 ~ |*4 51 | 52 {5:-- TERMINAL --} | 53 ]]) 54 end 55 56 -- Without $NVIM parent. 57 setup({ 58 NVIM = '', 59 NVIM_LISTEN_ADDRESS = '', 60 NVIM_LOG_FILE = testlog, 61 __NVIM_TEST_LOG = '1', 62 }) 63 -- Example: 64 -- ERR 2024-09-11T16:40:02.421 ui.47056 ui_client_run:165: test log message 65 assert_log(' ui%.%d+% +ui_client_run:%d+: test log message', testlog, 100) 66 67 -- With $NVIM parent. 68 setup({ 69 NVIM_LOG_FILE = testlog, 70 __NVIM_TEST_LOG = '1', 71 }) 72 -- Example: 73 -- ERR 2024-09-11T16:41:17.539 ui/c/T2.47826.0 ui_client_run:165: test log message 74 local tid = _G._nvim_test_id 75 assert_log(' ui/c/' .. tid .. '%.%d+%.%d +ui_client_run:%d+: test log message', testlog, 100) 76 end) 77 78 it('formats messages with session name or test id', function() 79 -- Examples: 80 -- ERR 2024-09-11T16:44:33.794 T3.49429.0 server_init:58: test log message 81 -- ERR 2024-09-11T16:44:33.823 c/T3.49429.0 server_init:58: test log message 82 83 clear({ 84 env = { 85 NVIM_LOG_FILE = testlog, 86 -- TODO: remove this after nvim_log #7062 is merged. 87 __NVIM_TEST_LOG = '1', 88 }, 89 }) 90 91 local tid = _G._nvim_test_id 92 assert_log(tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100) 93 94 exec_lua([[ 95 local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict()) 96 vim.fn.jobwait({ j1 }, 5000) 97 ]]) 98 99 -- Child Nvim spawned by jobstart() prepends "c/" to parent name. 100 assert_log('c/' .. tid .. '%.%d+%.%d +server_init:%d+: test log message', testlog, 100) 101 end) 102 end)