Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/resources/pandoc/datadir/luacov_reporter.lua
12922 views
1
#!/usr/bin/env lua
2
local runner = require("luacov.runner")
3
4
local patterns = {}
5
local configfile
6
local reporter
7
8
local help_message = ([[
9
LuaCov %s - coverage analyzer for Lua scripts
10
11
Usage:
12
luacov [options] [pattern...]
13
14
Launch your Lua programs with -lluacov to perform accounting.
15
Launch this script to generate a report from collected stats.
16
By default it reports on every Lua file encountered running your
17
script. To filter filenames, pass one or more Lua patterns matching
18
files to be included in the command line, or use a config.
19
20
Options:
21
-c filename, --config filename
22
23
Use a config file, .luacov by default. For details see
24
luacov.defaults module.
25
26
-r name, --reporter name
27
28
Use a custom reporter - a module in luacov.reporter.* namespace.
29
30
-h, --help
31
32
Show this help message and exit.
33
34
Examples:
35
luacov foo/bar
36
37
This will report only on modules in the foo/bar subtree.
38
]]):format(runner.version)
39
40
-- pandoc doesn't support arg
41
arg = {}
42
43
local function read_key(i)
44
if arg[i]:sub(1, 1) ~= "-" or #arg[i] == 1 then
45
return nil, arg[i], i + 1
46
end
47
48
if arg[i]:sub(2, 2) == "-" then
49
local key, value = arg[i]:match("^%-%-([^=]+)=(.*)$")
50
if key then
51
return key, value, i + 1
52
else
53
return arg[i]:sub(3), arg[i + 1], i + 2
54
end
55
else
56
local key = arg[i]:sub(2, 2)
57
local value = arg[i]:sub(3)
58
if #value == 0 then
59
i = i + 1
60
value = arg[i]
61
elseif value:sub(1, 1) == "=" then
62
value = value:sub(2)
63
end
64
return key, value, i + 1
65
end
66
end
67
68
local function norm_pat(p)
69
return (p:gsub("\\", "/"):gsub("%.lua$", ""))
70
end
71
72
local i = 1
73
while arg[i] do
74
local key, value
75
key, value, i = read_key(i)
76
if key then
77
if (key == "h") or (key == "help") then
78
print(help_message)
79
os.exit(0)
80
elseif (key == "c") or (key == "config") then
81
configfile = value
82
elseif (key == "r") or (key == "reporter") then
83
reporter = value
84
end
85
else
86
table.insert(patterns, norm_pat(value))
87
end
88
end
89
90
-- will load configfile specified, or defaults otherwise
91
local configuration = runner.load_config(configfile)
92
93
configuration.include = configuration.include or {}
94
configuration.exclude = configuration.exclude or {}
95
96
-- add elements specified on commandline to config
97
for _, patt in ipairs(patterns) do
98
table.insert(configuration.include, patt)
99
end
100
101
configuration.reporter = reporter or configuration.reporter
102
runner.run_report(configuration)
103
104