Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subsets of tests #45

Closed
twilsonco opened this issue Sep 13, 2023 · 3 comments · Fixed by #46
Closed

Support subsets of tests #45

twilsonco opened this issue Sep 13, 2023 · 3 comments · Fixed by #46

Comments

@twilsonco
Copy link
Contributor

twilsonco commented Sep 13, 2023

I'd like to enable use of LocalCoverage.jl with subsets of tests by providing three optional arguments to generate_coverage() (and to any functions that call generate_coverage()):

  1. test_args::String which is simply passed along to Pkg.test()
  2. folder_list::Vector{String} a list of paths to directories for `process_folder(), and
  3. file_list::Vector{String} a list of paths to files for process_file()

generate_coverage() would then be changed:

function generate_coverage(pkg = nothing; run_test = true, test_args = "", folder_list = ["src"], file_list = [])
    if run_test
        # passing `test_args` to `Pkg.test()`
        isnothing(pkg) ? Pkg.test(; coverage = true, test_args = test_args) : Pkg.test(pkg; coverage = true, test_args = test_args)
    end
    package_dir = pkgdir(pkg)
    cd(package_dir) do
        # initialize empty vector of coverage data
        coverage = Vector{CoverageTools.FileCoverage}()
        # process folders (same as default if `folder_list` isn't provided)
        for f in folder_list
            append!(coverage, process_folder(f))
        end
        # process individual files
        for f in file_list
            push!(coverage, process_file(f))
        end
        mkpath(COVDIR)
        tracefile = joinpath(COVDIR, LCOVINFO)
        CoverageTools.LCOV.writefile(tracefile, coverage)
        CoverageTools.clean_folder("./")
        eval_coverage_metrics(coverage, package_dir)
    end
end

Motivation

I have a project where testing is compartmentalized, using test_args, based on which files changed. Using Coverage.jl I can then use process_folder() and process_file() on the different directories/files that were included in the test so that coverage is accurate for the tests run.

Data loaders - 627/648 lines covered (96.76%)
Analysis routines - 86/93 lines covered (92.47%)

I'd like to be able to achieve the same effect with LocalCoverage.jl

I'm happy to PR this.

@tpapp
Copy link
Collaborator

tpapp commented Sep 14, 2023

Great idea, a PR would be welcome.

@twilsonco
Copy link
Contributor Author

Awesome. I'll put one together!

@twilsonco
Copy link
Contributor Author

@tpapp #46

@tpapp tpapp closed this as completed in #46 Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants