This now works, but it makes assumptions about the directory structure which are hopefully standard:
"""
local_test(pkgname, [coverage])
Find and test a package in `LOAD_PATH`.
Useful when the package is outside `Pkg.dir()`.
"""
function local_test(pkgname; coverage::Bool=false)
module_path = Base.find_in_path(pkgname, nothing)
src_dir, module_file = splitdir(module_path)
dir = normpath(src_dir, "..")
test_path = joinpath(dir, "test", "runtests.jl")
@assert isfile(test_path) "Could not find $(test_path)"
Base.cd(dir) do
try
color = Base.have_color? "--color=yes" : "--color=no"
codecov = coverage? ["--code-coverage=user"] : ["--code-coverage=none"]
compilecache = "--compilecache=" * (Bool(Base.JLOptions().use_compilecache) ? "yes" : "no")
julia_exe = Base.julia_cmd()
run(`$julia_exe --check-bounds=yes $codecov $color $compilecache $test_path`)
info("$module_file tests passed")
catch err
Base.Pkg.Entry.warnbanner(err, label="[ ERROR: $module_file ]")
end
end
end