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

nightconcept / almandine / 14718277335

28 Apr 2025 09:29PM UTC coverage: 97.146% (+0.02%) from 97.124%
14718277335

push

github

nightconcept
fix: Fix install script pathing for calling Lua

1021 of 1051 relevant lines covered (97.15%)

2.07 hits per line

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

96.36
/src/spec/modules/update_spec.lua
1
--[[
2
  Update Module Specification
3

4
  Busted test suite for update_dependencies in src/modules/update.lua.
5
  - Verifies update to latest allowed and absolute latest versions.
6
  - Uses stubs/mocks for manifest, downloader, and resolver.
7
]]
8
--
9

10
-- luacheck: globals describe it assert
11
-- local busted = require("busted")  -- unused
12

13
--- Update module specification for Busted.
14
-- @module update_spec
15

16
describe("update_module.update_dependencies", function()
2✔
17
  local update_module = require("modules.update")
1✔
18

19
  it("updates dependency to latest allowed version", function()
2✔
20
    local manifest = { dependencies = { foo = "https://example.com/foo.lua" } }
1✔
21
    local function load()
22
      return manifest
1✔
23
    end
24
    local function save(_) -- luacheck: ignore
25
      manifest = _
1✔
26
    end
27
    local function ensure_lib_dir1() end
2✔
28
    local utils = { downloader = {
1✔
29
      download = function()
30
        return true
1✔
31
      end,
32
    } }
1✔
33
    local function resolve_latest_version(_name)
34
      return "1.3.4"
1✔
35
    end
36
    update_module.update_dependencies(load, save, ensure_lib_dir1, utils, resolve_latest_version)
1✔
37
    -- After update, manifest.dependencies.foo should be a table with version and url
38
    assert.are.equal(manifest.dependencies.foo.version, "1.3.4")
1✔
39
    assert.are.equal(manifest.dependencies.foo.url, "https://example.com/foo.lua")
1✔
40
  end)
41

42
  it("updates dependency to absolute latest version", function()
2✔
43
    local manifest = { dependencies = { foo = "https://example.com/foo.lua" } }
1✔
44
    local function load()
45
      return manifest
1✔
46
    end
47
    local function save(_) -- luacheck: ignore
48
    end
49
    local function ensure_lib_dir2() end
2✔
50
    local utils = { downloader = {
1✔
51
      download = function()
52
        return true
1✔
53
      end,
54
    } }
1✔
55
    local function resolve_latest_version(_name)
56
      return "latest"
1✔
57
    end
58
    update_module.update_dependencies(load, save, ensure_lib_dir2, utils, resolve_latest_version, true)
1✔
59
    assert.are.equal(manifest.dependencies.foo.version, "latest")
1✔
60
    assert.are.equal(manifest.dependencies.foo.url, "https://example.com/foo.lua")
1✔
61
  end)
62

63
  it("updates dependency versions in manifest", function()
2✔
64
    local manifest = {
1✔
65
      dependencies = {
1✔
66
        foo = {
1✔
67
          version = "1.0.0",
1✔
68
          url = "https://example.com/foo.lua",
1✔
69
        },
1✔
70
      },
1✔
71
    }
72
    local function load()
73
      return manifest
1✔
74
    end
75
    local function save(_) -- luacheck: ignore
76
      manifest = _
1✔
77
    end
78
    local function ensure_lib_dir3() end
2✔
79
    local utils = { downloader = {
1✔
80
      download = function()
81
        return true
1✔
82
      end,
83
    } }
1✔
84
    local function resolve_latest_version(_name)
85
      return "2.0.0"
1✔
86
    end
87
    update_module.update_dependencies(load, save, ensure_lib_dir3, utils, resolve_latest_version)
1✔
88
    assert.are.equal(manifest.dependencies.foo.version, "2.0.0")
1✔
89
    assert.are.equal(manifest.dependencies.foo.url, "https://example.com/foo.lua")
1✔
90
  end)
91

92
  it("prints error and returns if manifest fails to load", function()
2✔
93
    local function load()
94
      return nil, "manifest error!"
1✔
95
    end
96
    local function save(_) -- luacheck: ignore
97
      error("should not save on manifest load error")
×
98
    end
99
    local ensure_lib_dir = function() end
2✔
100
    local utils = { downloader = {
1✔
101
      download = function()
102
        error("should not download")
×
103
      end,
104
    } }
1✔
105
    local resolve_latest_version = function()
106
      error("should not resolve")
×
107
    end
108
    local printed = {}
1✔
109
    local printer = function(...)
110
      local args = { ... }
1✔
111
      for i = 1, #args do
2✔
112
        args[i] = tostring(args[i])
1✔
113
      end
114
      table.insert(printed, table.concat(args, " "))
1✔
115
    end
116
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version, nil, printer)
1✔
117
    local output = table.concat(printed, "\n")
1✔
118
    assert.is_true(output:find("manifest error!", 1, true) ~= nil)
1✔
119
  end)
