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 use_test_helper() #1978

Merged
merged 19 commits into from
Jul 26, 2024
Merged

Add use_test_helper() #1978

merged 19 commits into from
Jul 26, 2024

Conversation

olivroy
Copy link
Contributor

@olivroy olivroy commented Apr 11, 2024

Fix #1822

Probably better to merge #1990 first.

If merged, I will add some pointer in https://testthat.r-lib.org/articles/special-files.html#helper-files.

Considerations:

Test interactively: be able to jump the 3 files easily R/mocks.R, tests/testthat/test-mocks.R and tests/testthat/helper-mocks.R
.

use_test_helper() # will go to specific associated helper file if exists or tests/testthat/helper.R otherwise

In usethis, I'd type the 3 functions successively starting with mocks.R to see that the 3 way workflow works as expected.

A case I have not considered:

if multiple tests/testthat/helper-{file}.R exist, but not tests/testthat/helper.R, but not tests/testthat/helper-foofy.R, it would probably be better to have it than what I currently implemented (tests/testthat/helper.R)

Harder to jump back to test files or R from tests/testthat/helper.R, will create a possibly unwanted file. I added a condition to prevent that.. 31d68a2

R/r.R Outdated Show resolved Hide resolved
@jennybc jennybc mentioned this pull request Jun 27, 2024
@jennybc
Copy link
Member

jennybc commented Jul 24, 2024

As per the discussion in #1822, let's strip this down to just creating/opening a test helper file.

@olivroy
Copy link
Contributor Author

olivroy commented Jul 24, 2024

Should it be documented with use_r() and use_test() or should it be its own topic?

@jennybc
Copy link
Member

jennybc commented Jul 24, 2024

It looks hard to document with use_r() and use_test() since they are so tightly coupled. I think it's fine to stand alone. You'd definitely want cross links in the help for use_test_helper() and use_r()/use_test().

Merge commit '1909b25e110f5a97b2d1c393d0218a2768078a46'

#Conflicts:
#	NEWS.md
Merge commit '875aa503ae50d29e37293d85c98656a72cfbbd43'

#Conflicts:
#	NEWS.md
R/r.R Outdated Show resolved Hide resolved
tests/testthat/test-r.R Outdated Show resolved Hide resolved
R/utils-git.R Outdated Show resolved Hide resolved
@olivroy olivroy mentioned this pull request Jul 25, 2024
Condition
Error in `use_test_helper()`:
x Your package must use testthat to use a helper file.
Call `usethis::use_testthat()` to set up testthat.
Copy link
Member

Choose a reason for hiding this comment

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

This should be a "todo" bullet, so I'm going to open a separate issue about that. Has nothing to do with this PR.

@jennybc
Copy link
Member

jennybc commented Jul 26, 2024

Thanks!

@jennybc jennybc merged commit decf39d into r-lib:main Jul 26, 2024
11 of 12 checks passed
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.

FR: use_test_helper()
2 participants