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

Code before:
      pcall_err(command, "call jobstart(['cat', '-'], { 'cwd': 'bogusssssss/bogus' })")
    )
    matches(
      "E475: Invalid argument: 'term' must be Boolean",
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': 'bogus' })")
    )
    matches(
      "E475: Invalid argument: 'term' must be Boolean",
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': 1 })")
    )
    command('set modified')
    matches(
      vim.pesc('jobstart(...,{term=true}) requires unmodified buffer'),
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': v:true })")
    )

    -- Non-failure cases:
    command('set nomodified')
    command("call jobstart(['cat', '-'], { 'term': v:true })")
    command("call jobstart(['cat', '-'], { 'term': v:false })")

    -- "term=true" accept width/height (#33904)
    local buf = api.nvim_create_buf(false, true)
    exec_lua(function()
      vim.api.nvim_buf_call(buf, function()
        vim.fn.jobstart(
          { 'nvim', '--clean', '--headless', '+lua print(vim.uv.new_tty(0, true):get_winsize())' },
          { term = true, width = 11, height = 12 }
        )
      end)
    end)
    retry(nil, nil, function()
      eq({ '11 12' }, api.nvim_buf_get_lines(buf, 0, 1, false))
    end)
  end)

  it('must specify env option as a dict', function()
    command('let g:job_opts.env = v:true')
    local _, err = pcall(function()
      if is_os('win') then
        command("let j = jobstart('set', g:job_opts)")
      else
        command("let j = jobstart('env', g:job_opts)")
      end
    end)
    matches('E475: Invalid argument: env', err)
  end)

  it('append environment #env', function()
    command("let $VAR = 'abc'")
    command("let $TOTO = 'goodbye world'")

Review comment (refactor):
could use `api.nvim_set_current_buf(buf)` to avoid the need for `exec_lua`/`nvim_buf_call`.

and, let's move this test to a new it() since there's no other place for it.

    it('jobstart(term=true) accepts width/height',

Code after:
      pcall_err(command, "call jobstart(['cat', '-'], { 'cwd': 'bogusssssss/bogus' })")
    )
    matches(
      "E475: Invalid argument: 'term' must be Boolean",
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': 'bogus' })")
    )
    matches(
      "E475: Invalid argument: 'term' must be Boolean",
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': 1 })")
    )
    command('set modified')
    matches(
      vim.pesc('jobstart(...,{term=true}) requires unmodified buffer'),
      pcall_err(command, "call jobstart(['cat', '-'], { 'term': v:true })")
    )

    -- Non-failure cases:
    command('set nomodified')
    command("call jobstart(['cat', '-'], { 'term': v:true })")
    command("call jobstart(['cat', '-'], { 'term': v:false })")
  end)

  it('jobstart(term=true) accepts width/height (#33904)', function()
    local buf = api.nvim_create_buf(false, true)
    exec_lua(function()
      vim.api.nvim_buf_call(buf, function()
        vim.fn.jobstart({
          vim.v.progpath,
          '--clean',
          '--headless',
          '+lua print(vim.uv.new_tty(1, false):get_winsize())',
        }, {
          term = true,
          width = 11,
          height = 12,
          env = { VIMRUNTIME = os.getenv('VIMRUNTIME') },
        })
      end)
    end)
    retry(nil, nil, function()
      eq({ '11 12' }, api.nvim_buf_get_lines(buf, 0, 1, false))
    end)
  end)

  it('must specify env option as a dict', function()
    command('let g:job_opts.env = v:true')
    local _, err = pcall(function()
      if is_os('win') then
        command("let j = jobstart('set', g:job_opts)")
      else
        command("let j = jobstart('env', g:job_opts)")