• 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

98.48
/src/spec/modules/remove_spec.lua
1
--[[
2
  Remove Command Specification
3

4
  Busted test suite for the remove command in src/modules/remove.lua.
5
  - Verifies dependencies are removed from project.lua and files are deleted.
6
  - Handles both existing and non-existent dependencies.
7
]]
8
--
9

10
-- luacheck: globals describe it after_each assert
11

12
--- Remove module specification for Busted.
13
-- @module remove_spec
14

15
local remove_module = require("modules.remove")
1✔
16
local manifest_loader = require("utils.manifest")
1✔
17

18
local TEST_DEP_NAME = "testdep"
1✔
19
local TEST_DEP_PATH = "src/lib/testdep.lua"
1✔
20
local MANIFEST_FILE = "project.lua"
1✔
21

22
describe("remove_module.remove_dependency", function()
2✔
23
  local function write_manifest(deps)
24
    local file = assert(io.open(MANIFEST_FILE, "w"))
10✔
25
    file:write("return {\n")
10✔
26
    file:write('  name = "testproj",\n')
10✔
27
    file:write('  type = "application",\n')
10✔
28
    file:write('  version = "0.1.0",\n')
10✔
29
    file:write('  license = "MIT",\n')
10✔
30
    file:write('  description = "Test manifest",\n')
10✔
31
    file:write("  scripts = {},\n")
10✔
32
    file:write("  dependencies = {\n")
10✔
33
    for k, v in pairs(deps) do
15✔
34
      if type(v) == "table" then
5✔
35
        file:write(string.format("    [%q] = {", k))
1✔
36
        for tkey, tval in pairs(v) do
3✔
37
          file:write(string.format(" %s = %q,", tkey, tval))
2✔
38
        end
39
        file:write(" },\n")
1✔
40
      else
41
        file:write(string.format("    [%q] = %q,\n", k, v))
4✔
42
      end
43
    end
44
    file:write("  }\n")
10✔
45
    file:write("}\n")
10✔
46
    file:close()
10✔
47
  end
48

49
  local function file_exists(path)
50
    local f = io.open(path, "r")
5✔
51
    if f then
5✔
52
      f:close()
2✔
53
      return true
2✔
54
    end
55
    return false
3✔
56
  end
57

58
  local function cleanup()
59
    os.remove(MANIFEST_FILE)
8✔
60
    os.remove(TEST_DEP_PATH)
8✔
61
  end
62

63
  after_each(cleanup)
1✔
64

65
  it("removes existing dependency and deletes file", function()
2✔
66
    write_manifest({ [TEST_DEP_NAME] = "dummy_source" })
1✔
67
    os.execute("mkdir -p src/lib >nul 2>&1 || true")
1✔
68
    local f = assert(io.open(TEST_DEP_PATH, "w"))
1✔
69
    f:write("dummy content")
1✔
70
    f:close()
1✔
71
    assert.is_true(file_exists(TEST_DEP_PATH))
1✔
72
    local function save_manifest(m)
73
      m.name = "testproj"
1✔
74
      m.type = "application"
1✔
75
      m.version = "0.1.0"
1✔
76
      m.license = "MIT"
1✔
77
      m.description = "Test manifest"
1✔
78
      m.scripts = m.scripts or {}
1✔
79
      local deps = m.dependencies or {}
1✔
80
      write_manifest(deps)
1✔
81
      return true, nil
1✔
82
    end
83
    remove_module.remove_dependency(TEST_DEP_NAME, manifest_loader.safe_load_project_manifest, save_manifest)
1✔
84
    local manifest = manifest_loader.safe_load_project_manifest()
1✔
85
    -- TODO: Check for nil value before using result
86
    assert.is_not_nil(manifest)
1✔
87
    assert.is_nil((manifest.dependencies or {})[TEST_DEP_NAME])
1✔
88
    assert.is_false(file_exists(TEST_DEP_PATH))
1✔
89
  end)
90

91
  it("does not error when removing nonexistent dependency", function()
2✔
92
    write_manifest({})
1✔
93
    assert.has_no.errors(function()
2✔
94
      remove_module.remove_dependency("doesnotexist", manifest_loader.safe_load_project_manifest, function(m)
2✔
NEW
95
        return write_manifest(m.dependencies or {})
×
96
      end)
97
    end)
98
  end)
99

100
  it("prints error when manifest fails to load", function()
2✔
101
    local printed = {}
1✔
102
    local stub = require("luassert.stub")
1✔
103
    local print_stub = stub(_G, "print", function(msg)
2✔
104
      table.insert(printed, tostring(msg))
1✔
105
    end)
106
    local function load_fail()
107
      return nil, "load error!"
1✔
108
    end
109
    local save_manifest = function()
NEW
110
      error("should not be called")
×
111
    end
112
    remove_module.remove_dependency(TEST_DEP_NAME, load_fail, save_manifest)
1✔
113
    print_stub:revert()
1✔
114
    assert.is_not_nil(table.concat(printed, "\n"):match("load error!"))
1✔
115
  end)
116
  it("prints error when save_manifest fails", function()
2✔
117
    write_manifest({ [TEST_DEP_NAME] = "dummy_source" })
1✔
118
    os.execute("mkdir -p src/lib >nul 2>&1 || true")
1✔
119
    local f = assert(io.open(TEST_DEP_PATH, "w"))
1✔
120
    f:write("dummy content")
1✔
121
    f:close()
1✔
122
    local printed = {}
1✔
123
    local stub = require("luassert.stub")
1✔
124
    local print_stub = stub(_G, "print", function(msg)
2✔
125
      table.insert(printed, tostring(msg))
1✔
126
    end)
127
    local function save_fail()
128
      return false, "save failed!"
1✔
129
    end
130
    remove_module.remove_dependency(TEST_DEP_NAME, manifest_loader.safe_load_project_manifest, save_fail)
1✔
131
    print_stub:revert()
1✔
132
    assert.is_not_nil(table.concat(printed, "\n"):match("save failed!"))
1✔
133
    assert.is_true(file_exists(TEST_DEP_PATH)) -- file should not be deleted
1✔
134
  end)
135
  it("removes dependency with custom .path", function()
2✔
136
    local dep_path = "src/lib/customdep.lua"
1✔
137
    write_manifest({ customdep = { url = "url", path = dep_path } })
1✔
138
    os.execute("mkdir -p src/lib >nul 2>&1 || true")
1✔
139
    local f = assert(io.open(dep_path, "w"))
1✔
140
    f:write("dummy content")
1✔
141
    f:close()
1✔
142
    local function save_manifest(m)
143
      write_manifest(m.dependencies or {})
1✔
144
      return true, nil
1✔
145
    end
146
    remove_module.remove_dependency("customdep", manifest_loader.safe_load_project_manifest, save_manifest)
1✔
147
    assert.is_false(file_exists(dep_path))
1✔
148
    local manifest = manifest_loader.safe_load_project_manifest()
1✔
149
    assert.is_nil((manifest.dependencies or {}).customdep)
1✔
150
  end)
151
  it("removes dependency using _G.dependency_add_test_paths", function()
2✔
152
    _G.dependency_add_test_paths = { foo = "src/lib/foo_testpath.lua" }
1✔
153
    write_manifest({ foo = "url" })
1✔
154
    os.execute("mkdir -p src/lib >nul 2>&1 || true")
1✔
155
    local f = assert(io.open("src/lib/foo_testpath.lua", "w"))
1✔
156
    f:write("dummy content")
1✔
157
    f:close()
1✔
158
    local function save_manifest(m)
159
      write_manifest(m.dependencies or {})
1✔
160
      return true, nil
1✔
161
    end
162
    remove_module.remove_dependency("foo", manifest_loader.safe_load_project_manifest, save_manifest)
1✔
163
    assert.is_false(file_exists("src/lib/foo_testpath.lua"))
1✔
164
    local manifest = manifest_loader.safe_load_project_manifest()
1✔
165
    assert.is_nil((manifest.dependencies or {}).foo)
1✔
166
    _G.dependency_add_test_paths = nil
1✔
167
  end)
168
  it("warns if file cannot be deleted", function()
2✔
169
    write_manifest({ bar = "url" })
1✔
170
    local printed = {}
1✔
171
    local stub = require("luassert.stub")
1✔
172
    local print_stub = stub(_G, "print", function(msg)
2✔
173
      table.insert(printed, tostring(msg))
2✔
174
    end)
175
    local function save_manifest(m)
176
      write_manifest(m.dependencies or {})
1✔
177
      return true, nil
1✔
178
    end
179
    -- do not create the file
180
    remove_module.remove_dependency("bar", manifest_loader.safe_load_project_manifest, save_manifest)
1✔
181
    print_stub:revert()
1✔
182
    local output = table.concat(printed, "\n")
1✔
183
    assert.is_not_nil(output:match("Warning: Could not delete file"))
1✔
184
  end)
185
  it("prints help_info output", function()
2✔
186
    local printed = {}
1✔
187
    local stub = require("luassert.stub")
1✔
188
    local print_stub = stub(_G, "print", function(msg)
2✔
189
      table.insert(printed, tostring(msg))
1✔
190
    end)
191
    assert.has_no.errors(function()
2✔
192
      remove_module.help_info()
1✔
193
    end)
194
    print_stub:revert()
1✔
195
    assert.is_not_nil(table.concat(printed, "\n"):match("Usage: almd remove"))
1✔
196
  end)
197
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