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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a simple way to test this code?

(Also needs a news bullet)

R/test-example.R Outdated
#' 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}}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"or otherwise"

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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
Copy link
Member Author

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
@hadley
Copy link
Member

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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants