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

Refactor the test_examples function #532

Merged
merged 6 commits into from Oct 1, 2017
Merged

Conversation

@jimhester
Copy link
Member

@jimhester jimhester commented Oct 6, 2016

Previously it would never run examples during R CMD check because there
was no '/man' directory for installed packages. This instead uses
tools::Rd_db to parse the Rd files into a database and uses that
directly, which does work for installed packages.

Fixes r-lib/covr#205

Copy link
Member

@hadley hadley left a comment

Is there a simple way to test this code?

(Also needs a news bullet)

#' For \code{test_example}, path to a single Rd file. Remember the working
#' directory for tests is \code{tests/testthat}.
#' @param rd A parsed Rd object, obtained from \code{\link[tools]{Rd_db}}.

This comment has been minimized.

@hadley

hadley Dec 15, 2016
Member

"or otherwise"

test_examples <- function(path = "../../man") {
man <- dir(path, "\\.Rd$", full.names = TRUE)
lapply(man, test_example)
test_examples <- function(path = "../..") {

This comment has been minimized.

@hadley

hadley Dec 15, 2016
Member

I think this would be clearer with two functions - maybe test_examples_installed and test_examples_source ?

This comment has been minimized.

@jimhester

jimhester Dec 30, 2016
Author Member

Ok I split it up, I agree the logic is more clear now

jimhester added 4 commits Oct 6, 2016
This can then be used by `test_examples()` to find the examples for the
package being tested.
Previously it would never run examples during R CMD check because there
was no '/man' directory for installed packages. This instead uses
tools::Rd_db to parse the Rd files into a database and uses that
directly, which does work for installed packages.
@jimhester jimhester force-pushed the jimhester:test_examples branch from 6b032ab to 9023d3c Dec 30, 2016
@jimhester
Copy link
Member Author

@jimhester jimhester commented Dec 30, 2016

I haven't come up with a good way to test this, since we don't have a source package when using R CMD check there isn't a great way to test running source examples. The current test runs the the code to find the examples, but does not actually run them. The main issue with running them is the examples contain expectations themselves, which makes the reporting a little confusing. They also have additional output that would need to be suppressed using something like withr::with_output_sink().

@hadley hadley merged commit 4438b21 into r-lib:master Oct 1, 2017
0 of 2 checks passed
0 of 2 checks passed
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@hadley
Copy link
Member

@hadley hadley commented Oct 1, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants