LCOV - code coverage report
Current view: top level - src - LocalCoverage.jl (source / functions) Hit Total Coverage
Test: on branch master Lines: 1 25 4.0 %
Date: 2018-03-09 08:34:02 Functions: 0 0 -

          Line data    Source code
       1             : module LocalCoverage
       2             : 
       3             : using Coverage
       4             : using DocStringExtensions
       5             : 
       6             : export generate_coverage, open_coverage, clean_coverage
       7             : 
       8             : "Directory for coverage results."
       9             : const COVDIR = "coverage"
      10             : 
      11             : "Coverage tracefile."
      12             : const LCOVINFO = "lcov.info"
      13             : 
      14             : """
      15             :     $SIGNATURES
      16             : 
      17             : Open the HTML coverage results in a browser for `pkg` if they exist.
      18             : 
      19             : See [`generate_coverage`](@ref).
      20             : """
      21             : function open_coverage(pkg)
      22           0 :     htmlfile = Pkg.dir(pkg, COVDIR, "index.html")
      23           0 :     if !isfile(htmlfile)
      24           0 :         warn("Not found, run generate_coverage(pkg) first.")
      25           0 :         return nothing
      26             :     end
      27           0 :     try
      28           0 :         if is_apple()
      29           0 :             run(`open $htmlfile`)
      30           0 :         elseif is_linux() || is_bsd()
      31           0 :             run(`xdg-open $htmlfile`)
      32           0 :         elseif is_windows()
      33           0 :             run(`start $htmlfile`)
      34             :         end
      35             :     catch e
      36           0 :         error("Failed to open the generated $(htmlfile)\n",
      37             :               "Error: ", sprint(Base.showerror, e))
      38             :     end
      39           0 :     nothing
      40             : end
      41             : 
      42             : """
      43             :     $SIGNATURES
      44             : 
      45             : Generate a coverage report for package `pkg`.
      46             : 
      47             : When `genhtml`, the corresponding external command will be called to generate a
      48             : HTML report. This can be found in eg the package `lcov` on Debian/Ubuntu.
      49             : 
      50             : `*.cov` files are near the source files as generated by Julia, everything else
      51             : is placed in `Pkg.dir(pkg, \"$(COVDIR)\")`. The summary is in
      52             : `Pkg.dir(pkg, \"$(COVDIR)\", \"$(LCOVINFO)\")`.
      53             : 
      54             : Use [`clean_coverage`](@ref) for cleaning.
      55             : """
      56             : function generate_coverage(pkg; genhtml = true)
      57           1 :     Pkg.test(pkg; coverage = true)
      58           0 :     cd(Pkg.dir(pkg)) do
      59           0 :         coverage = Coverage.process_folder()
      60           0 :         isdir(COVDIR) || mkdir(COVDIR)
      61           0 :         tracefile = "$(COVDIR)/lcov.info"
      62           0 :         Coverage.LCOV.writefile(tracefile, coverage)
      63           0 :         if genhtml
      64           0 :             branch = strip(read(`git branch`, String), [' ', '*', '\n'])
      65           0 :             title = "on branch $(branch)"
      66           0 :             run(`genhtml -t $(title) -o $(COVDIR) $(tracefile)`)
      67             :         end
      68             :     end
      69             : end
      70             : 
      71             : """
      72             :     clean_coverage(pkg)
      73             : 
      74             : Clean up after [`generate_coverage`](@ref).
      75             : """
      76             : function clean_coverage(pkg)
      77           0 :     Coverage.clean_folder(Pkg.dir(pkg))
      78           0 :     rm(Pkg.dir(pkg, COVDIR); force = true, recursive = true)
      79             : end
      80             : 
      81             : end # module

Generated by: LCOV version 1.13