Skip to content

Commit

Permalink
Upgrade to luacov master
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed Aug 30, 2015
1 parent d942d42 commit c5ba158
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
6 changes: 2 additions & 4 deletions .travis_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ set -e
luarocks install dkjson --deps-mode=none
luarocks install lanes

mkdir busted
wget -O - https://api.github.com/repos/Olivine-Labs/busted/tarball/master | tar xz -C busted --strip-components=1
git clone --depth=1 https://github.com/Olivine-Labs/busted
cd busted
luarocks make busted-scm-0.rockspec
cd ..

mkdir luacov
wget -O - https://api.github.com/repos/mpeterv/luacov/tarball/simplify-lines | tar xz -C luacov --strip-components=1
git clone --depth=1 https://github.com/keplerproject/luacov
cd luacov
luarocks make rockspecs/luacov-scm-1.rockspec
cd ..
45 changes: 10 additions & 35 deletions spec/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,16 @@ local function antipath(path)
return (".."..dir_sep):rep(level)
end

-- Try to load a lua module from `file_path` when run from `loc_path`.
local function try_load(loc_path, file_path)
local real_path = antipath(loc_path)..file_path
local fd = io.open(real_path, "rb")

if not fd then
return
end

local src = fd:read("*a")
fd:close()
local func, err = (loadstring or load)(src, "@"..file_path) -- luacheck: compat
return err or func
end

-- Return a package searcher which, when run from `loc_path`,
-- loads lua libraries from `lib_path`.
function helper.prefix_searcher(loc_path, lib_path)
return function(package_name)
local package_path = lib_path..package_name:gsub("%.", dir_sep)
return try_load(loc_path, package_path..".lua") or
try_load(loc_path, package_path..dir_sep.."init.lua"), package_name
end
end

function helper.luacov_config(prefix)
return {
statsfile = prefix.."luacov.stats.out",
reportfile = prefix.."luacov.report.out",
deletestats = false,
runreport = false,
include = {"luacheck/[^/]+$"},
exclude = {}
modules = {
luacheck = "src/luacheck/init.lua",
["luacheck.*"] = "src"
},
exclude = {
"bin/luacheck$"
}
}
end

Expand All @@ -52,11 +29,9 @@ function helper.luacheck_command(loc_path)
local prefix = antipath(loc_path)
local cmd = ("cd %s && lua"):format(loc_path)

-- Extend package.path to allow loading this helper.
cmd = cmd..(" -e 'package.path=[[%s?.lua;]]..package.path'"):format(prefix)
-- Add searcher for luacheck modules.
cmd = cmd..(" -e 'table.insert(package.loaders or package.searchers,1,"..
"require[[spec.helper]].prefix_searcher([[%s]],[[./src%s]]))'"):format(loc_path, dir_sep)
-- Extend package.path to allow loading this helper and luacheck modules.
cmd = cmd..(" -e 'package.path=[[%s?.lua;%ssrc%s?.lua;%ssrc%s?%sinit.lua;]]..package.path'"):format(
prefix, prefix, dir_sep, prefix, dir_sep, dir_sep)

if luacov then
-- Launch luacov.
Expand Down

0 comments on commit c5ba158

Please sign in to comment.