120

121
  it("does not update or save if dependency already up-to-date", function()
2✔
122
    local manifest = { dependencies = { foo = { version = "1.3.4", url = "https://example.com/foo.lua" } } }
1✔
123
    local function load()
124
      return manifest
1✔
125
    end
126
    local function save(_) -- luacheck: ignore
127
    end
128
    local ensure_lib_dir = function() end
2✔
129
    local utils = {
1✔
130
      downloader = {
1✔
131
        download = function()
132
          error("should not download if up-to-date")
×
133
        end,
134
      },
1✔
135
    }
136
    local resolve_latest_version = function(_name)
137
      return "1.3.4"
1✔
138
    end
139
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version)
1✔
140
    assert.are.equal(manifest.dependencies.foo.version, "1.3.4")
1✔
141
  end)
142

143
  it("prints download failure and continues", function()
2✔
144
    local manifest = {
1✔
145
      dependencies = {
1✔
146
        foo = "https://example.com/foo.lua",
1✔
147
        bar = {
1✔
148
          url = "https://example.com/bar.lua",
1✔
149
        },
1✔
150
      },
1✔
151
    }
152
    local function load()
153
      return manifest
1✔
154
    end
155
    local function save(_) -- luacheck: ignore
156
    end
157
    local ensure_lib_dir = function() end
2✔
158
    local utils = {
1✔
159
      downloader = {
1✔
160
        download = function(url, _)
161
          if url:find("foo") then
2✔
162
            return false, "network fail"
1✔
163
          end
164
          return true
1✔
165
        end,
166
      },
1✔
167
    }
168
    local resolve_latest_version = function(_)
169
      return "2.0.0"
2✔
170
    end
171
    local printed = {}
1✔
172
    local printer = function(...)
173
      local args = { ... }
2✔
174
      for i = 1, #args do
4✔
175
        args[i] = tostring(args[i])
2✔
176
      end
177
      table.insert(printed, table.concat(args, " "))
2✔
178
    end
179
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version, nil, printer)
1✔
180
    local output = table.concat(printed, "\n")
1✔
181
    assert.is_true(output:find("Failed to download foo: network fail", 1, true) ~= nil)
1✔
182
    assert.are.equal(manifest.dependencies.foo.version, "2.0.0")
1✔
183
    assert.are.equal(manifest.dependencies.bar.version, "2.0.0")
1✔
184
  end)
185

186
  it("handles empty dependencies table", function()
2✔
187
    local manifest = { dependencies = {} }
1✔
188
    local function load()
189
      return manifest
1✔
190
    end
191
    local function save(_) -- luacheck: ignore
192
    end
193
    local ensure_lib_dir = function() end
2✔
194
    local utils = {
1✔
195
      downloader = {
1✔
196
        download = function()
197
          error("should not download if empty")
×
198
        end,
199
      },
1✔
200
    }
201
    local resolve_latest_version = function()
202
      error("should not resolve if empty")
×
203
    end
204
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version)
1✔
205
    assert.are.same({}, manifest.dependencies)
1✔
206
  end)
