Skip to content

Commit 88dbf75

Browse files
settings for including/excluding mods
1 parent 41587c4 commit 88dbf75

File tree

4 files changed

+87
-15
lines changed

4 files changed

+87
-15
lines changed

control.lua

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ coveragedata = {
1919
2020
--]]
2121

22-
local function callAll(funcname,...)
22+
local function callAll(mods,funcname,...)
2323
local results = {}
24-
for name,version in pairs(game.active_mods) do
24+
for name,version in pairs(mods) do
2525
local remotename = "__coverage_" .. name
2626
if remote.interfaces[remotename] then
2727
results[name] = remote.call(remotename,funcname,...)
@@ -33,23 +33,56 @@ local function callAll(funcname,...)
3333
return results
3434
end
3535

36+
local active_mods = nil
37+
local function getActiveMods()
38+
if active_mods then return active_mods end
39+
local json = game.json_to_table(settings.global["coverage-include-modstates"].value)
40+
if json then
41+
active_mods = {}
42+
for _,modname in pairs(json) do
43+
active_mods[modname] = game.active_mods[modname]
44+
end
45+
else
46+
active_mods = game.active_mods
47+
end
48+
return active_mods
49+
end
50+
51+
52+
local function getExcludeMods(excludetype)
53+
local json = game.json_to_table(settings.global[excludetype].value)
54+
local nopathmods = {}
55+
if json then
56+
for _,modname in pairs(json) do
57+
nopathmods[modname] = true
58+
end
59+
else
60+
nopathmods = game.active_mods
61+
end
62+
return nopathmods
63+
end
64+
3665
local runningtestname = nil
3766
local function start(testname)
3867
runningtestname = testname
39-
callAll("start",testname)
68+
callAll(getActiveMods(),"start",testname)
4069
end
4170
local function stop()
4271
runningtestname = nil
43-
callAll("stop")
72+
callAll(getActiveMods(),"stop")
4473
end
45-
-- These mod names will remain in __modname__ format, rather than being translated
46-
local nopathmods = {level=true,base=true,core=true}
47-
-- These mods will be omitted from output entirely
48-
local ignoremods = {coverage = true}
74+
4975
local function report()
5076
if runningtestname then stop() end
51-
local moddumps = callAll("dump")
52-
77+
-- These mod names will remain in __modname__ format, rather than being translated
78+
local nopathmods = getExcludeMods("coverage-nopath-mods")
79+
nopathmods.level = true
80+
nopathmods.base = true
81+
nopathmods.core = true
82+
-- These mods will be omitted from output entirely
83+
local ignoremods = getExcludeMods("coverage-exclude-modfiles")
84+
--dump everything anyone collected, will just be empty for disabled mods unless startup collection
85+
local moddumps = callAll(game.active_mods,"dump")
5386
local outlines = {}
5487
for dumpname,dump in pairs(moddumps) do
5588
for testname,files in pairs(dump.tests) do
@@ -104,11 +137,17 @@ remote.add_interface("coverage",{
104137
})
105138

106139
script.on_init(function()
107-
if runningtestname == "startup" then stop() end
140+
if runningtestname == "startup" then
141+
runningtestname = nil
142+
callAll(game.active_mods,"stop")
143+
end
108144
end)
109145

110146
script.on_load(function()
111-
if runningtestname == "startup" then stop() end
147+
if runningtestname == "startup" then
148+
runningtestname = nil
149+
callAll(game.active_mods,"stop")
150+
end
112151
end)
113152

114153
commands.add_command("startCoverage", "Starts coverage counting",

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coverage",
3-
"version": "0.17.0",
3+
"version": "0.17.1",
44
"factorio_version": "0.17",
55
"title": "Lua Coverage Tester",
66
"author": "justarandomgeek",

locale/en/en.cfg

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
[mod-setting-name]
2-
coverage-startup=Enable Line Counting during control.lua initialization
2+
coverage-startup=Enable Line Counting during control.lua initialization
3+
coverage-include-modstates=Mod states to include in coverage counting
4+
coverage-exclude-modfiles=Mods to exclude file output counts for
5+
coverage-nopath-mods=Mod to skip path translation for
6+
7+
[mod-setting-description]
8+
coverage-startup=A coverage test named "startup" will be started as soon as the coverage tester is required into a lua state, and stopped in on_init/on_load.
9+
coverage-include-modstates=For all tests except "startup", only enable the coverage tester in these mods. If blank, the tester will be enabled in all mods. "level" is always included if supported.
10+
coverage-exclude-modfiles=Files in these mods will be excluded from lcov output, in any modstate.
11+
coverage-nopath-mods=These mods will be output in "__modname__" format. "level", "base" and "core" will always be on this list.

settings.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ data:extend{
44
name = "coverage-startup",
55
setting_type = "runtime-global",
66
default_value = false,
7-
order="coverage-startup"
7+
order="coverage-10-startup",
8+
},
9+
{
10+
type = "string-setting",
11+
name = "coverage-include-modstates",
12+
setting_type = "runtime-global",
13+
default_value = "",
14+
allow_blank = true,
15+
order="coverage-20-include-modstates",
16+
},
17+
{
18+
type = "string-setting",
19+
name = "coverage-exclude-modfiles",
20+
setting_type = "runtime-global",
21+
default_value = "[\"coverage\"]",
22+
allow_blank = true,
23+
order="coverage-30-exclude-modfiles",
24+
},
25+
{
26+
type = "string-setting",
27+
name = "coverage-nopath-mods",
28+
setting_type = "runtime-global",
29+
default_value = "",
30+
allow_blank = true,
31+
order="coverage-40-nopath-mods",
832
},
933
}

0 commit comments

Comments
 (0)