mirror of
https://github.com/flutter/packages.git
synced 2025-06-05 10:57:11 +08:00
[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:
@ -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>[
|
||||
|
Reference in New Issue
Block a user