在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:JuliaCI/Coverage.jl开源软件地址:https://github.com/JuliaCI/Coverage.jl开源编程语言:Julia 100.0%开源软件介绍:Coverage.jl"Take Julia code coverage and memory allocation results, do useful things with them" Code coverage: Julia can track how many times, if any, each line of your code is run. This is useful for measuring how much of your code base your tests actually test, and can reveal the parts of your code that are not tested and might be hiding a bug. You can use Coverage.jl to summarize the results of this tracking, or to send them to a service like Coveralls.io or Codecov.io. Memory allocation: Julia can track how much memory is allocated by each line of your code. This can reveal problems like type instability, or operations that you might have thought were cheap (in terms of memory allocated) but aren't (i.e. accidental copying). Comparison of coverage packages
Most users will want to use Coverage.jl. Working locallyCode coverageStep 1: collect coverage data. If you are using your default test suite, you can collect coverage data with julia --code-coverage=user or more comprehensively (if you're interested in getting coverage for Julia's standard libraries) julia --code-coverage=tracefile-%p.info --code-coverage=user # available in Julia v1.1+ You can add other options (e.g., Step 2: collect summary statistics (optional). Navigate to the top-level directory of your package, restart Julia (with no special flags) and analyze your code coverage: using Coverage
# process '*.cov' files
coverage = process_folder() # defaults to src/; alternatively, supply the folder name as argument
coverage = append!(coverage, process_folder("deps")) # useful if you want to analyze more than just src/
# process '*.info' files, if you collected them
coverage = merge_coverage_counts(coverage, filter!(
let prefixes = (joinpath(pwd(), "src", ""),
joinpath(pwd(), "deps", ""))
c -> any(p -> startswith(c.filename, p), prefixes)
end,
LCOV.readfolder("test")))
# Get total coverage for all Julia files
covered_lines, total_lines = get_summary(coverage)
# Or process a single file
@show get_summary(process_file(joinpath("src", "MyPkg.jl"))) The fraction of total coverage is equal to Step 3: identify uncovered lines (optional). To discover which functions lack testing, browse through the Be aware of a few limitations:
Memory allocationStart julia with julia --track-allocation=user Then:
Finally, navigate to the directory holding your source code. Start julia (without command-line flags), and analyze the results using using Coverage
analyze_malloc(dirnames) # could be "." for the current directory, or "src", etc. This will return a vector of LCOV exportThere are many tools to work with LCOV info-format files as generated by the coverage = process_folder()
LCOV.writefile("coverage-lcov.info", coverage) Cleaning up .cov filesWhen using Coverage.jl locally, over time a lot of Codecov.ioTracking Coverage withCodecov.io is a test coverage tracking tool that integrates with your continuous integration servers (e.g. TravisCI) or with HTTP POSTs from your very own computer at home.
Coveralls.ioTracking Coverage withCoveralls.io is a test coverage tracking tool that integrates with your continuous integration solution (e.g. TravisCI).
A note for advanced usersCoverage tracking in Julia is not yet quite perfect. One problem is that (at least in certain scenarios), the coverage data emitted by Julia does not mark functions which are never called (and thus are not covered) as code. Thus, they end up being treated like comments, and are not counted as uncovered code, even though they clearly are. This can arbitrarily inflate coverage scores, and in the extreme case could even result in a project showing 100% coverage even though it contains not a single test. To overcome this, Coverage.jl applies a workaround which ensures that all lines of code in all functions of your project are properly marked as "this is code". This resolves the problem of over reporting coverage. Unfortunately, this workaround itself can have negative consequences, and lead to under reporting coverage, for the following reason: when Julia compiles code with inlining and optimizations, it can happen that some lines of Julia code do not correspond to any generated machine code; in that case, Julia's code coverage tracking will never mark these lines as executed, and also won't mark them as code. One may now argue whether this is a bug in itself or not, but that's how it is, and normally would be fine -- except that our workaround now does mark these lines as code, but code which now never has a chance as being marked as executed. We may be able to improve our workaround to deal with this better in the
future (see also #188), but this
has not yet been done and it is unclear whether it will take care of all
instances. Even better would be if Julia improved the coverage information it
produces to be on par with what e.g. C compilers like GCC and clang produce.
Since it is unclear when or if any of these will happen, we have added an
expert option which allows Julia module owners to disable our workaround code,
by setting the environment variable For Travis, this can be achieved by adding the following to
For AppVeyor, add this to
Some Julia packages using Coverage.jlPull requests to add your package welcome (or open an issue)
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论