log_spec.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local assert_log = helpers.assert_log
  3. local clear = helpers.clear
  4. local command = helpers.command
  5. local eq = helpers.eq
  6. local exec_lua = helpers.exec_lua
  7. local expect_exit = helpers.expect_exit
  8. local request = helpers.request
  9. local retry = helpers.retry
  10. describe('log', function()
  11. local testlog = 'Xtest_logging'
  12. after_each(function()
  13. expect_exit(command, 'qa!')
  14. os.remove(testlog)
  15. end)
  16. it('skipped before log_init', function()
  17. -- This test is for _visibility_: adjust as needed, after checking for regression.
  18. --
  19. -- During startup some components may try to log before logging is setup.
  20. -- That should be uncommon (ideally never)--and if there are MANY such
  21. -- calls, that needs investigation.
  22. clear()
  23. eq(0, request('nvim__stats').log_skip)
  24. clear{env={CDPATH='~doesnotexist'}}
  25. assert(request('nvim__stats').log_skip <= 13)
  26. end)
  27. it('messages are formatted with name or test id', function()
  28. -- Examples:
  29. -- ERR 2022-05-29T12:30:03.800 T2 log_init:110: test log message
  30. -- ERR 2022-05-29T12:30:03.814 T2/child log_init:110: test log message
  31. clear({env={
  32. NVIM_LOG_FILE=testlog,
  33. -- TODO: remove this after nvim_log #7062 is merged.
  34. __NVIM_TEST_LOG='1'
  35. }})
  36. local tid = _G._nvim_test_id
  37. retry(nil, 1000, function()
  38. assert_log(tid..'%.%d+%.%d +server_init:%d+: test log message', testlog, 100)
  39. end)
  40. exec_lua([[
  41. local j1 = vim.fn.jobstart({ vim.v.progpath, '-es', '-V1', '+foochild', '+qa!' }, vim.empty_dict())
  42. vim.fn.jobwait({ j1 }, 10000)
  43. ]])
  44. -- Child Nvim spawned by jobstart() appends "/c" to parent name.
  45. retry(nil, 1000, function()
  46. assert_log('%.%d+%.%d/c +server_init:%d+: test log message', testlog, 100)
  47. end)
  48. end)
  49. end)