Repository: neovim/neovim
File: test/functional/plugin/man_spec.lua (Lua)

Code before:
      exec_lua [[require'man'.init_pager()]]

      screen:expect([[
       ^    0      1      2      3                          |
           4      5      6      7      8      9            |
          10     11     12     13     14     15            |
          16                                               |
                                                           |
      ]])
    end)
  end)

  it('q quits in "$MANPAGER mode" (:Man!) #18281', function()
    -- This will hang if #18281 regresses.
    local args = {
      nvim_prog,
      '--headless',
      '+autocmd VimLeave * echo "quit works!!"',
      '+Man!',
      '+tag ls',
      '+call nvim_input("q")',
    }
    matches('quit works!!', fn.system(args, { 'manpage contents' }))
  end)

  it('Raw manpage into (:Man!) will create new buffer #30132', function ()
    local args = {
      nvim_prog,
      '--headless',
      '+autocmd VimEnter * echo bufname()',
      '+call nvim_input("new")',
      '+r!man -Pcat foo',
      '+Man!',
      '+call nvim_input("new")',
      '+r!man -Pcat foo',
      '+Man!',
      '+call nvim_input("new")',
      '+r!man -Pcat foo',
      '+Man!',
      '+call nvim_input("q!")'
    }
    matches('man://', 'man://_copy', 'man://_copy_copy', fn.system(args, { 'manpage contents' }))
  end)

  it('reports non-existent man pages for absolute paths', function()
    skip(is_ci('cirrus'))
    local actual_file = tmpname()
    -- actual_file must be an absolute path to an existent file for us to test against it
    matches('^/.+', actual_file)
    local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' }
    matches(

Review comment (suggestion):
```suggestion
  it('raw manpage into (:Man!) creates a new buffer #30132', function ()
```

Code after:
      exec_lua [[require'man'.init_pager()]]

      screen:expect([[
       ^    0      1      2      3                          |
           4      5      6      7      8      9            |
          10     11     12     13     14     15            |
          16                                               |
                                                           |
      ]])
    end)
  end)

  it('q quits in "$MANPAGER mode" (:Man!) #18281', function()
    -- This will hang if #18281 regresses.
    local args = {
      nvim_prog,
      '--headless',
      '+autocmd VimLeave * echo "quit works!!"',
      '+Man!',
      '+tag ls',
      '+call nvim_input("q")',
    }
    matches('quit works!!', fn.system(args, { 'manpage contents' }))
  end)

  it('raw manpage into (:Man!) creates a new buffer #30132', function()
    local args = {
      nvim_prog,
      '--headless',
      '+Man! foo',
      '+echo bufname()',
      '+enew',
      '+Man! foo',
      '+echo bufname()',
      '+enew',
      '+Man! foo',
      '+echo bufname()',
      '+q',
    }
    local out = fn.system(args, { 'manpage contents' })
    assert(out and out:match('man://%?new=%d'))
  end)

  it('reports non-existent man pages for absolute paths', function()
    skip(is_ci('cirrus'))
    local actual_file = tmpname()
    -- actual_file must be an absolute path to an existent file for us to test against it
    matches('^/.+', actual_file)
    local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' }
    matches(
      ('Error detected while processing command line:\r\n' .. 'man.lua: no manual entry for %s'):format(