Skip to content

Refactor the test_examples function#532

Merged
hadley merged 6 commits intor-lib:masterfrom
jimhester:test_examples
Oct 1, 2017
Merged

Refactor the test_examples function#532
hadley merged 6 commits intor-lib:masterfrom
jimhester:test_examples

Conversation

@jimhester
Copy link
Copy Markdown
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
Copy Markdown
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)

Comment thread R/test-example.R Outdated
#' @param path For \code{test_examples}, path to the package directory.
#' 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
Copy Markdown
Member

Choose a reason for hiding this comment

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

"or otherwise"

Comment thread R/test-example.R
test_examples <- function(path = "../../man") {
man <- dir(path, "\\.Rd$", full.names = TRUE)
lapply(man, test_example)
test_examples <- function(path = "../..") {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants