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

Shim code and revise tests for upcoming release of testthat #135

Merged
merged 1 commit into from Oct 9, 2017

Conversation

nealrichardson
Copy link
Contributor

r-lib/testthat#553 makes it so that with_mock can't mock functions in base packages anymore. See r-lib/testthat#546 and various other issues linked to it for a discussion. They keep saying that mocking doesn't work with the current development version of R, but I've never seen any test failures on it locally or on Travis, so /me shrugs. Apparently they landed on a compromise of disallowing mocking of base packages and not preventing it for anything outside of your own package, which would have been a disaster for us.

"Fixing" it here generally means adding a function to crunch that passes through to the base/utils/whatever function, and then mocking the crunch version in the tests.

Since we're due for a CRAN release anyway, and I can see that they're gearing up for a testthat release too, let's get in front of the reverse-dependency check notification and update now. I ran everything locally with the current master branch of testthat and it passes.

… allow mocking functions from base packages
@codecov
Copy link

codecov bot commented Oct 9, 2017

Codecov Report

Merging #135 into master will decrease coverage by 0.03%.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
- Coverage   87.44%   87.41%   -0.04%     
==========================================
  Files          87       87              
  Lines        4980     4984       +4     
==========================================
+ Hits         4355     4357       +2     
- Misses        625      627       +2
Impacted Files Coverage Δ
R/auth.R 61.4% <0%> (-1.1%) ⬇️
R/consent.R 100% <100%> (ø) ⬆️
R/progress.R 100% <100%> (ø) ⬆️
R/dataset.R 93.05% <50%> (-0.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c793732...b632bcb. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Oct 9, 2017

Codecov Report

Merging #135 into master will decrease coverage by 0.03%.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
- Coverage   87.44%   87.41%   -0.04%     
==========================================
  Files          87       87              
  Lines        4980     4984       +4     
==========================================
+ Hits         4355     4357       +2     
- Misses        625      627       +2
Impacted Files Coverage Δ
R/auth.R 61.4% <0%> (-1.1%) ⬇️
R/consent.R 100% <100%> (ø) ⬆️
R/progress.R 100% <100%> (ø) ⬆️
R/dataset.R 93.05% <50%> (-0.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c793732...b632bcb. Read the comment docs.

Copy link
Contributor

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -1,7 +1,7 @@
with_fake_input <- function (input, expr) {
with_mock(
`crunch:::is.interactive`=function () return(TRUE),
`base::readline`=function (...) input,
`crunch:::read_input`=function (...) input,
Copy link
Contributor

Choose a reason for hiding this comment

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

The crunch::: doesn't appear to be strictly necessary here. I tried removing them and running (against both release and master branch testthat) and the examples don't have them: https://github.com/hadley/testthat/blob/master/R/mock.R#L34

However, I don't mind leaving them in since they make it more explicit what's going on and make sure we aren't accidentally mocking from another namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it turns out R CMD check fails if you remove the crunch::: from these, like Function is.interactive not found in environment testthat.

@nealrichardson nealrichardson merged commit b632bcb into master Oct 9, 2017
@nealrichardson nealrichardson deleted the no-mock-base branch October 9, 2017 20:16
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