Skip to content

Instantly share code, notes, and snippets.

@mpeterv
Created October 30, 2015 10:40
Show Gist options
  • Save mpeterv/2f579f508eb725295d50 to your computer and use it in GitHub Desktop.
Save mpeterv/2f579f508eb725295d50 to your computer and use it in GitHub Desktop.
#!/usr/bin/env lua
local LineScanner = require("luacov.reporter").LineScanner
local lfs = require "lfs"
local function annotate_file(path)
local lines = {}
local max_len = 0
for line in io.lines(path) do
table.insert(lines, line)
max_len = math.max(max_len, #line)
end
local f = assert(io.open(path, "w"))
local scanner = LineScanner:new()
for _, line in ipairs(lines) do
f:write(line, (" "):rep(max_len - #line))
local always_excluded, excluded_when_not_hit = scanner:consume(line)
local symbol = always_excluded and "-" or (excluded_when_not_hit and "?" or "+")
f:write(symbol, "\n")
end
f:close()
end
local function annotate_dir(dir)
for path in lfs.dir(dir) do
if path ~= "." and path ~= ".." then
path = dir .. "/" .. path
local mode = lfs.attributes(path, "mode")
if mode == "directory" then
annotate_dir(path)
elseif mode == "file" then
annotate_file(path)
else
return true
end
end
end
end
if not arg[1] or lfs.attributes(arg[1], "mode") ~= "directory" then
print("Pass a directory to recursively annotate as the first argument.")
else
annotate_dir(arg[1])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment