#!/usr/bin/env lua
local telescope = require 'telescope'
pcall(require, "luarocks.require")
pcall(require, "shake")
package.path = "./?.lua;" .. package.path
local function luacov_report()
local luacov = require("luacov.stats")
local data = luacov.load_stats()
if not data then
print("Could not load stats file "..luacov.statsfile..".")
print("Run your Lua program with -lluacov and then rerun luacov.")
os.exit(1)
end
local report = io.open("coverage.html", "w")
report:write('', "\n")
report:write([[
Luacov Code Coverage Report
]])
report:write("
Generated on ", os.date(), "
\n")
local names = {}
for filename, _ in pairs(data) do
table.insert(names, filename)
end
local escapes = {
[">"] = ">",
["<"] = "<"
}
local function escape_html(str)
return str:gsub("[<>]", function(a) return escapes[a] end)
end
table.sort(names)
for _, filename in ipairs(names) do
if string.match(filename, "/luacov/") or
string.match(filename, "/luarocks/") or
string.match(filename, "/tsc$")
then
break
end
local filedata = data[filename]
filename = string.gsub(filename, "^%./", "")
local file = io.open(filename, "r")
if file then
report:write("
", filename, "
", "\n")
report:write("
")
report:write("
", "\n")
local line_nr = 1
while true do
local line = file:read("*l")
if not line then break end
if line:match("^%s*%-%-") then -- Comment line
elseif line:match("^%s*$") -- Empty line
or line:match("^%s*end,?%s*$") -- Single "end"
or line:match("^%s*else%s*$") -- Single "else"
or line:match("^%s*{%s*$") -- Single opening brace
or line:match("^%s*}%s*$") -- Single closing brace
or line:match("^#!") -- Unix hash-bang magic line
then
report:write("", string.format("%-4d", line_nr), " ", escape_html(line), "
", "\n")
else
local hits = filedata[line_nr]
local class = "uncovered"
if not hits then hits = 0 end
if hits > 0 then class = "covered" end
report:write("- ", "
", string.format("%-4d", line_nr), string.format("%-4d", hits), " ", escape_html(line), "
", "\n")
end
line_nr = line_nr + 1
end
end
report:write("
", "\n")
report:write("
", "\n")
end
report:write([[
]])
end
local function getopt(arg, options)
local tab = {}
for k, v in ipairs(arg) do
if string.sub(v, 1, 2) == "--" then
local x = string.find(v, "=", 1, true)
if x then tab[string.sub(v, 3, x - 1)] = string.sub(v, x + 1)
else tab[string.sub(v, 3)] = true
end
elseif string.sub(v, 1, 1) == "-" then
local y = 2
local l = string.len(v)
local jopt
while (y <= l) do
jopt = string.sub(v, y, y)
if string.find(options, jopt, 1, true) then
if y < l then
tab[jopt] = string.sub(v, y + 1)
y = l
else
tab[jopt] = arg[k + 1]
end
else
tab[jopt] = true
end
y = y + 1
end
end
end
return tab
end
local callbacks = {}
local function progress_meter(t)
io.stdout:write(t.status_label)
end
local function show_usage()
local text = [[
Telescope
Usage: tsc [options] [files]
Description:
Telescope is a test framework for Lua that allows you to write tests
and specs in a TDD or BDD style.
Options:
-f, --full Show full report
-q, --quiet Show don't show any stack traces
-s --silent Don't show any output
-h,-? --help Show this text
-v --version Show version
-c --luacov Output a coverage file using Luacov (http://luacov.luaforge.net/)
--load=