From 1ac09088c3f06698e24805d55a1740dbaa2aabfe Mon Sep 17 00:00:00 2001 From: kwkr Date: Tue, 28 Apr 2020 22:12:12 +0200 Subject: [PATCH] Fix/use contains ignoring whitespace (#55887) --- .../commands.shard/hermetic/attach_test.dart | 4 +- .../commands.shard/hermetic/config_test.dart | 25 ++++++++--- .../commands.shard/hermetic/devices_test.dart | 2 +- .../commands.shard/hermetic/run_test.dart | 12 +++-- .../test/general.shard/channel_test.dart | 22 +++++++--- .../commands/build_apk_test.dart | 29 ++++++++---- .../commands/build_appbundle_test.dart | 44 +++++++++++++------ .../general.shard/runner/runner_test.dart | 5 ++- 8 files changed, 101 insertions(+), 42 deletions(-) diff --git a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart index c571111f83..98e11e3437 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart @@ -648,7 +648,7 @@ void main() { createTestCommandRunner(command).run(['attach']), throwsToolExit(), ); - expect(testLogger.statusText, contains('No supported devices connected')); + expect(testLogger.statusText, containsIgnoringWhitespace('No supported devices connected')); }, overrides: { FileSystem: () => testFileSystem, ProcessManager: () => FakeProcessManager.any(), @@ -671,7 +671,7 @@ void main() { createTestCommandRunner(command).run(['attach']), throwsToolExit(), ); - expect(testLogger.statusText, contains('More than one device')); + expect(testLogger.statusText, containsIgnoringWhitespace('More than one device')); expect(testLogger.statusText, contains('xx1')); expect(testLogger.statusText, contains('yy2')); }, overrides: { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/config_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/config_test.dart index 8c6def3c89..54b26042ea 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/config_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/config_test.dart @@ -161,7 +161,10 @@ void main() { '--enable-web' ]); - expect(testLogger.statusText, contains('You may need to restart any open editors')); + expect( + testLogger.statusText, + containsIgnoringWhitespace('You may need to restart any open editors'), + ); }, overrides: { Usage: () => mockUsage, }); @@ -183,10 +186,22 @@ void main() { 'config', ]); - expect(testLogger.statusText, contains('enable-web: true (Unavailable)')); - expect(testLogger.statusText, contains('enable-linux-desktop: true (Unavailable)')); - expect(testLogger.statusText, contains('enable-windows-desktop: true (Unavailable)')); - expect(testLogger.statusText, contains('enable-macos-desktop: true (Unavailable)')); + expect( + testLogger.statusText, + containsIgnoringWhitespace('enable-web: true (Unavailable)'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('enable-linux-desktop: true (Unavailable)'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('enable-windows-desktop: true (Unavailable)'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('enable-macos-desktop: true (Unavailable)'), + ); verifyNoAnalytics(); }, overrides: { AndroidStudio: () => mockAndroidStudio, diff --git a/packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart index 9bbbf213cc..32cafe11f8 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart @@ -31,7 +31,7 @@ void main() { testUsingContext('no error when no connected devices', () async { final DevicesCommand command = DevicesCommand(); await createTestCommandRunner(command).run(['devices']); - expect(testLogger.statusText, contains('No devices detected')); + expect(testLogger.statusText, containsIgnoringWhitespace('No devices detected')); }, overrides: { AndroidSdk: () => null, DeviceManager: () => DeviceManager(), diff --git a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart index 6aa596002a..4e6f05bbf5 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart @@ -113,9 +113,10 @@ void main() { expect(e, isA()); } final BufferLogger bufferLogger = globals.logger as BufferLogger; - expect(bufferLogger.statusText, contains( - 'Changing current working directory to:' - )); + expect( + bufferLogger.statusText, + containsIgnoringWhitespace('Changing current working directory to:'), + ); }, overrides: { FileSystem: () => MemoryFileSystem(), ProcessManager: () => FakeProcessManager.any(), @@ -230,7 +231,10 @@ void main() { expect(e.message, null); } - expect(testLogger.statusText, contains(userMessages.flutterNoSupportedDevices)); + expect( + testLogger.statusText, + containsIgnoringWhitespace(userMessages.flutterNoSupportedDevices), + ); }, overrides: { DeviceManager: () => mockDeviceManager, FileSystem: () => fs, diff --git a/packages/flutter_tools/test/general.shard/channel_test.dart b/packages/flutter_tools/test/general.shard/channel_test.dart index c2a474815e..ad9b4c6b04 100644 --- a/packages/flutter_tools/test/general.shard/channel_test.dart +++ b/packages/flutter_tools/test/general.shard/channel_test.dart @@ -35,7 +35,10 @@ void main() { // The bots may return an empty list of channels (network hiccup?) // and when run locally the list of branches might be different // so we check for the header text rather than any specific channel name. - expect(testLogger.statusText, contains('Flutter channels:')); + expect( + testLogger.statusText, + containsIgnoringWhitespace('Flutter channels:'), + ); } testUsingContext('list', () async { @@ -212,7 +215,10 @@ void main() { environment: anyNamed('environment'), )).called(1); - expect(testLogger.statusText, contains("Switching to flutter channel 'beta'...")); + expect( + testLogger.statusText, + containsIgnoringWhitespace("Switching to flutter channel 'beta'..."), + ); expect(testLogger.errorText, hasLength(0)); when(mockProcessManager.start( @@ -290,12 +296,16 @@ void main() { environment: anyNamed('environment'), )).called(1); - expect(testLogger.statusText, containsIgnoringWhitespace( - "Successfully switched to flutter channel 'beta'.")); - expect(testLogger.statusText, + expect( + testLogger.statusText, + containsIgnoringWhitespace("Successfully switched to flutter channel 'beta'."), + ); + expect( + testLogger.statusText, containsIgnoringWhitespace( "To ensure that you're on the latest build " - "from this channel, run 'flutter upgrade'")); + "from this channel, run 'flutter upgrade'"), + ); expect(testLogger.errorText, hasLength(0)); }, overrides: { FileSystem: () => MemoryFileSystem(), diff --git a/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart b/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart index 5f9c6d7d6e..2ba9a70866 100644 --- a/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart +++ b/packages/flutter_tools/test/general.shard/commands/build_apk_test.dart @@ -375,12 +375,18 @@ void main() { ); }, throwsToolExit(message: 'Gradle task assembleRelease failed with exit code 1')); - expect(testLogger.statusText, - contains('The shrinker may have failed to optimize the Java bytecode.')); - expect(testLogger.statusText, - contains('To disable the shrinker, pass the `--no-shrink` flag to this command.')); - expect(testLogger.statusText, - contains('To learn more, see: https://developer.android.com/studio/build/shrink-code')); + expect( + testLogger.statusText, + containsIgnoringWhitespace('The shrinker may have failed to optimize the Java bytecode.'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('To disable the shrinker, pass the `--no-shrink` flag to this command.'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('To learn more, see: https://developer.android.com/studio/build/shrink-code'), + ); verify(mockUsage.sendEvent( 'build', @@ -433,11 +439,16 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText, containsIgnoringWhitespace("Your app isn't using AndroidX")); - expect(testLogger.statusText, containsIgnoringWhitespace( + expect( + testLogger.statusText, + containsIgnoringWhitespace("Your app isn't using AndroidX"), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace( 'To avoid potential build failures, you can quickly migrate your app by ' 'following the steps on https://goo.gl/CP92wY' - ) + ), ); verify(mockUsage.sendEvent( 'build', diff --git a/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart b/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart index 649a72c5fc..2f38fced65 100644 --- a/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart +++ b/packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart @@ -303,12 +303,18 @@ void main() { ); }, throwsToolExit(message: 'Gradle task bundleRelease failed with exit code 1')); - expect(testLogger.statusText, - contains('The shrinker may have failed to optimize the Java bytecode.')); - expect(testLogger.statusText, - contains('To disable the shrinker, pass the `--no-shrink` flag to this command.')); - expect(testLogger.statusText, - contains('To learn more, see: https://developer.android.com/studio/build/shrink-code')); + expect( + testLogger.statusText, + containsIgnoringWhitespace('The shrinker may have failed to optimize the Java bytecode.'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('To disable the shrinker, pass the `--no-shrink` flag to this command.'), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace('To learn more, see: https://developer.android.com/studio/build/shrink-code'), + ); verify(mockUsage.sendEvent( 'build', @@ -361,11 +367,16 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText, containsIgnoringWhitespace("Your app isn't using AndroidX")); - expect(testLogger.statusText, containsIgnoringWhitespace( + expect( + testLogger.statusText, + containsIgnoringWhitespace("Your app isn't using AndroidX"), + ); + expect( + testLogger.statusText, + containsIgnoringWhitespace( 'To avoid potential build failures, you can quickly migrate your app by ' 'following the steps on https://goo.gl/CP92wY' - ) + ), ); verify(mockUsage.sendEvent( 'build', @@ -412,12 +423,17 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText, - not(containsIgnoringWhitespace("Your app isn't using AndroidX"))); expect( - testLogger.statusText, not(containsIgnoringWhitespace( - 'To avoid potential build failures, you can quickly migrate your app by ' - 'following the steps on https://goo.gl/CP92wY')) + testLogger.statusText, + not(containsIgnoringWhitespace("Your app isn't using AndroidX")), + ); + expect( + testLogger.statusText, + not( + containsIgnoringWhitespace( + 'To avoid potential build failures, you can quickly migrate your app by ' + 'following the steps on https://goo.gl/CP92wY'), + ) ); verify(mockUsage.sendEvent( 'build', diff --git a/packages/flutter_tools/test/general.shard/runner/runner_test.dart b/packages/flutter_tools/test/general.shard/runner/runner_test.dart index 1b33cf13d0..c927d5f38c 100644 --- a/packages/flutter_tools/test/general.shard/runner/runner_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/runner_test.dart @@ -103,7 +103,10 @@ void main() { await completer.future; final String errorText = testLogger.errorText; - expect(errorText, contains('Oops; flutter has exited unexpectedly: "an exception % --".\n')); + expect( + errorText, + containsIgnoringWhitespace('Oops; flutter has exited unexpectedly: "an exception % --".\n'), + ); final File log = globals.fs.file('/flutter_01.log'); final String logContents = log.readAsStringSync();