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 ff5178f27e1..6aa596002a8 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/run_test.dart @@ -42,6 +42,7 @@ void main() { MockDeviceManager mockDeviceManager; MockFlutterVersion mockStableFlutterVersion; MockFlutterVersion mockUnstableFlutterVersion; + MockStdio mockStdio; setUpAll(() { Cache.disableLocking(); @@ -51,6 +52,10 @@ void main() { mockUnstableFlutterVersion = MockFlutterVersion(isStable: false); }); + setUp((){ + mockStdio = MockStdio()..stdout.terminalColumns = 80; + }); + testUsingContext('fails when target not found', () async { final RunCommand command = RunCommand(); applyMocksToCommand(command); @@ -145,7 +150,7 @@ void main() { FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), DeviceManager: () => MockDeviceManager(), - Stdio: () => MockStdio(), + Stdio: () => mockStdio, }); testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/shell_completion_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/shell_completion_test.dart index d9bb0a4c87c..5605e44e875 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/shell_completion_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/shell_completion_test.dart @@ -22,7 +22,7 @@ void main() { setUp(() { Cache.disableLocking(); - mockStdio = MockStdio(); + mockStdio = MockStdio()..stdout.terminalColumns = 80; }); testUsingContext('generates bash initialization script to stdout', () async { diff --git a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart index f648e9d1840..97210055ab2 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/packages_test.dart @@ -337,7 +337,7 @@ void main() { setUp(() { mockProcessManager = MockProcessManager(); - mockStdio = MockStdio(); + mockStdio = MockStdio()..stdout.terminalColumns = 80; }); testUsingContext('test without bot', () async { diff --git a/packages/flutter_tools/test/general.shard/channel_test.dart b/packages/flutter_tools/test/general.shard/channel_test.dart index 850ddbf321b..c2a474815eb 100644 --- a/packages/flutter_tools/test/general.shard/channel_test.dart +++ b/packages/flutter_tools/test/general.shard/channel_test.dart @@ -290,8 +290,12 @@ void main() { environment: anyNamed('environment'), )).called(1); - expect(testLogger.statusText, contains("Successfully switched to flutter channel 'beta'.")); - expect(testLogger.statusText, contains("To ensure that you're on the latest build from this channel, run 'flutter upgrade'")); + 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'")); 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 0d619d648e7..5f9c6d7d6ea 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 @@ -433,8 +433,8 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText, contains("Your app isn't using AndroidX")); - expect(testLogger.statusText, contains( + 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' ) 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 0b66e5dc090..649a72c5fca 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 @@ -361,8 +361,8 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText, contains("Your app isn't using AndroidX")); - expect(testLogger.statusText, contains( + 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' ) @@ -412,13 +412,12 @@ void main() { ); }, throwsToolExit()); - expect(testLogger.statusText.contains("Your app isn't using AndroidX"), isFalse); + expect(testLogger.statusText, + not(containsIgnoringWhitespace("Your app isn't using AndroidX"))); expect( - testLogger.statusText.contains( + testLogger.statusText, not(containsIgnoringWhitespace( 'To avoid potential build failures, you can quickly migrate your app by ' - 'following the steps on https://goo.gl/CP92wY' - ), - isFalse, + 'following the steps on https://goo.gl/CP92wY')) ); verify(mockUsage.sendEvent( 'build', @@ -451,6 +450,10 @@ Future runBuildAppBundleCommand( return command; } +Matcher not(Matcher target){ + return isNot(target); +} + class MockAndroidSdk extends Mock implements AndroidSdk {} class MockProcessManager extends Mock implements ProcessManager {} class MockProcess extends Mock implements Process {} diff --git a/packages/flutter_tools/test/general.shard/common_test.dart b/packages/flutter_tools/test/general.shard/common_test.dart new file mode 100644 index 00000000000..0507aecd867 --- /dev/null +++ b/packages/flutter_tools/test/general.shard/common_test.dart @@ -0,0 +1,62 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../src/common.dart'; + +void main() { + group('containsIgnoreWhitespace Matcher', () { + group('on item to be contained', () { + test('matches simple case.', () { + expect('Give me any text!', containsIgnoringWhitespace('any text!')); + }); + + test("shouldn't match when it's only because of removing whitespaces", () { + expect('Give me anytext!', isNot(containsIgnoringWhitespace('any text!'))); + }); + + test('ignores trailing spaces.', () { + expect('Give me any text!', containsIgnoringWhitespace('any text! ')); + }); + + test('ignores leading spaces.', () { + expect('Give me any text!', containsIgnoringWhitespace(' any text!')); + }); + + test('ignores linebreaks.', () { + expect('Give me any text!', containsIgnoringWhitespace('any\n text!')); + }); + + test('ignores tabs.', () { + expect('Give me any text!', containsIgnoringWhitespace('any\t text!')); + }); + + test('is case sensitive.', () { + expect('Give me Any text!', isNot(containsIgnoringWhitespace('any text!'))); + }); + }); + + group('on value to match against', () { + + test('ignores trailing spaces.', () { + expect('Give me any value to include! ', + containsIgnoringWhitespace('any value to include!')); + }); + + test('ignores leading spaces.', () { + expect(' Give me any value to include!', + containsIgnoringWhitespace('any value to include!')); + }); + + test('ignores linebreaks.', () { + expect('Give me \n any \n value \n to \n include!', + containsIgnoringWhitespace('any value to include!')); + }); + + test('ignores tabs.', () { + expect('\tGive\t me any\t value \t to \t include!', + containsIgnoringWhitespace('any value to include!')); + }); + }); + }); +} diff --git a/packages/flutter_tools/test/src/common.dart b/packages/flutter_tools/test/src/common.dart index 8648a12d3c7..ecf413d0723 100644 --- a/packages/flutter_tools/test/src/common.dart +++ b/packages/flutter_tools/test/src/common.dart @@ -145,6 +145,15 @@ Future expectToolExitLater(Future future, Matcher messageMatcher) } } +Matcher containsIgnoringWhitespace(String toSearch) { + return predicate( + (String source) { + return collapseWhitespace(source).contains(collapseWhitespace(toSearch)); + }, + 'contains "$toSearch" ignoring whitespace.', + ); +} + /// Executes a test body in zone that does not allow context-based injection. /// /// For classes which have been refactored to excluded context-based injection