• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nightconcept / almandine / 14716629923

28 Apr 2025 07:54PM UTC coverage: 95.996%. First build
14716629923

push

github

web-flow
feat: Initial features (#1)

863 of 899 new or added lines in 16 files covered. (96.0%)

863 of 899 relevant lines covered (96.0%)

1.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/src/spec/modules/add_spec.lua
1
--[[
2
  Add Module Specification
3

4
  Busted test suite for add_dependency in src/modules/add.lua.
5
  - Verifies dependency addition, manifest update, downloader call, and name inference.
6
  - Uses only stubs/mocks and does not touch real files or network.
7
]]
8
--
9

10
-- luacheck: globals describe it assert
11

12
--- Add module specification for Busted.
13
-- @module add_spec
14

15
describe("add_module.add_dependency", function()
2✔
16
  local add_mod = require("modules.add")
1✔
17
  local busted = require("busted")
1✔
18
  local stub = busted.stub or require("luassert.stub")
1✔
19

20
  local function make_fake_manifest()
21
    return {
4✔
22
      name = "test-project",
4✔
23
      type = "application",
4✔
24
      version = "0.0.1",
4✔
25
      license = "MIT",
4✔
26
      description = "Test manifest",
4✔
27
      scripts = {},
4✔
28
      dependencies = {},
4✔
29
    }
4✔
30
  end
31

32
  it("adds a simple dependency", function()
2✔
33
    local manifest = make_fake_manifest()
1✔
34
    local saved_manifest, save_called
35
    local function load_manifest()
36
      return manifest, nil
1✔
37
    end
38
    local function save_manifest(m)
39
      saved_manifest = m
1✔
40
      save_called = true
1✔
41
      return true, nil
1✔
42
    end
43
    local ensure_lib_dir_called = false
1✔
44
    local function ensure_lib_dir()
45
      ensure_lib_dir_called = true
1✔
46
    end
47
    local downloader_called = false
1✔
48
    local downloader_args = {}
1✔
49
    local downloader = {
1✔
50
      download = function(url, out_path)
51
        downloader_called = true
1✔
52
        downloader_args.url = url
1✔
53
        downloader_args.out_path = out_path
1✔
54
        return true, nil
1✔
55
      end,
56
    }
57
    local dep_name = "foo"
1✔
58
    local dep_url = "https://example.com/foo.lua"
1✔
59
    add_mod.add_dependency(dep_name, dep_url, load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
60
    assert.is_true(save_called)
1✔
61
    assert.are.equal(saved_manifest.dependencies[dep_name], dep_url)
1✔
62
    assert.is_true(ensure_lib_dir_called)
1✔
63
    assert.is_true(downloader_called)
1✔
64
    assert.are.equal(downloader_args.url, dep_url)
1✔
65
    assert.are.equal(downloader_args.out_path, "src/lib/foo.lua")
1✔
66
  end)
67

68
  it("adds a dependency from a table source", function()
2✔
69
    local manifest = make_fake_manifest()
1✔
70
    local saved_manifest
71
    local function load_manifest()
72
      return manifest, nil
1✔
73
    end
74
    local function save_manifest(m)
75
      saved_manifest = m
1✔
76
      return true, nil
1✔
77
    end
78
    local ensure_lib_dir = function() end
2✔
79
    local downloader_args = {}
1✔
80
    local downloader = {
1✔
81
      download = function(url, out_path)
82
        downloader_args.url = url
1✔
83
        downloader_args.out_path = out_path
1✔
84
        return true, nil
1✔
85
      end,
86
    }
87
    local dep_name = "bar"
1✔
88
    local dep_source = { url = "https://example.com/bar.lua", path = "custom/bar.lua" }
1✔
89
    add_mod.add_dependency(dep_name, dep_source, load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
90
    assert.are.same(saved_manifest.dependencies[dep_name], dep_source)
1✔
91
    assert.are.equal(downloader_args.url, dep_source.url)
1✔
92
    assert.are.equal(downloader_args.out_path, dep_source.path)
1✔
93
  end)
94

95
  it("does not fail when no dependency is given", function()
2✔
96
    local manifest = make_fake_manifest()
1✔
97
    local function load_manifest()
98
      return manifest, nil
1✔
99
    end
100
    local save_manifest = function()
NEW
101
      error("Should not be called")
×
102
    end
103
    local ensure_lib_dir = function() end
2✔
104
    local downloader = {
1✔
105
      download = function()
NEW
106
        return true, nil
×
107
      end,
108
    }
109
    assert.has_no.errors(function()
2✔
110
      add_mod.add_dependency(nil, nil, load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
111
    end)
112
  end)
113

114
  it("infers name from URL if not provided", function()
2✔
115
    local manifest = make_fake_manifest()
1✔
116
    local saved_manifest, save_called
117
    local function load_manifest()
118
      return manifest, nil
1✔
119
    end
120
    local function save_manifest(m)
121
      saved_manifest = m
1✔
122
      save_called = true
1✔
123
      return true, nil
1✔
124
    end
125
    local ensure_lib_dir_called = false
1✔
126
    local function ensure_lib_dir()
127
      ensure_lib_dir_called = true
1✔
128
    end
129
    local downloader_called = false
1✔
130
    local downloader_args = {}
1✔
131
    local downloader = {
1✔
132
      download = function(url, out_path)
133
        downloader_called = true
1✔
134
        downloader_args.url = url
1✔
135
        downloader_args.out_path = out_path
1✔
136
        return true, nil
1✔
137
      end,
138
    }
139
    local dep_url = "https://raw.githubusercontent.com/owner/repo/branch/path/to/baz.lua"
1✔
140
    add_mod.add_dependency(nil, dep_url, load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
141
    assert.is_true(save_called)
1✔
142
    assert.are.equal(saved_manifest.dependencies["baz"], dep_url)
1✔
143
    assert.is_true(ensure_lib_dir_called)
1✔
144
    assert.is_true(downloader_called)
1✔
145
    assert.are.equal(downloader_args.url, dep_url)
1✔
146
    assert.are.equal(downloader_args.out_path, "src/lib/baz.lua")
1✔
147
  end)
148

149
  it("prints error and returns if manifest fails to load", function()
2✔
150
    local function load_manifest()
151
      return nil, "manifest load error"
1✔
152
    end
153
    local save_manifest = function() end
1✔
154
    local ensure_lib_dir = function() end
2✔
155
    local downloader = {
1✔
156
      download = function()
NEW
157
        return true, nil
×
158
      end,
159
    }
160
    local printed = {}
1✔
161
    stub(_G, "print", function(msg)
2✔
162
      table.insert(printed, tostring(msg))
1✔
163
    end)
164
    assert.has_no.errors(function()
2✔
165
      require("modules.add").add_dependency("foo", "url", load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
166
    end)
167
    assert.is_true(table.concat(printed, "\n"):match("manifest load error") ~= nil)
1✔
168
  end)
169

170
  it("prints error and returns if dep_name cannot be inferred from bad URL", function()
2✔
171
    local manifest = { dependencies = {} }
1✔
172
    local function load_manifest()
173
      return manifest, nil
1✔
174
    end
175
    local save_manifest_called = false
1✔
176
    local save_manifest = function()
NEW
177
      save_manifest_called = true
×
178
    end
179
    local ensure_lib_dir = function() end
2✔
180
    local downloader = {
1✔
181
      download = function()
NEW
182
        return true, nil
×
183
      end,
184
    }
185
    local printed = {}
1✔
186
    stub(_G, "print", function(msg)
2✔
187
      table.insert(printed, tostring(msg))
1✔
188
    end)
189
    assert.has_no.errors(function()
2✔
190
      require("modules.add").add_dependency(
2✔
191
        nil,
1✔
192
        "https://example.com/",
1✔
193
        load_manifest,
1✔
194
        save_manifest,
1✔
195
        ensure_lib_dir,
1✔
196
        downloader
197
      )
1✔
198
    end)
199
    assert.is_true(table.concat(printed, "\n"):match("Could not infer dependency name") ~= nil)
1✔
200
    assert.is_false(save_manifest_called)
1✔
201
  end)
202

203
  it("prints error and returns if save_manifest fails", function()
2✔
204
    local manifest = { dependencies = {} }
1✔
205
    local function load_manifest()
206
      return manifest, nil
1✔
207
    end
208
    local function save_manifest()
209
      return false, "save failed"
1✔
210
    end
211
    local ensure_lib_dir = function() end
2✔
212
    local downloader = {
1✔
213
      download = function()
NEW
214
        return true, nil
×
215
      end,
216
    }
217
    local printed = {}
1✔
218
    stub(_G, "print", function(msg)
2✔
219
      table.insert(printed, tostring(msg))
1✔
220
    end)
221
    assert.has_no.errors(function()
2✔
222
      require("modules.add").add_dependency("foo", "url", load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
223
    end)
224
    assert.is_true(table.concat(printed, "\n"):match("save failed") ~= nil)
1✔
225
  end)
226

227
  it("prints error if downloader fails", function()
2✔
228
    local manifest = { dependencies = {} }
1✔
229
    local function load_manifest()
230
      return manifest, nil
1✔
231
    end
232
    local function save_manifest()
233
      return true, nil
1✔
234
    end
235
    local ensure_lib_dir = function() end
2✔
236
    local downloader = {
1✔
237
      download = function()
238
        return false, "download failed"
1✔
239
      end,
240
    }
241
    local printed = {}
1✔
242
    stub(_G, "print", function(msg)
2✔
243
      table.insert(printed, tostring(msg))
2✔
244
    end)
245
    assert.has_no.errors(function()
2✔
246
      require("modules.add").add_dependency("foo", "url", load_manifest, save_manifest, ensure_lib_dir, downloader)
1✔
247
    end)
248
    local output = table.concat(printed, "\n")
1✔
249
    assert.is_true(output:match("Failed to download") ~= nil)
1✔
250
    assert.is_true(output:match("download failed") ~= nil)
1✔
251
  end)
252

253
  it("prints usage/help output", function()
2✔
254
    local add_mod_local = require("modules.add")
1✔
255
    local output = {}
1✔
256
    stub(_G, "print", function(msg)
2✔
257
      table.insert(output, tostring(msg))
1✔
258
    end)
259
    assert.has_no.errors(function()
2✔
260
      add_mod_local.help_info()
1✔
261
    end)
262
    local all = table.concat(output, "\n")
1✔
263
    assert.is_true(all:match("Usage: almd add") ~= nil)
1✔
264
  end)
265
end)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc