-
Notifications
You must be signed in to change notification settings - Fork 25
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
Recursive test_r() #433
base: main
Are you sure you want to change the base?
Recursive test_r() #433
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #433 +/- ##
===========================================
+ Coverage 11.90% 38.85% +26.94%
===========================================
Files 8 9 +1
Lines 294 435 +141
===========================================
+ Hits 35 169 +134
- Misses 259 266 +7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
DESCRIPTION
Outdated
@@ -1,6 +1,6 @@ | |||
Package: rhino | |||
Title: A Framework for Enterprise Shiny Applications | |||
Version: 1.3.0 | |||
Version: 1.3.0.8001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding version conflict with the covr support branch.
R/recursive_unit_tests.R
Outdated
valid_paths <- unique( | ||
fs::path_dir( | ||
fs::dir_ls(path = private$path, | ||
regexp = private$filter, | ||
recurse = private$recursive, type = "file") | ||
) | ||
) | ||
|
||
private$valid_paths <- valid_paths[order(valid_paths)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because testthat::test_dir()
throws an error if given a path without a valid test file, we get a list of valid test files, then get their paths.
R/recursive_unit_tests.R
Outdated
r_cmd_check_fix <- function() { | ||
testthat::test_check() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, I was getting an R CMD CHECK note Namespace in Imports field not imported from: 'testthat'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Rodrigo, many thanks for this PR! I really appreciate that you dived into this issue 😃 👍 I'm doing a detailed code review yet, as I'd like to discuss a bunch of high-level points first.
Output
The most important point for me is the console output of test_r()
. With this implementation we'll print test results for each directory and a summary at the end. This leads to a ton of horizontal lines and partial summaries; I find it very difficult to read.
Ideally the output would look pretty much like it did before: just a single table with all tests and one summary line at the end. Is it feasible?
test_r()
API
Ideal API IMO:
- Accept a vector in
paths
(files and directories with tests to run). - Drop
recursive
(when would we need something else thanTRUE
?) - Replace
...
withfilter
(what other use cases would it have?).
Additionally:
- Apply filter after stripping
test-
and.R
. - Don't require
test-
prefix for files (is it possible?).
Implementation / approach
- Using
getFromNamespace()
is risky, just like:::
. CRAN reviewers might not accept it; it will leave us prone to internal changes intestthat
. - I think, ideally,
testthat
would export a function which can run all tests in the given file and return results in a format which can be further processed (e.g. data frame). How about submitting a patch fortestthat
? - I can see how R6 helps us to avoid introducing too many functions to the outside world 👍 However, storing the arguments as private class fields makes it somewhat difficult to reason about the object state. Passing stuff around via arguments and return values would probably make for a more readable code. Perhaps we don't need R6 then?
Code style
See my comments in the code.
Final words
Again, thanks a lot for working on this! ❤️ Some issues might be easier to discuss in person; LMK if you'd like to have a call. Also LMK if you need some support getting more time reserved to work on this 🙂
R/recursive_unit_tests.R
Outdated
test_results <- private$run_recursive_test_dir(...) | ||
|
||
private$show_summary(test_results) | ||
|
||
private$show_final_line(test_results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation: Use blank lines sparingly, to separate logical blocks of code.
R/recursive_unit_tests.R
Outdated
summary_line(final_line_results[["failed"]], | ||
final_line_results[["warning"]], | ||
final_line_results[["skipped"]], | ||
final_line_results[["passed"]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation: Use the following indentation style when arguments don't fit on one line:
func(
long_arg_1, # All arguments indented with 2 spaces.
long_arg_2
) # Closing parenthesis on new line, with the same indentation as `func`.
This way if func
is renamed there is no need to adjust the indentation of its arguments, which is easy to forget about and leads to larger / not meaningful diffs (harder to review).
Hi Kamil, Thank you for the code review. OutputThe output looks like that now because all we are doing now is running API
|
Massive update |
…eload() calls in test files
Retracting this PR in favor of forking testthat itself Appsilon/testthat#2 |
Changes
A unit test handler than can accept a vector of paths (a combination of files and directories) to run tests on.
test_r()
defaults to runningtestthat::test_file()
on all*.R
files found insidetests/testthat/
directory and nested directories.test_file()
is intelligent enough to not do anything (returnsNULL
) if it does not find any tests.Ways of using
test_r()
:test_r()
test_r(paths = "tests/testthat/test-main.R")
test_r(paths = "tests/testthat/logic")
test_r(paths = c("tests/testthat/test-main.R", "tests/testthat/logic")
Removed R6. Now just a collection of functions.
In addition to
paths
,test_r()
accepts:inline_issues
- defaults to FALSE, switches where failures and skipped test messages are located. TRUE mimicstestthat::test_dir()
behavior.raw_testthat_output
- defaults to FALSE which causestest_r()
to return a single data.frame. TRUE causestest_r()
to return a list oftestthat::test_file()
results which are lists containing data of test results.Also added:
Not (yet) added:
Added a unit test handler that can run tests on:single test filesingle test dir (non-recursive)recursive test dirs from a base pathA lot of code taken from
testthat
internal functions to have the same look and feel. May need attribution.I am open to suggestions on how to write unit tests for this.Unit tests written. May need more detailed tests (snapshots).Addresses Issue #39
How to test
unit tests for
test_r()
are available intests/testthat/test-test_r.R
. It usestests/testthat/test_recursive
as its sample test files and directoriesrhino::test_r()
- recursive run on all validtest-*.R
files intests/testthat
, if there are no nested test folders, just runs the basictestthat::test_dir("tests/testthat")
rhino::test_r(recursive = FALSE)
- equivalent totestthat::test_dir("tests/testthat")
rhino::test_file("tests/testthat/main.R") - equivalent to
testthat::test_file("tests/testthat/main.R")`Covr
Done.Appsilon/covr
will need to be updated to handle nested test foldersAppsilon/rhino@feature/covr-support
version 1.3.0.9003