Repository: neovim/neovim
File: test/functional/core/job_spec.lua (Lua)

Code before:
    ]])

    feed(':q<CR>')
    if is_os('freebsd') then
      screen:expect { any = vim.pesc('[Process exited 0]') }
    else
      screen:expect([[
                                                          |
        [Process exited 0]^                                |
                                                          |*4
        {5:-- TERMINAL --}                                    |
      ]])
    end
  end)

  it('uses real pipes for stdin/stdout #35984', function()
    skip(is_os('win'), 'Not applicable for Windows')
    -- this fails on linux if we used socketpair() for stdin and stdout,
    -- which libuv does if you ask to create stdio streams for you
    local val = exec_lua([[
      local outpurt
      local job = vim.fn.jobstart('wc /dev/stdin > /dev/stdout', {
      stdout_buffered=true,
      on_stdout=function(chan, data, name)
        output = data
      end})
      vim.fn.chansend(job, 'foo\nbar baz\n')
      vim.fn.chanclose(job, 'stdin')
      vim.fn.jobwait({job})
      return output
      ]])
    eq(2, #val, val)
    eq({ '2', '3', '12', '/dev/stdin' }, vim.split(val[1], '%s+', { trimempty = true }))
    eq('', val[2])
  end)
end)

describe('pty process teardown', function()
  local screen
  before_each(function()
    clear()
    screen = Screen.new(30, 6)
    screen:expect([[
      ^                              |
      {1:~                             }|*4
                                    |
    ]])
  end)

  it('does not prevent/delay exit. #4798 #4900', function()
    skip(fn.executable('sleep') == 0, 'missing "sleep" command')

Review comment (suggestion):
```suggestion
        stdout_buffered=true,
        on_stdout=function(chan, data, name)
          output = data
        end})
```

Code after:
      -- Other job doesn't block first job from receiving SIGHUP on jobclose()
      command('call jobclose(j)')
      -- Have to wait so that the SIGHUP can be processed by tty-test on time.
      -- Can't wait for the next message in case this test fails, if it fails
      -- there won't be any more messages, and the test would hang.
      vim.uv.sleep(100)
      local err = exc_exec('call jobpid(j)')
      eq('Vim(call):E900: Invalid channel id', err)

      -- cleanup
      eq(other_pid, eval('jobpid(' .. other_jobid .. ')'))
      command('call jobstop(' .. other_jobid .. ')')
    end)
  end)

  it('does not close the same handle twice on exit #25086', function()
    local filename = string.format('%s.lua', t.tmpname())
    write_file(
      filename,
      [[
      vim.api.nvim_create_autocmd('VimLeavePre', {
        callback = function()
          local id = vim.fn.jobstart('sleep 0')
          vim.fn.jobwait({id})
        end,
      })
    ]]
    )

    local screen = tt.setup_child_nvim({
      '--cmd',
      'set notermguicolors',
      '-i',
      'NONE',
      '-u',
      filename,
    })
    -- Wait for startup to complete, so that all terminal responses are received.
    screen:expect([[
      ^                                                  |
      ~                                                 |*3
      {2:[No Name]                       0,0-1          All}|
                                                        |
      {5:-- TERMINAL --}                                    |
    ]])

    feed(':q<CR>')
    if is_os('freebsd') then
      screen:expect { any = vim.pesc('[Process exited 0]') }
    else
      screen:expect([[