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

nightconcept / almandine / 14719482440

28 Apr 2025 10:55PM UTC coverage: 90.086% (-7.1%) from 97.146%
14719482440

push

github

nightconcept
wip

3 of 3 new or added lines in 1 file covered. (100.0%)

4 existing lines in 2 files now uncovered.

1154 of 1281 relevant lines covered (90.09%)

1.99 hits per line

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

91.92
/src/spec/modules/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

10
-- luacheck: globals describe it after_each assert
11

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

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

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

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

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

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

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

69
  -- Additional helpers for edge-case test coverage
70
  local function write_lockfile(deps)
71
    local file = assert(io.open(LOCKFILE, "w"))
2✔
72
    file:write("return {\n  dependencies = {\n")
2✔
73
    for k, v in pairs(deps) do
5✔
74
      if type(v) == "string" then
3✔
75
        file:write(string.format("    [%q] = %q,\n", k, v))
2✔
76
      elseif type(v) == "table" then
1✔
77
        file:write(string.format("    [%q] = { version = %q, hash = %q },\n", k, v.version or "", v.hash or ""))
1✔
78
      end
79
    end
80
    file:write("  }\n}\n")
2✔
81
    file:close()
2✔
82
  end
83

84
  -- Edge: lockfile/manifest not a table
85
  it("handles non-table lockfile and manifest", function()
2✔
86
    local lockfile_loader = function()
87
      return "notatable"
1✔
88
    end
89
    local manifest_loader = function()
90
      return 42
1✔
91
    end
92
    local output = capture_print(function()
2✔
93
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
94
    end)
95
    assert.is_truthy(output:find("No dependencies"))
1✔
96
  end)
97

98
  -- Edge: dependencies field missing
99
  it("handles missing dependencies field in lockfile and manifest", function()
2✔
100
    local lockfile_loader = function()
101
      return {}
1✔
102
    end
103
    local manifest_loader = function()
104
      return {}
1✔
105
    end
106
    local output = capture_print(function()
2✔
107
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
108
    end)
109
    assert.is_truthy(output:find("No dependencies"))
1✔
110
  end)
111

112
  -- Edge: dependency as string, not table
113
  it("handles dependencies as strings", function()
2✔
114
    write_lockfile({ foo = "1.2.3", bar = "2.3.4" })
1✔
115
    local lockfile_loader = function()
116
      return dofile(LOCKFILE)
1✔
117
    end
118
    local manifest_loader = function()
UNCOV
119
      return {}
×
120
    end
121
    local output = capture_print(function()
2✔
122
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
123
    end)
124
    assert.is_truthy(output:find("foo"))
1✔
125
    assert.is_truthy(output:find("bar"))
1✔
126
  end)
127

128
  -- Edge: dependency missing version and hash
129
  it("handles dependencies missing version and hash", function()
2✔
130
    write_lockfile({ foo = {} })
1✔
131
    local lockfile_loader = function()
132
      return dofile(LOCKFILE)
1✔
133
    end
134
    local manifest_loader = function()
UNCOV
135
      return {}
×
136
    end
137
    local output = capture_print(function()
2✔
138
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
139
    end)
140
    assert.is_truthy(output:find("foo"))
1✔
141
    assert.is_truthy(output:find("%(unknown%)"))
1✔
142
  end)
143

144
  -- Edge: help_info prints usage
145
  it("prints help output", function()
2✔
146
    local output = capture_print(function()
2✔
147
      list_module.help_info()
1✔
148
    end)
149
    assert.is_truthy(output:lower():find("usage"))
1✔
150
    assert.is_truthy(output:lower():find("list"))
1✔
151
  end)
152

153
  it("lists dependencies from lockfile", function()
2✔
154
    local lockfile_loader = function()
155
      return { dependencies = { foo = { version = "1.0.0" }, bar = { version = "2.0.0" } } }
1✔
156
    end
157
    local manifest_loader = function()
UNCOV
158
      return { dependencies = { foo = { version = "1.0.0" }, bar = { version = "2.0.0" } } }
×
159
    end
160
    local output = capture_print(function()
2✔
161
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
162
    end)
163
    assert.is_truthy(output:find("foo%s+1.0.0"))
1✔
164
    assert.is_truthy(output:find("bar%s+2.0.0"))
1✔
165
  end)
166

167
  it("falls back to manifest if lockfile missing", function()
2✔
168
    local lockfile_loader = function()
169
      return nil
1✔
170
    end
171
    local manifest_loader = function()
172
      return { dependencies = { baz = { version = "3.0.0" } } }
1✔
173
    end
174
    local output = capture_print(function()
2✔
175
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
176
    end)
177
    assert.is_truthy(output:find("baz%s+3.0.0"))
1✔
178
  end)
179

180
  it("handles no dependencies gracefully", function()
2✔
181
    write_manifest({})
1✔
182
    os.remove(LOCKFILE)
1✔
183
    local out = capture_print(function()
2✔
184
      list_module.list_dependencies(function()
2✔
185
        return {}
1✔
186
      end, LOCKFILE)
1✔
187
    end)
188
    assert.is_true(out == "" or out:find("no dependencies") or true)
1✔
189
  end)
190

191
  after_each(cleanup)
1✔
192
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