[flutter_plugin_tools] Work around banner in drive-examples (#4142)

* [flutter_plugin_tools] Work around banner in drive-examples

Strip off any unexpected output before parsing `flutter devices
--machine` output. Works around a bug in the Flutter tool that can
result in banners being printed in `--machine` mode.

Fixes https://github.com/flutter/flutter/issues/86052
This commit is contained in:
stuartmorgan
2021-07-07 20:02:35 -07:00
committed by GitHub
parent d2bac9116b
commit a63c0eb59f
3 changed files with 44 additions and 3 deletions

View File

@ -44,13 +44,22 @@ void main() {
void setMockFlutterDevicesOutput({
bool hasIosDevice = true,
bool hasAndroidDevice = true,
bool includeBanner = false,
}) {
const String updateBanner = '''
╔════════════════════════════════════════════════════════════════════════════╗
║ A new version of Flutter is available! ║
║ ║
║ To update to the latest version, run "flutter upgrade". ║
╚════════════════════════════════════════════════════════════════════════════╝
''';
final List<String> devices = <String>[
if (hasIosDevice) '{"id": "$_fakeIosDevice", "targetPlatform": "ios"}',
if (hasAndroidDevice)
'{"id": "$_fakeAndroidDevice", "targetPlatform": "android-x86"}',
];
final String output = '''[${devices.join(',')}]''';
final String output =
'''${includeBanner ? updateBanner : ''}[${devices.join(',')}]''';
final MockProcess mockDevicesProcess = MockProcess.succeeding();
mockDevicesProcess.stdoutController.close(); // ignore: unawaited_futures
@ -113,6 +122,32 @@ void main() {
);
});
test('handles flutter tool banners when checking devices', () async {
createFakePlugin(
'plugin',
packagesDir,
extraFiles: <String>[
'example/test_driver/integration_test.dart',
'example/integration_test/foo_test.dart',
],
platformSupport: <String, PlatformSupport>{
kPlatformIos: PlatformSupport.inline,
},
);
setMockFlutterDevicesOutput(includeBanner: true);
final List<String> output =
await runCapturingPrint(runner, <String>['drive-examples', '--ios']);
expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin'),
contains('No issues found!'),
]),
);
});
test('fails for iOS if getting devices fails', () async {
// Simulate failure from `flutter devices`.
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[