Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
b698c9d7
Unverified
Commit
b698c9d7
authored
Dec 09, 2019
by
Jonah Williams
Committed by
GitHub
Dec 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Prevent accidental calls to io.exit when asserts are active in unit tests (#46210)
parent
05862ff9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
3 deletions
+35
-3
io.dart
packages/flutter_tools/lib/src/base/io.dart
+16
-2
io_test.dart
packages/flutter_tools/test/general.shard/base/io_test.dart
+10
-0
daemon_mode_test.dart
...lutter_tools/test/integration.shard/daemon_mode_test.dart
+3
-0
test_utils.dart
...ages/flutter_tools/test/integration.shard/test_utils.dart
+6
-1
No files found.
packages/flutter_tools/lib/src/base/io.dart
View file @
b698c9d7
...
...
@@ -26,7 +26,7 @@
/// increase the API surface that we have to test in Flutter tools, and the APIs
/// in `dart:io` can sometimes be hard to use in tests.
import
'dart:async'
;
import
'dart:io'
as
io
show
exit
,
IOSink
,
Process
,
ProcessInfo
,
ProcessSignal
,
import
'dart:io'
as
io
show
exit
,
IOSink
,
P
latform
,
P
rocess
,
ProcessInfo
,
ProcessSignal
,
stderr
,
stdin
,
Stdin
,
StdinException
,
Stdout
,
stdout
;
import
'package:meta/meta.dart'
;
...
...
@@ -92,12 +92,26 @@ ExitFunction _exitFunction = _defaultExitFunction;
/// Exits the process.
///
/// 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
/// variable to a non-null string.
///
/// This is analogous to the `exit` function in `dart:io`, except that this
/// function may be set to a testing-friendly value by calling
/// [setExitFunctionForTests] (and then restored to its default implementation
/// with [restoreExitFunction]). The default implementation delegates to
/// `dart:io`.
ExitFunction
get
exit
=>
_exitFunction
;
ExitFunction
get
exit
{
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.'
,
);
return
_exitFunction
;
}
/// Sets the [exit] function to a function that throws an exception rather
/// than exiting the process; this is intended for testing purposes.
...
...
packages/flutter_tools/test/general.shard/base/io_test.dart
View file @
b698c9d7
...
...
@@ -68,6 +68,16 @@ void main() {
testUsingContext
(
'ProcessSignal toString() works'
,
()
async
{
expect
(
io
.
ProcessSignal
.
sigint
.
toString
(),
ProcessSignal
.
SIGINT
.
toString
());
});
test
(
'exit throws a StateError if called without being overriden'
,
()
{
expect
(()
=>
exit
(
0
),
throwsA
(
isInstanceOf
<
AssertionError
>()));
});
test
(
'exit does not throw a StateError if overriden'
,
()
{
setExitFunctionForTests
((
int
value
)
{});
expect
(()
=>
exit
(
0
),
returnsNormally
);
});
}
class
MockIoProcessSignal
extends
Mock
implements
io
.
ProcessSignal
{}
packages/flutter_tools/test/integration.shard/daemon_mode_test.dart
View file @
b698c9d7
...
...
@@ -29,6 +29,9 @@ void main() {
final
Process
process
=
await
processManager
.
start
(
<
String
>[
flutterBin
,
'--show-test-device'
,
'daemon'
],
workingDirectory:
tempDir
.
path
,
environment:
<
String
,
String
>{
'FLUTTER_TEST'
:
'true'
,
}
);
final
StreamController
<
String
>
stdout
=
StreamController
<
String
>.
broadcast
();
...
...
packages/flutter_tools/test/integration.shard/test_utils.dart
View file @
b698c9d7
...
...
@@ -46,7 +46,12 @@ Future<void> getPackages(String folder) async {
'pub'
,
'get'
,
];
final
ProcessResult
result
=
await
processManager
.
run
(
command
,
workingDirectory:
folder
);
final
ProcessResult
result
=
await
processManager
.
run
(
command
,
workingDirectory:
folder
,
environment:
<
String
,
String
>{
'FLUTTER_TEST'
:
'true'
},
);
if
(
result
.
exitCode
!=
0
)
{
throw
Exception
(
'flutter pub get failed:
${result.stderr}
\n
${result.stdout}
'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment