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

Code before:
    eq('vim.deprecated', getcompletion('vim', 'checkhealth')[1])
    eq('vim.provider', getcompletion('vim.prov', 'checkhealth')[1])
    eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1])

    -- "test_plug/health/init.lua" should complete as "test_plug", not "test_plug.health". #30342
    eq({
      'test_plug',
      'test_plug.full_render',
      'test_plug.submodule',
      'test_plug.submodule_empty',
      'test_plug.success1',
      'test_plug.success2',
    }, getcompletion('test_plug', 'checkhealth'))
  end)

  it('completion checks for vim.health._complete() return type #28456', function()
    clear()
    exec_lua([[vim.health._complete = function() return 1 end]])
    eq({}, getcompletion('', 'checkhealth'))
    exec_lua([[vim.health._complete = function() return { 1 } end]])
    eq({}, getcompletion('', 'checkhealth'))
    assert_alive()
  end)

  it('vim.g.health', function()
    clear { args = { '-u', 'NORC', '+set runtimepath+=test/functional/fixtures' } }
    command("let g:health = {'style':'float'}")
    command('checkhealth lsp')
    eq(
      'editor',
      exec_lua([[
      return vim.api.nvim_win_get_config(0).relative
    ]])
    )

    -- Prevent checkhealth floating window closing after using gO. See #34784
    command('checkhealth full_render')
    local win = api.nvim_get_current_win()
    api.nvim_win_set_cursor(win, { 5, 1 })
    n.feed('gO')
    eq(true, api.nvim_win_is_valid(win))
    eq('qf', api.nvim_get_option_value('filetype', { buf = 0 }))
  end)

  it("vim.provider works with a misconfigured 'shell'", function()
    clear()
    command([[set shell=echo\ WRONG!!!]])
    command('let g:loaded_perl_provider = 0')
    command('let g:loaded_python3_provider = 0')
    command('checkhealth vim.provider')
    eq(nil, string.match(curbuf_contents(), 'WRONG!!!'))

Review comment (suggestion):
clear() specifies `-u NONE`, but I assume you are overriding it with `-u NORC` want plugins to be loaded? if so, try `args_rm` to make it clear what you want to override. And `--clean` seems more appropriate.

```lua
clear {
  args_rm = { '-u' },
  args = { '--clean', '+set runtimepath+=test/functional/fixtures' },
}
```

Code after:
    eq('vim.deprecated', getcompletion('vim', 'checkhealth')[1])
    eq('vim.provider', getcompletion('vim.prov', 'checkhealth')[1])
    eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1])

    -- "test_plug/health/init.lua" should complete as "test_plug", not "test_plug.health". #30342
    eq({
      'test_plug',
      'test_plug.full_render',
      'test_plug.submodule',
      'test_plug.submodule_empty',
      'test_plug.success1',
      'test_plug.success2',
    }, getcompletion('test_plug', 'checkhealth'))
  end)

  it('completion checks for vim.health._complete() return type #28456', function()
    clear()
    exec_lua([[vim.health._complete = function() return 1 end]])
    eq({}, getcompletion('', 'checkhealth'))
    exec_lua([[vim.health._complete = function() return { 1 } end]])
    eq({}, getcompletion('', 'checkhealth'))
    assert_alive()
  end)

  it('vim.g.health', function()
    clear {
      args_rm = { '-u' },
      args = { '--clean', '+set runtimepath+=test/functional/fixtures' },
    }
    command("let g:health = {'style':'float'}")
    command('checkhealth lsp')
    eq(
      'editor',
      exec_lua([[
      return vim.api.nvim_win_get_config(0).relative
    ]])
    )

    -- gO should not close the :checkhealth floating window. #34784
    command('checkhealth full_render')
    local win = api.nvim_get_current_win()
    api.nvim_win_set_cursor(win, { 5, 1 })
    n.feed('gO')
    eq(true, api.nvim_win_is_valid(win))
    eq('qf', api.nvim_get_option_value('filetype', { buf = 0 }))
  end)

  it("vim.provider works with a misconfigured 'shell'", function()
    clear()
    command([[set shell=echo\ WRONG!!!]])
    command('let g:loaded_perl_provider = 0')