Guard cli.spinner option to avoid crash#74
Conversation
Handle invalid cli.spinner option values in runTestsQuietly. btw::local_reproducible_output (via btw_tool_run_r) can set options(cli.spinner = FALSE), which causes cli::get_spinner() to fail ("$ operator is invalid for atomic vectors") when testthat reporters access spinner frames. This change saves the old value, coerces non-NULL non-character non-list values to "line", and restores the original option on exit to prevent the crash during tests.
There was a problem hiding this comment.
Pull request overview
This PR adds a defensive guard in runTestsQuietly() to prevent a crash when cli.spinner has been set to an invalid value (e.g., FALSE) by btw::local_reproducible_output(). The cli::get_spinner() function used internally by testthat reporters requires the option to be NULL, a character string, or a list — any other type causes a "$ operator is invalid for atomic vectors" crash.
Changes:
- The invalid
cli.spinneroption value is detected and coerced to"line"before tests run. - The original option value is always restored via
on.exit()after the test function completes.
| #' @keywords internal | ||
| runTestsQuietly <- function(testFun) { | ||
| # Fix cli.spinner: btw::local_reproducible_output() (called by btw_tool_run_r) | ||
|
|
There was a problem hiding this comment.
The explanatory comment is accidentally split by a blank line between lines 166 and 168, making it read as two separate comments. The sentence "btw::local_reproducible_output() (called by btw_tool_run_r)" is cut off at line 166, with the rest of the sentence starting on line 168. The blank line should be removed so the comment is a single continuous block.
Handle invalid cli.spinner option values in runTestsQuietly. btw::local_reproducible_output (via btw_tool_run_r) can set options(cli.spinner = FALSE), which causes cli::get_spinner() to fail ("$ operator is invalid for atomic vectors") when testthat reporters access spinner frames. This change saves the old value, coerces non-NULL non-character non-list values to "line", and restores the original option on exit to prevent the crash during tests.