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

nightconcept / almandine / 14717913225

28 Apr 2025 09:08PM UTC coverage: 97.573% (+1.6%) from 95.996%
14717913225

push

github

nightconcept
test: Increase coverage for update command

106 of 107 new or added lines in 2 files covered. (99.07%)

3 existing lines in 2 files now uncovered.

1005 of 1030 relevant lines covered (97.57%)

2.15 hits per line

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

98.15
/src/modules/run.lua
1
--[[
2
  Run Command Module
3

4
  Provides logic for executing scripts defined in the `scripts` table of project.lua.
5
  Used by the main CLI entrypoint for the `run` command and for direct script invocation if unambiguous.
6
]]
7
--
8

9
---
10
-- Executes a script by name from the project manifest.
11
-- @param script_name [string] The key of the script in the scripts table.
12
-- @param manifest_loader [table] The manifest loader module.
13
-- @param executor [function] (optional) Function to execute the command, defaults to os.execute.
14
-- @return [boolean, string] True and output if successful, false and error message otherwise.
15
local function run_script(script_name, manifest_loader, executor)
16
  executor = executor or os.execute
6✔
17
  local manifest = manifest_loader.safe_load_project_manifest("project.lua")
6✔
18
  if not manifest then
6✔
19
    return false, "Failed to load project manifest."
1✔
20
  end
21
  local scripts = manifest.scripts or {}
5✔
22
  if not scripts or not scripts[script_name] then
5✔
23
    print(string.format("Script '%s' not found in project.lua.", script_name))
2✔
24
    return false, string.format("Script '%s' not found in project.lua.", script_name)
2✔
25
  end
26
  local script = scripts[script_name]
3✔
27
  local cmd = script.cmd or script
3✔
28
  local args = script.args or {}
3✔
29
  local command = cmd
3✔
30
  if #args > 0 then
3✔
31
    command = cmd .. " " .. table.concat(args, " ")
1✔
32
  end
33
  print(string.format("Running script '%s': %s", script_name, command))
3✔
34
  local ok, exit_reason, code = executor(command)
3✔
35
  if ok then
3✔
36
    print(string.format("Script '%s' completed successfully.", script_name))
2✔
37
    return true, nil
2✔
38
  else
39
    print(
2✔
40
      string.format("Script '%s' failed (reason: %s, code: %s)", script_name, tostring(exit_reason), tostring(code))
1✔
41
    )
42
    return false,
1✔
43
      string.format("Script '%s' failed (reason: %s, code: %s)", script_name, tostring(exit_reason), tostring(code))
1✔
44
  end
45
end
46

47
---
48
-- Determines if a string is a reserved command name.
49
-- @param name [string]
50
-- @return [boolean]
51
local function is_reserved_command(name)
52
  local reserved = {
2✔
53
    ["init"] = true,
2✔
54
    ["add"] = true,
2✔
55
    ["i"] = true,
2✔
56
    ["install"] = true,
2✔
57
    ["in"] = true,
2✔
58
    ["ins"] = true,
2✔
59
    ["remove"] = true,
2✔
60
    ["rm"] = true,
2✔
61
    ["uninstall"] = true,
2✔
62
    ["un"] = true,
2✔
63
    ["update"] = true,
2✔
64
    ["up"] = true,
2✔
65
    ["upgrade"] = true,
2✔
66
    ["run"] = true,
2✔
67
    ["list"] = true,
2✔
68
  }
69
  return reserved[name] == true
2✔
70
end
71

72
---
73
-- Finds a matching script if the name is unambiguous.
74
-- @param name [string] The candidate script name.
75
-- @param manifest_loader [table]
76
-- @return [string|nil] The script name if unambiguous, or nil.
77
local function get_unambiguous_script(name, manifest_loader)
78
  local manifest = manifest_loader.safe_load_project_manifest("project.lua")
2✔
79
  if not manifest or not manifest.scripts then
2✔
UNCOV
80
    return nil
×
81
  end
82
  if manifest.scripts[name] then
2✔
83
    return name
1✔
84
  end
85
  return nil
1✔
86
end
87

88
---
89
-- Prints usage/help information for the `run` command.
90
-- Usage: almd run <script_name>
91
-- Executes a script defined in project.lua.
92
local function help_info()
93
  print([[
2✔
94
Usage: almd run <script_name>
95

96
Executes a script defined in the `scripts` table of project.lua.
97
Example:
98
  almd run test
99
]])
1✔
100
end
101

102
return {
1✔
103
  run_script = run_script,
1✔
104
  is_reserved_command = is_reserved_command,
1✔
105
  get_unambiguous_script = get_unambiguous_script,
1✔
106
  help_info = help_info,
1✔
107
}
1✔
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