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

decorate and retrieve @examples calls from testthat/ #12

Open
maxheld83 opened this issue Oct 9, 2024 · 1 comment
Open

decorate and retrieve @examples calls from testthat/ #12

maxheld83 opened this issue Oct 9, 2024 · 1 comment

Comments

@maxheld83
Copy link
Contributor

another (third?) alternative idea for the existing source_pef()-clumsiness, after #11 #4 have failed:

It'd be nice to have some magic markup/decoration inside the testthat that can then be called from roxygen decorators, like so (absolute pseudocode):

testthat/test-foo.R:

res <- {#' @exampleFromTestthat bar_1
  bar_fun(1, 2)
}
test_that("lorem", expect_true(res))

R/foo.R:

#' Foo function
#' @reuseExamplesFromTestthat bar_1
...
@maxheld83
Copy link
Contributor Author

however this is still quite convoluted, and I'm not sure this can be built cleanly, or at all.

I'm guessing this would require some fancy work with environments, because I'm not sure of any other way to mark some part of the testthat code as reusable, while also still evaluating it in terms of testthat.
(By contrast, the stuff behind roxygen2 or plumber decorations doesn't get evaluated in the normal course of evaluation of a file; they're commments.)
So this might get fairly deep into the language/parser ... I don't even know.

It's probably a bridge too far for a relatively modest increase in convenience,
while it's also still somewhat ham-fisted/un-idiomatic.

Leaving this here on backlog for reference.

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

No branches or pull requests

1 participant