Skip to content

Commit

Permalink
Merge cc32644 into c71f207
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Jan 24, 2020
2 parents c71f207 + cc32644 commit 603103b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
21 changes: 13 additions & 8 deletions src/CoverageTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module CoverageTools
coverage::Vector{CovCount}
end

include("lcov.jl")

"""
get_summary(fcs)
Expand Down Expand Up @@ -244,29 +246,33 @@ module CoverageTools
process_file(filename) = process_file(filename, splitdir(filename)[1])

"""
process_folder(folder="src") -> Vector{FileCoverage}
process_folder(folder="src"; jl = true, info = true) -> Vector{FileCoverage}
Process the contents of a folder of Julia source code to collect coverage
statistics for all the files contained within. Will recursively traverse
child folders. Default folder is "src", which is useful for the primary case
where CoverageTools is called from the root directory of a package.
where CoverageTools is called from the root directory of a package. By
default, will process both `.jl` and `.info` files.
"""
function process_folder(folder="src")
@info "CoverageTools.process_folder: Searching $folder for .jl files..."
function process_folder(folder="src"; jl = true, info = true)
jl && @info "CoverageTools.process_folder: Searching $folder for .jl files..."
info && @info "CoverageTools.process_folder: Searching $folder for .info files..."
source_files = FileCoverage[]
files = readdir(folder)
for file in files
fullfile = joinpath(folder, file)
if isfile(fullfile)
# Is it a Julia file?
if splitext(fullfile)[2] == ".jl"
if jl && splitext(fullfile)[2] == ".jl"
push!(source_files, process_file(fullfile, folder))
elseif info && splitext(fullfile)[2] == ".info"
append!(source_files, LCOV.readfile(fullfile))
else
@debug "CoverageTools.process_folder: Skipping $file, not a .jl file"
@debug "CoverageTools.process_folder: Skipping $file, not a .jl or .info file"
end
elseif isdir(fullfile)
# If it is a folder, recursively traverse
append!(source_files, process_folder(fullfile))
append!(source_files, process_folder(fullfile; jl = jl, info = info))
end
end
return source_files
Expand Down Expand Up @@ -323,7 +329,6 @@ module CoverageTools
end
end

include("lcov.jl")
include("memalloc.jl")
include("parser.jl")
end
28 changes: 1 addition & 27 deletions src/lcov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,6 @@ function readfile(infofile::AbstractString)
return source_files
end

"""
readfolder(folder) -> Vector{FileCoverage}
Process the contents of a folder of LCOV files to collect coverage statistics.
Will recursively traverse child folders.
Post-process with `merge_coverage_counts(coverages)` to combine duplicates.
"""
function readfolder(folder)
@info """CoverageTools.LCOV.readfolder: Searching $folder for .info files..."""
source_files = FileCoverage[]
files = readdir(folder)
for file in files
fullfile = joinpath(folder, file)
if isfile(fullfile)
# Is it a tracefile?
if endswith(fullfile, ".info")
append!(source_files, readfile(fullfile))
else
@debug "CoverageTools.LCOV.readfolder: Skipping $file, not a .info file"
end
elseif isdir(fullfile)
# If it is a folder, recursively traverse
append!(source_files, readfolder(fullfile))
end
end
return source_files
end
@deprecate readfolder(folder) process_folder(folder; jl = false)

end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end
rm(lcov)

# test that reading the LCOV file gives the same data
lcov = LCOV.readfolder(datadir)
lcov = process_folder(datadir; jl = false)
@test length(lcov) == 1
r2 = lcov[1]
r2_filename = r2.filename
Expand Down Expand Up @@ -127,7 +127,7 @@ end

covtarget = (sum(x->x !== nothing && x > 0, target), sum(x->x !== nothing, target))
@test get_summary(r) == covtarget
@test get_summary(process_folder(datadir)) == (98, 106)
@test get_summary(process_folder(datadir; info = false)) == (98, 106)

r_disabled = withenv("DISABLE_AMEND_COVERAGE_FROM_SRC" => "yes") do
process_file(srcname, datadir)
Expand Down

0 comments on commit 603103b

Please sign in to comment.