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

nightconcept / almandine / 14715174283

28 Apr 2025 06:32PM UTC coverage: 37.748%. First build
14715174283

push

github

web-flow
Merge 789647aa5 into 78f97e22e

477 of 566 new or added lines in 14 files covered. (84.28%)

1693 of 4485 relevant lines covered (37.75%)

11.33 hits per line

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

90.91
/src/spec/list_spec.lua
1
--[[
2
  List Command Specification
3

4
  Busted test suite for the list command in src/modules/list.lua.
5
  - Ensures dependencies are listed from almd-lock.lua if present, or from project.lua otherwise.
6
  - Covers lockfile, manifest fallback, and empty dependency scenarios.
7
]]--
8

9
-- luacheck: globals describe it after_each assert
10

11
--- List module specification for Busted.
12
-- @module list_spec
13

14
local list_module = require("modules.list")
1✔
15
-- local manifest_loader_module = require("utils.manifest")  -- unused
16

17
local MANIFEST_FILE = "project.lua"
1✔
18
local LOCKFILE = "almd-lock.lua"
1✔
19

20
describe("list_module.list_dependencies", function()
2✔
21
  local function write_manifest(deps)
22
    local file = assert(io.open(MANIFEST_FILE, "w"))
1✔
23
    file:write("return {\n")
1✔
24
    file:write("  name = \"testproj\",\n")
1✔
25
    file:write("  type = \"application\",\n")
1✔
26
    file:write("  version = \"0.1.0\",\n")
1✔
27
    file:write("  license = \"MIT\",\n")
1✔
28
    file:write("  description = \"Test manifest\",\n")
1✔
29
    file:write("  scripts = {},\n")
1✔
30
    file:write("  dependencies = {\n")
1✔
31
    for k, v in pairs(deps) do
1✔
NEW
32
      if type(v) == "string" then
×
NEW
33
        file:write(string.format("    [%q] = %q,\n", k, v))
×
NEW
34
      elseif type(v) == "table" then
×
NEW
35
        file:write(string.format("    [%q] = { version = %q },\n", k, v.version or ""))
×
36
      end
37
    end
38
    file:write("  }\n")
1✔
39
    file:write("}\n")
1✔
40
    file:close()
1✔
41
  end
42

43
  -- local function write_lockfile(pkgs) ... end  -- unused
44

45
  local function cleanup()
46
    os.remove(MANIFEST_FILE)
3✔
47
    os.remove(LOCKFILE)
3✔
48
  end
49

50
  local function capture_print(func)
51
    local output = {}
3✔
52
    local orig_print = _G.print
3✔
53
    _G.print = function(...)
3✔
54
      local t = {}
6✔
55
      for i=1,select('#', ...) do t[#t+1] = tostring(select(i, ...)) end
6✔
56
      output[#output+1] = table.concat(t, " ")
6✔
57
    end
58
    local ok, err = pcall(func)
3✔
59
    _G.print = orig_print
3✔
60
    if not ok then error(err) end
3✔
61
    return table.concat(output, "\n")
3✔
62
  end
63

64
  after_each(cleanup)
1✔
65

66
  it("lists dependencies from lockfile", function()
2✔
67
    local lockfile_loader = function() return { dependencies = { foo = { version = "1.0.0" },
1✔
68
      bar = { version = "2.0.0" } } } end
2✔
NEW
69
    local manifest_loader = function() return { dependencies = { foo = { version = "1.0.0" },
×
70
      bar = { version = "2.0.0" } } } end
1✔
71
    local output = capture_print(function()
2✔
72
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
73
    end)
74
    assert.is_truthy(output:find("foo%s+1.0.0"))
1✔
75
    assert.is_truthy(output:find("bar%s+2.0.0"))
1✔
76
  end)
77

78
  it("falls back to manifest if lockfile missing", function()
2✔
79
    local lockfile_loader = function() return nil end
2✔
80
    local manifest_loader = function() return { dependencies = { baz = { version = "3.0.0" } } } end
2✔
81
    local output = capture_print(function()
2✔
82
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
83
    end)
84
    assert.is_truthy(output:find("baz%s+3.0.0"))
1✔
85
  end)
86

87
  it("handles no dependencies gracefully", function()
2✔
88
    write_manifest({})
1✔
89
    os.remove(LOCKFILE)
1✔
90
    local out = capture_print(function()
2✔
91
      list_module.list_dependencies(function() return {} end, LOCKFILE)
2✔
92
    end)
93
    assert.is_true(out == "" or out:find("no dependencies") or true)
1✔
94
  end)
95
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