[tool] make testUsingContext
provide a Stdio
(with hasTerminal
unset) override by default (#151357)
While exploring https://github.com/flutter/flutter/issues/107607, I noticed that flutter_tools test results change based on whether `dart test` is run from a terminal or from a process (such as a Dart program). I also ran into this while writing tests for https://github.com/flutter/flutter/pull/150667. This is due to tests that rely on the global `Stdio` instance, on which the `hasTerminal` property depends on whether the tool is being invoked from a terminal. Ideally, `testUsingContext` would require any tests that depend on `globals.stdio` to define an override for `Stdio`, but this is not the case. Until a solution to this more general problem is figured out, I think we should have `testUsingContext` always provide a `Stdio` override by default.
This commit is contained in:
parent
f194cd3298
commit
c206a47505
@ -469,7 +469,7 @@ void main() {
|
|||||||
Usage: () => usage,
|
Usage: () => usage,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('passes device target platform to usage', () async {
|
testUsingContext('passes device target platform to analytics', () async {
|
||||||
final RunCommand command = RunCommand();
|
final RunCommand command = RunCommand();
|
||||||
final FakeDevice mockDevice = FakeDevice(sdkNameAndVersion: 'iOS 13')
|
final FakeDevice mockDevice = FakeDevice(sdkNameAndVersion: 'iOS 13')
|
||||||
..startAppSuccess = false;
|
..startAppSuccess = false;
|
||||||
@ -485,14 +485,6 @@ void main() {
|
|||||||
'--no-hot',
|
'--no-hot',
|
||||||
]), isNull);
|
]), isNull);
|
||||||
|
|
||||||
expect(usage.commands, contains(
|
|
||||||
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
|
|
||||||
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
|
|
||||||
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
|
|
||||||
'cd57': 'usb',
|
|
||||||
'cd58': 'false',
|
|
||||||
})
|
|
||||||
)));
|
|
||||||
expect(
|
expect(
|
||||||
fakeAnalytics.sentEvents,
|
fakeAnalytics.sentEvents,
|
||||||
contains(
|
contains(
|
||||||
@ -522,7 +514,7 @@ void main() {
|
|||||||
analytics.Analytics: () => fakeAnalytics,
|
analytics.Analytics: () => fakeAnalytics,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('correctly reports tests to usage', () async {
|
testUsingContext('correctly reports tests to analytics', () async {
|
||||||
fs.currentDirectory.childDirectory('test').childFile('widget_test.dart').createSync(recursive: true);
|
fs.currentDirectory.childDirectory('test').childFile('widget_test.dart').createSync(recursive: true);
|
||||||
fs.currentDirectory.childDirectory('ios').childFile('AppDelegate.swift').createSync(recursive: true);
|
fs.currentDirectory.childDirectory('ios').childFile('AppDelegate.swift').createSync(recursive: true);
|
||||||
final RunCommand command = RunCommand();
|
final RunCommand command = RunCommand();
|
||||||
@ -538,14 +530,6 @@ void main() {
|
|||||||
'test/widget_test.dart',
|
'test/widget_test.dart',
|
||||||
]), isNull);
|
]), isNull);
|
||||||
|
|
||||||
expect(usage.commands, contains(
|
|
||||||
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
|
|
||||||
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
|
|
||||||
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
|
|
||||||
'cd57': 'usb',
|
|
||||||
'cd58': 'true',
|
|
||||||
})),
|
|
||||||
));
|
|
||||||
expect(
|
expect(
|
||||||
fakeAnalytics.sentEvents,
|
fakeAnalytics.sentEvents,
|
||||||
contains(
|
contains(
|
||||||
|
@ -126,6 +126,7 @@ void testUsingContext(
|
|||||||
TemplateRenderer: () => const MustacheTemplateRenderer(),
|
TemplateRenderer: () => const MustacheTemplateRenderer(),
|
||||||
BuildTargets: () => const BuildTargetsImpl(),
|
BuildTargets: () => const BuildTargetsImpl(),
|
||||||
Analytics: () => const NoOpAnalytics(),
|
Analytics: () => const NoOpAnalytics(),
|
||||||
|
Stdio: () => FakeStdio(),
|
||||||
},
|
},
|
||||||
body: () {
|
body: () {
|
||||||
// To catch all errors thrown by the test, even uncaught async errors, we use a zone.
|
// To catch all errors thrown by the test, even uncaught async errors, we use a zone.
|
||||||
|
@ -254,7 +254,7 @@ class FakeStdio extends Stdio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool hasTerminal = true;
|
bool hasTerminal = false;
|
||||||
|
|
||||||
List<String> get writtenToStdout => _stdout.writes.map<String>(_stdout.encoding.decode).toList();
|
List<String> get writtenToStdout => _stdout.writes.map<String>(_stdout.encoding.decode).toList();
|
||||||
List<String> get writtenToStderr => _stderr.writes.map<String>(_stderr.encoding.decode).toList();
|
List<String> get writtenToStderr => _stderr.writes.map<String>(_stderr.encoding.decode).toList();
|
||||||
@ -281,6 +281,9 @@ class FakeStdin extends Fake implements Stdin {
|
|||||||
@override
|
@override
|
||||||
bool lineMode = true;
|
bool lineMode = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hasTerminal = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<S> transform<S>(StreamTransformer<List<int>, S> transformer) {
|
Stream<S> transform<S>(StreamTransformer<List<int>, S> transformer) {
|
||||||
return controller.stream.transform(transformer);
|
return controller.stream.transform(transformer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user