Skip to content

Use restart in test_code() #2153

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Use restart in test_code() #2153

wants to merge 1 commit into from

Conversation

hadley
Copy link
Member

@hadley hadley commented Aug 1, 2025

No description provided.

@hadley hadley requested a review from lionel- August 1, 2025 12:42
@@ -175,7 +167,7 @@ test_code <- function(test, code, env, reporter, skip_on_empty = TRUE) {

debug_end <- if (inherits(e, "skip_empty")) -1 else 2
register_expectation(e, debug_end)
signalCondition(e)
invokeRestart("end_test")
Copy link
Member Author

Choose a reason for hiding this comment

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

This now seems like a clear bug — resignalling a condition inside a calling handler would have just duplicated the condition.

}
handle_fatal <- function(e) {
handled <<- TRUE
# Error caught in handle_error() has precedence
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer needed because we jump out of both the tryCatch + withCallingHandlers stack with a restart.

Copy link
Member

Choose a reason for hiding this comment

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

hmm... According to the comment on line 123, register_expectation() might fail, and one of the reasons the test_error setup was done is so the original error, rather than the internal one, would be registered here.

But we call register_expectation() again below (albeit with a different debug_end) so I'm not sure why this really matters.

Perhaps just remove the comment on line 123?

Copy link
Member

@lionel- lionel- left a comment

Choose a reason for hiding this comment

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

Looks like you can remove all mentions of test_error which is now dangling.

}
handle_fatal <- function(e) {
handled <<- TRUE
# Error caught in handle_error() has precedence
Copy link
Member

Choose a reason for hiding this comment

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

hmm... According to the comment on line 123, register_expectation() might fail, and one of the reasons the test_error setup was done is so the original error, rather than the internal one, would be registered here.

But we call register_expectation() again below (albeit with a different debug_end) so I'm not sure why this really matters.

Perhaps just remove the comment on line 123?

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.

2 participants