From c5ba1580b6a10807567a703128730566e1a10a6d Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 27 Aug 2015 11:53:24 +0300 Subject: [PATCH] Upgrade to luacov master --- .travis_deps.sh | 6 ++---- spec/helper.lua | 45 ++++++++++----------------------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/.travis_deps.sh b/.travis_deps.sh index 3a40d2c9..a0e05967 100644 --- a/.travis_deps.sh +++ b/.travis_deps.sh @@ -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 .. diff --git a/spec/helper.lua b/spec/helper.lua index af39ca34..17c75f88 100644 --- a/spec/helper.lua +++ b/spec/helper.lua @@ -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 @@ -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.