• 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

89.47
/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✔
NEW
33
      if type(v) == "string" then
×
NEW
34
        file:write(string.format("    [%q] = %q,\n", k, v))
×
NEW
35
      elseif type(v) == "table" then
×
NEW
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)
3✔
48
    os.remove(LOCKFILE)
3✔
49
  end
50

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

69
  after_each(cleanup)
1✔
70

71
  it("lists dependencies from lockfile", function()
2✔
72
    local lockfile_loader = function()
73
      return { dependencies = { foo = { version = "1.0.0" }, bar = { version = "2.0.0" } } }
1✔
74
    end
75
    local manifest_loader = function()
NEW
76
      return { dependencies = { foo = { version = "1.0.0" }, bar = { version = "2.0.0" } } }
×
77
    end
78
    local output = capture_print(function()
2✔
79
      list_module.list_dependencies(manifest_loader, lockfile_loader)
1✔
80
    end)
81
    assert.is_truthy(output:find("foo%s+1.0.0"))
1✔
82
    assert.is_truthy(output:find("bar%s+2.0.0"))
1✔
83
  end)
84

85
  it("falls back to manifest if lockfile missing", function()
2✔
86
    local lockfile_loader = function()
87
      return nil
1✔
88
    end
89
    local manifest_loader = function()
90
      return { dependencies = { baz = { version = "3.0.0" } } }
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("baz%s+3.0.0"))
1✔
96
  end)
97

98
  it("handles no dependencies gracefully", function()
2✔
99
    write_manifest({})
1✔
100
    os.remove(LOCKFILE)
1✔
101
    local out = capture_print(function()
2✔
102
      list_module.list_dependencies(function()
2✔
103
        return {}
1✔
104
      end, LOCKFILE)
1✔
105
    end)
106
    assert.is_true(out == "" or out:find("no dependencies") or true)
1✔
107
  end)
108
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