aboutsummaryrefslogtreecommitdiffstats
path: root/tests/core/managers/opam_spec.lua
blob: 39e892ca01748d6a38d5a38397a3ae8189d33ae9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local match = require "luassert.match"
local mock = require "luassert.mock"
local Optional = require "nvim-lsp-installer.core.optional"
local installer = require "nvim-lsp-installer.core.installer"
local opam = require "nvim-lsp-installer.core.managers.opam"

describe("opam manager", function()
    ---@type InstallContext
    local ctx
    before_each(function()
        ctx = InstallContextGenerator {
            spawn = mock.new {
                opam = mockx.returns {},
            },
        }
    end)

    it(
        "should call opam install",
        async_test(function()
            ctx.requested_version = Optional.of "42.13.37"
            installer.run_installer(ctx, opam.packages { "main-package", "supporting-package", "supporting-package2" })
            assert.spy(ctx.spawn.opam).was_called(1)
            assert.spy(ctx.spawn.opam).was_called_with(match.tbl_containing {
                "install",
                "--destdir=.",
                "--yes",
                "--verbose",
                match.tbl_containing {
                    "main-package.42.13.37",
                    "supporting-package",
                    "supporting-package2",
                },
            })
        end)
    )

    it(
        "should provide receipt information",
        async_test(function()
            ctx.requested_version = Optional.of "42.13.37"
            installer.run_installer(ctx, opam.packages { "main-package", "supporting-package", "supporting-package2" })
            assert.equals(
                vim.inspect {
                    type = "opam",
                    package = "main-package",
                },
                vim.inspect(ctx.receipt.primary_source)
            )
            assert.equals(
                vim.inspect {
                    {
                        type = "opam",
                        package = "supporting-package",
                    },
                    {
                        type = "opam",
                        package = "supporting-package2",
                    },
                },
                vim.inspect(ctx.receipt.secondary_sources)
            )
        end)
    )
end)