Skip to content

prevent accidental calls to io.exit when asserts are active.#46210

Merged
jonahwilliams merged 9 commits intoflutter:masterfrom
jonahwilliams:never_again_
Dec 9, 2019
Merged

prevent accidental calls to io.exit when asserts are active.#46210
jonahwilliams merged 9 commits intoflutter:masterfrom
jonahwilliams:never_again_

Conversation

@jonahwilliams
Copy link
Copy Markdown
Contributor

@jonahwilliams jonahwilliams commented Dec 6, 2019

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. Allow an env variable to override to allow for integration tests, which run the full flutter process with asserts enabled

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Dec 6, 2019
@jonahwilliams
Copy link
Copy Markdown
Contributor Author

Errm, right - assertions in integration tests. If we could detect that we are in a package:test isolate maybe this could be more narrowly focused.

final ProcessResult result = await processManager.run(command,
workingDirectory: folder,
environment: <String, String>{
'FLUTTER_INTEGRATION_TEST': 'true'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the previous two instances of this it's set to 'test' rather than 'true'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/// 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_INTEGRATION_TEST` environment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is FLUTTER_INTEGRATION_TEST new? Is there any pre-existing one that could work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

there is a FLUTTER_TEST value that is set by flutter test and for some reason by the test_driver.dart. I could reuse that field since I don't think it is used otherwise for pub run test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to FLUTTER_TEST

/// `dart:io`.
ExitFunction get exit => _exitFunction;
ExitFunction get exit {
assert(() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this work?

assert(
  _exitFunction != io.exit || io.Platform.environment['FLUTTER_TEST'] != null,
  'io.exit was called with assertions active. If this is an integration test, '
  'ensure that the environment variable FLUTTER_TEST is set '
  'to a non-null String.',
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea

@jonahwilliams jonahwilliams merged commit b698c9d into flutter:master Dec 9, 2019
@jonahwilliams jonahwilliams deleted the never_again_ branch December 9, 2019 21:01
@jonahwilliams jonahwilliams restored the never_again_ branch December 9, 2019 21:12
jonahwilliams pushed a commit that referenced this pull request Dec 9, 2019
…ts are active in unit tests (#46210)"

This reverts commit b698c9d.
jonahwilliams pushed a commit that referenced this pull request Dec 9, 2019
…ts are active in unit tests (#46210)" (#46630)

This reverts commit b698c9d.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants