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

Add wrap arg to test_dir for consistency with test_file (#586) #597

Closed
wants to merge 11 commits into from

Conversation

brodieG
Copy link
Contributor

@brodieG brodieG commented Jun 6, 2017

I hope it is not too presumptuous of me to submit this PR despite negative feedback in #586. I am just hoping that because the change:

  1. is minimal
  2. restores parameter symmetry between test_file and test_dir broken by 37cc0d0

you will consider it. Unfortunately for me I'm probably one of the very few people affected by 37cc0d0 since I happen to maintain a package that uses withCallingHandlers in testthat tests, outside of test_that blocks. If 37cc0d0 gets pushed to CRAN I have no way to workaround this anymore.

A possible alternative to this would be to set the test_file wrap parameter default value via getOption, which would provide another possible work-around.

Sorry for being obnoxious about this, but submitting this as a PR in the hopes you will consider it is a lot easier than figuring out how to take the ~800 tests in my package out of testthat.

Fix #586.

@brodieG
Copy link
Contributor Author

brodieG commented Jun 6, 2017

Re test failures, these seem to be the same ones in #594 and #590, so I'll let them be pending additional feedback. It also looks like Appveyor upgraded to 3.4 between the time these tests were run and the tests in #594 and #590.

Tests run fine on R3.3.3 for me.

Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Thanks, this looks like a simple compatibility solution.

R/test-files.R Outdated
@@ -27,17 +27,20 @@ test_env <- function() {
#' @return the results as a "testthat_results" (list)
#' @export
test_dir <- function(path, filter = NULL, reporter = default_reporter(),
env = test_env(), ..., encoding = "unknown", load_helpers = TRUE) {
env = test_env(), ..., encoding = "unknown",
load_helpers = TRUE, wrap = TRUE) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to document the new argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No because it is inherited from test_file (@inheritParams). You can see it in the Rd file: https://github.com/hadley/testthat/pull/597/files#diff-f540ef3582dc78a36153378451f7b979.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I did miss the @inheritParams...

## not recorded in return value, even when `wrap=TRUE` (see #596")

w.wrap <- capture.output(
test_dir('test_dir', filter='bare-expectations', wrap=TRUE)
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add space around =?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will address this evening. I've tried to do it as much as possible (e.g. in the actual function definition), but old habits die hard.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks -- and double quotes ", please ;-)

## test this because this test itself is in a `test_that` block, and further
## since the whole test suite is effectively run with `wrap=TRUE` it is not
## possible to test this at all. I ran this outside of the `test_that` call
## and it worked as expected.
Copy link
Member

Choose a reason for hiding this comment

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

We could use the callr package for this. @gaborcsardi: Do you have examples for running callr from a testthat test? Does it work for R CMD check?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you can do that, e.g. https://github.com/gaborcsardi/filelock/blob/master/tests/testthat/test.R#L27-L32

But it is kind of a big step, and brings in some dependencies as well, so I am not sure if it is worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@krlmlr let me know if you want me to do this.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we don't need it, because you will be using it all the time ;-)

@brodieG
Copy link
Contributor Author

brodieG commented Jun 7, 2017

@krlmlr, Alright, done. Also, merged in your master branch changes so the tests now pass!

Let me know if there is anything else I need to do here.

## possible to test this at all. I ran this outside of the `test_that` call
## and it worked as expected.

skip("untestable within test suite")
Copy link
Member

Choose a reason for hiding this comment

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

Forgot to mention that we don't need the skip() if we're not planning to implement a test. The rest looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so I'll just delete the test altogether then. I'll do that this evening.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the test before skip() looks fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, that's what I meant.

@krlmlr krlmlr requested a review from hadley June 7, 2017 06:53
@brodieG
Copy link
Contributor Author

brodieG commented Jun 8, 2017

@krlmlr, I removed the skipped test. Let me know if there is anything else that needs doing.

@hadley
Copy link
Member

hadley commented Oct 2, 2017

I'd rather fully understand your problem before we consider a PR.

@hadley
Copy link
Member

hadley commented Oct 5, 2017

Actually I think it'll be easier for me to finish this off.

@hadley hadley closed this Oct 5, 2017
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.

4 participants