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

Code before:
      local after_dir = vim.fs.joinpath(plug_path, 'after')
      eq(true, vim.tbl_contains(rtp, plug_path))
      -- No 'after/' directory in runtimepath because it is not present in plugin
      eq(false, vim.tbl_contains(rtp, after_dir))
    end)

    it("doesn't checkouts any files when the specified version doesn't exists", function()
      local err = pcall_err(exec_lua, function()
        vim.pack.add({
          {
            src = repos_src.basic,
            version = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
          },
        })
      end)
      n.clear()
      eq(
        'number',
        type(err:find('`deadbeefdeadbeefdeadbeefdeadbeefdeadbeef` is not a branch/tag/commit'))
      )

      local plug_path = pack_get_plug_path('basic')
      local entries = vim.iter(vim.fs.dir(plug_path)):totable()

      eq(true, vim.deep_equal(entries, { { '.git', 'directory' } }))
    end)

    it('can install from the Internet', function()
      t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
      exec_lua(function()
        vim.pack.add({ 'https://github.com/neovim/nvim-lspconfig' })
      end)
      eq(true, exec_lua('return pcall(require, "lspconfig")'))
    end)

    describe('startup', function()
      local init_lua = ''
      before_each(function()
        init_lua = vim.fs.joinpath(fn.stdpath('config'), 'init.lua')
        fn.mkdir(vim.fs.dirname(init_lua), 'p')
      end)
      after_each(function()
        pcall(vim.fs.rm, init_lua, { force = true })
      end)

      it('works in init.lua', function()
        local pack_add_cmd = ('vim.pack.add({ %s })'):format(vim.inspect(repos_src.plugindirs))
        fn.writefile({ pack_add_cmd, '_G.done = true' }, init_lua)

        local validate_loaded = function()
          eq('plugindirs main', exec_lua('return require("plugindirs")'))

Review comment (suggestion):
```suggestion
    it('does not checkout on bad `version`', function()
      local err = pcall_err(exec_lua, function()
        vim.pack.add({ { src = repos_src.basic, version = 'not-exist' } })
      end)
      matches('`not%-exist` is not a branch/tag/commit', err)

      local plug_path = pack_get_plug_path('basic')
      local entries = vim.iter(vim.fs.dir(plug_path)):totable()
      eq({ { '.git', 'directory' } }, entries)
    end)
```

Code after:
      local after_dir = vim.fs.joinpath(plug_path, 'after')
      eq(true, vim.tbl_contains(rtp, plug_path))
      -- No 'after/' directory in runtimepath because it is not present in plugin
      eq(false, vim.tbl_contains(rtp, after_dir))
    end)

    it('does not checkout on bad `version`', function()
      local err = pcall_err(exec_lua, function()
        vim.pack.add({ { src = repos_src.basic, version = 'not-exist' } })
      end)
      matches('`not%-exist` is not a branch/tag/commit', err)
      local plug_path = pack_get_plug_path('basic')
      local entries = vim.iter(vim.fs.dir(plug_path)):totable()
      eq({ { '.git', 'directory' } }, entries)
    end)

    it('can install from the Internet', function()
      t.skip(skip_integ, 'NVIM_TEST_INTEG not set: skipping network integration test')
      exec_lua(function()
        vim.pack.add({ 'https://github.com/neovim/nvim-lspconfig' })
      end)
      eq(true, exec_lua('return pcall(require, "lspconfig")'))
    end)

    describe('startup', function()
      local init_lua = ''
      before_each(function()
        init_lua = vim.fs.joinpath(fn.stdpath('config'), 'init.lua')
        fn.mkdir(vim.fs.dirname(init_lua), 'p')
      end)
      after_each(function()
        pcall(vim.fs.rm, init_lua, { force = true })
      end)

      it('works in init.lua', function()
        local pack_add_cmd = ('vim.pack.add({ %s })'):format(vim.inspect(repos_src.plugindirs))
        fn.writefile({ pack_add_cmd, '_G.done = true' }, init_lua)

        local validate_loaded = function()
          eq('plugindirs main', exec_lua('return require("plugindirs")'))

          -- Should source 'plugin/' and 'after/plugin/' exactly once
          eq({ true, true }, n.exec_lua('return { vim.g._plugin, vim.g._after_plugin }'))
          eq({ 'p', 'a' }, n.exec_lua('return _G.DL'))
        end

        -- Should auto-install but wait before executing code after it
        n.clear({ args_rm = { '-u' } })
        n.exec_lua('vim.wait(500, function() return _G.done end, 50)')
        validate_loaded()