aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/installer/managers/luarocks_spec.lua
blob: 31dd3dc0e3f69c847462cdae3d58fc40396f6c68 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
local luarocks = require "mason-core.installer.managers.luarocks"
local match = require "luassert.match"
local spy = require "luassert.spy"
local stub = require "luassert.stub"
local test_helpers = require "mason-test.helpers"

describe("luarocks manager", function()
    local snapshot

    before_each(function()
        snapshot = assert.snapshot()
    end)

    after_each(function()
        snapshot:revert()
    end)

    it("should install", function()
        local ctx = test_helpers.create_context()
        stub(ctx, "promote_cwd")
        ctx:execute(function()
            luarocks.install("my-rock", "1.0.0")
        end)

        assert.spy(ctx.promote_cwd).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called_with {
            "install",
            { "--tree", ctx.cwd:get() },
            vim.NIL, -- dev
            vim.NIL, -- server
            { "my-rock", "1.0.0" },
        }
    end)

    it("should install dev mode", function()
        local ctx = test_helpers.create_context()
        stub(ctx, "promote_cwd")
        ctx:execute(function()
            luarocks.install("my-rock", "1.0.0", {
                dev = true,
            })
        end)

        assert.spy(ctx.promote_cwd).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called_with {
            "install",
            { "--tree", ctx.cwd:get() },
            "--dev",
            vim.NIL, -- server
            { "my-rock", "1.0.0" },
        }
    end)

    it("should install using provided server", function()
        local ctx = test_helpers.create_context()
        stub(ctx, "promote_cwd")
        ctx:execute(function()
            luarocks.install("my-rock", "1.0.0", {
                server = "https://luarocks.org/dev",
            })
        end)

        assert.spy(ctx.promote_cwd).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called(1)
        assert.spy(ctx.spawn.luarocks).was_called_with {
            "install",
            { "--tree", ctx.cwd:get() },
            vim.NIL, -- dev
            "--server=https://luarocks.org/dev",
            { "my-rock", "1.0.0" },
        }
    end)

    it("should write output", function()
        local ctx = test_helpers.create_context()
        stub(ctx, "promote_cwd")
        spy.on(ctx.stdio_sink, "stdout")
        ctx:execute(function()
            luarocks.install("my-rock", "1.0.0")
        end)

        assert
            .spy(ctx.stdio_sink.stdout)
            .was_called_with(match.is_ref(ctx.stdio_sink), "Installing luarocks package my-rock@1.0.0…\n")
    end)
end)