Path: blob/main/src/resources/pandoc/datadir/luacov_reporter.lua
12922 views
#!/usr/bin/env lua1local runner = require("luacov.runner")23local patterns = {}4local configfile5local reporter67local help_message = ([[8LuaCov %s - coverage analyzer for Lua scripts910Usage:11luacov [options] [pattern...]1213Launch your Lua programs with -lluacov to perform accounting.14Launch this script to generate a report from collected stats.15By default it reports on every Lua file encountered running your16script. To filter filenames, pass one or more Lua patterns matching17files to be included in the command line, or use a config.1819Options:20-c filename, --config filename2122Use a config file, .luacov by default. For details see23luacov.defaults module.2425-r name, --reporter name2627Use a custom reporter - a module in luacov.reporter.* namespace.2829-h, --help3031Show this help message and exit.3233Examples:34luacov foo/bar3536This will report only on modules in the foo/bar subtree.37]]):format(runner.version)3839-- pandoc doesn't support arg40arg = {}4142local function read_key(i)43if arg[i]:sub(1, 1) ~= "-" or #arg[i] == 1 then44return nil, arg[i], i + 145end4647if arg[i]:sub(2, 2) == "-" then48local key, value = arg[i]:match("^%-%-([^=]+)=(.*)$")49if key then50return key, value, i + 151else52return arg[i]:sub(3), arg[i + 1], i + 253end54else55local key = arg[i]:sub(2, 2)56local value = arg[i]:sub(3)57if #value == 0 then58i = i + 159value = arg[i]60elseif value:sub(1, 1) == "=" then61value = value:sub(2)62end63return key, value, i + 164end65end6667local function norm_pat(p)68return (p:gsub("\\", "/"):gsub("%.lua$", ""))69end7071local i = 172while arg[i] do73local key, value74key, value, i = read_key(i)75if key then76if (key == "h") or (key == "help") then77print(help_message)78os.exit(0)79elseif (key == "c") or (key == "config") then80configfile = value81elseif (key == "r") or (key == "reporter") then82reporter = value83end84else85table.insert(patterns, norm_pat(value))86end87end8889-- will load configfile specified, or defaults otherwise90local configuration = runner.load_config(configfile)9192configuration.include = configuration.include or {}93configuration.exclude = configuration.exclude or {}9495-- add elements specified on commandline to config96for _, patt in ipairs(patterns) do97table.insert(configuration.include, patt)98end99100configuration.reporter = reporter or configuration.reporter101runner.run_report(configuration)102103104