Created
October 30, 2015 10:40
-
-
Save mpeterv/2f579f508eb725295d50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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