207

208
  it("converts string dependency to table and updates version", function()
2✔
209
    local manifest = { dependencies = { foo = "https://example.com/foo.lua" } }
1✔
210
    local function load()
211
      return manifest
1✔
212
    end
213
    local function save(_) -- luacheck: ignore
214
      manifest = _
1✔
215
    end
216
    local ensure_lib_dir = function() end
2✔
217
    local utils = { downloader = {
1✔
218
      download = function()
219
        return true
1✔
220
      end,
221
    } }
1✔
222
    local resolve_latest_version = function(_)
223
      return "9.9.9"
1✔
224
    end
225
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version)
1✔
226
    assert.are.same({ version = "9.9.9", url = "https://example.com/foo.lua" }, manifest.dependencies.foo)
1✔
227
  end)
228

229
  it("writes to default out_path if not specified in dependency table", function()
2✔
230
    local manifest = { dependencies = { foo = { version = "1.0.0", url = "https://example.com/foo.lua" } } }
1✔
231
    local function load()
232
      return manifest
1✔
233
    end
234
    local function save(_) -- luacheck: ignore
235
      manifest = _
1✔
236
    end
237
    local ensure_lib_dir = function() end
2✔
238
    local called_out_path
239
    local utils = {
1✔
240
      downloader = {
1✔
241
        download = function(_, out_path)
242
          called_out_path = out_path
1✔
243
          return true
1✔
244
        end,
245
      },
1✔
246
    }
247
    local resolve_latest_version = function(_)
248
      return "2.0.0"
1✔
249
    end
250
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version)
1✔
251
    assert.are.equal("src/lib/foo.lua", called_out_path)
1✔
252
  end)
253

254
  it("writes to specified out_path if present in dependency table", function()
2✔
255
    local manifest = {
1✔
256
      dependencies = { foo = { version = "1.0.0", url = "https://example.com/foo.lua", path = "custom/foo.lua" } },
1✔
257
    }
258
    local function load()
259
      return manifest
1✔
260
    end
261
    local function save(_) -- luacheck: ignore
262
      manifest = _
1✔
263
    end
264
    local ensure_lib_dir = function() end
2✔
265
    local called_out_path
266
    local utils = {
1✔
267
      downloader = {
1✔
268
        download = function(_, out_path)
269
          called_out_path = out_path
1✔
270
          return true
1✔
271
        end,
272
      },
1✔
273
    }
274
    local resolve_latest_version = function(_)
275
      return "2.0.0"
1✔
276
    end
277
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version)
1✔
278
    assert.are.equal("custom/foo.lua", called_out_path)
1✔
279
  end)
280

281
  it("prints update message when dependency is updated", function()
2✔
282
    local manifest = { dependencies = { foo = "https://example.com/foo.lua" } }
1✔
283
    local function load()
284
      return manifest
1✔
285
    end
286
    local function save(_) -- luacheck: ignore
287
      manifest = _
1✔
288
    end
289
    local ensure_lib_dir = function() end
2✔
290
    local utils = { downloader = {
1✔
291
      download = function()
292
        return true
1✔
293
      end,
294
    } }
1✔
295
    local resolve_latest_version = function(_)
296
      return "3.1.4"
1✔
297
    end
298
    local printed = {}
1✔
299
    local printer = function(...)
300
      local args = { ... }
1✔
301
      for i = 1, #args do
2✔
302
        args[i] = tostring(args[i])
1✔
303
      end
304
      table.insert(printed, table.concat(args, " "))
1✔
305
    end
306
    update_module.update_dependencies(load, save, ensure_lib_dir, utils, resolve_latest_version, nil, printer)
1✔
307
    local output = table.concat(printed, "\n")
1✔
308
    assert.is_true(output:find("Updating foo from", 1, true) ~= nil)
1✔
309
    assert.is_true(output:find("3.1.4", 1, true) ~= nil)
1✔
310
    assert.are.equal(manifest.dependencies.foo.version, "3.1.4")
1✔
311
  end)
312
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