-
Notifications
You must be signed in to change notification settings - Fork 121
Feature Addition (Addresses #462): Record test srcrefs and link to covr traces #463
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
Conversation
|
It might be worth looking at how this handles the tests in data.table and knitr. Both of them do not use testthat or RUnit. |
|
Thanks @jimhester! I've been trying to dig up good example packages and will definitely try these out. Regarding the CI checks, I'm able to successfully run tests on my machine (macOS R 4.0.3). I tried testing on an older R install (3.6.2) as well but ran into curl dynamic library issues - I think these are just issues with my machine, but can explore further if that might be helpful. At least for the linux builds, the issue seems to be with dependency installs. Do you have any suggested actions I should take to get builds passing? |
|
I think I've added some reasonably generalized fallbacks for trying to collect the test traces. In trying to test an RUnit package ( Just to document the process a bit:
|
|
You shouldn't need to open a new PR, you should be able to change the email on the commits with interactive rebase. Alternatively if you just add the other email to your list of emails on GitHub that would also solve the issue I think. |
…to dev/linked_testrefs
…to dev/linked_testrefs
This is not quite correct. |
|
Thanks @jimhester - will update this in the description. |
|
@jimhester - I went ahead and just removed the working directory behavior. Now, both I edited my previous commits to all be from the same email, and the CLA looks good now. (Just a note, the CLA mentions the project is "current located at https://github.com/jimhester/covr or its successors or assigns" - wanted to raise that to your attention in case it's an oversight in the r-lib migration that needs to be updated). Otherwise, I think this is in a good place unless you have other behavioral concerns. I looked into the failing CI builds, but I think these failures are holdovers from current master db5423f. |
|
As far as I can tell, the builds pass with the exception of an issue that also currently exists in master - a dependency on @jimhester - is there anything more that you'd like me to look into before considering this PR? |
It seems that this is not automatically done when using gfortran + clang on macOS
R CMD check sets this environment variable when running tests, but tools::testInstalledPackage does not. Covr aims to be as consistent as possible with R CMD check, so we should set it as well. Fixes #420
|
This seems to break tests: |
|
I'm seeing: |
|
This occurs an M1 Mac. |
|
Thanks @krlmlr. I don't have a physical M1 machine to test against, but it looks like there are a few web hosted offerings that I might be able to look into to do some investigation. I'll try my best to reproduce a similar setup to investigate where things are going wrong. |
|
Sorry for a bit of a delay - it took me a while to hunt down an M1 system to test against. Initially, I was able to see the exact same tests failing, but after rebuilding and reinstalling they seem to disappear. I was only able to get these exact test failures if I installed the version of |
Overview
As described in #462, this PR adds functionality to capture data about the executing test while capturing coverage traces. This adds two pieces of additional data to the coverage object:
attr(,"tests")During collection, this is captured under
.counters$tests(the.countersenvironment namespace uses srcref "keys" as names, so thetestname can be confidently used without risk of conflicts.) This object is lifted out into an attribute inpackage_coverage. It includes curated calls from the call stack during the execution of a test. Calls are included if their source is within the tests directory or is the last call prior to entering the package namespace (before the firstcountcall).<coverage object>$<srcref key>$testsIn addition, each covr trace keeps a listing of which tests result in the trace execution including the index of the corresponding tests in
attr(cov, "tests")and the stack depth into the package at which the trace is executed:Change log
covr.record_testsoption, which must beTRUEbefore additional information is usedcount_testfromcount, if option "covr.record_tests" isTRUE.current_testenvironment object to thecovrnamespace (like.counters), which is used for capturing the current test during each trace count. It is invalidated if the executing call srcref changes and a new test trace, test frame and srcref take its place as the current test.as_coveragefunction, in order to centralize handling of the .counters$test value.merge_coveragean S3 generic function, dispatching on a character vector of filepaths or a list of coverage objects. This just makes it easier to test without having to write coverage objects out to files.<coverage obj>$testsconsolidation inmerge_coverageoptions(covr.record_tests = .(getOption("covr.record_tests")))through to package startup within a test installation.covroptions to?covrpackage documentation. This isn't directly related to test srcrefs, but seemed like a gap I could address in the process. I tried my best to document the options whose behavior, pulling comments where they exist already somewhere in the code base when possible or when I could confidently infer from the source code. There were quite a few (mostly pertaining to gcc and icc) that I left blank.Design Considerations
Just a couple design decisions that I want to raise to your attention for review:
$testswithin.counters. I think this is safe, knowing that srcref keys will always take the forma:1:2:3:4:5:6:7:8, but it's always a bit disconcerting to attribute so much meaning to value names.Benchmarks
I did a bit of benchmarking. Across the board, execution time was about 5-10% slower with
options(covr.record_tests)enabled, and object size (usinglobstr::obj_size) was ~5x the size.Future Work