[flutter_tool] Prevent accidental calls to io.exit in unit tests#46639
Merged
jonahwilliams merged 13 commits intoflutter:masterfrom Dec 10, 2019
Merged
[flutter_tool] Prevent accidental calls to io.exit in unit tests#46639jonahwilliams merged 13 commits intoflutter:masterfrom
jonahwilliams merged 13 commits intoflutter:masterfrom
Conversation
added 10 commits
December 5, 2019 19:32
zanderso
reviewed
Dec 9, 2019
| /// Throws [StateError] if assertions are enabled and the dart:io exit | ||
| /// is still active when called. This may indicate exit was called in | ||
| /// a test without being configured correctly. This behavior can be | ||
| /// removed by setting the `FLUTTER_TEST` environment |
Member
There was a problem hiding this comment.
Looks like the comment needs to be updated.
| ExitFunction get exit { | ||
| assert(() { | ||
| if (_exitFunction == io.exit) { | ||
| try { |
Member
There was a problem hiding this comment.
Consider pulling the expect() check into a helper method, and simplifying here as in the last PR.
added 2 commits
December 9, 2019 14:12
zanderso
approved these changes
Dec 9, 2019
| ExitFunction get exit { | ||
| assert( | ||
| _exitFunction != io.exit || !_inUnitTest(), | ||
| 'io.exit was called with assertions active in a unit test' |
Member
There was a problem hiding this comment.
nit: Does assert allow a comma after the message string?
Contributor
Author
There was a problem hiding this comment.
Lets find out...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
To prevent a scenario such as #46142 for occurring again in the future, prevent calls to dart:io's exit when asserts are enabled within a unit test. This is detected by invoking
expectand checking if a StateError is thrown