mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix/set mocks defaults (#54756)
This commit is contained in:
parent
6a490ed497
commit
d21ab5184a
@ -42,6 +42,7 @@ void main() {
|
|||||||
MockDeviceManager mockDeviceManager;
|
MockDeviceManager mockDeviceManager;
|
||||||
MockFlutterVersion mockStableFlutterVersion;
|
MockFlutterVersion mockStableFlutterVersion;
|
||||||
MockFlutterVersion mockUnstableFlutterVersion;
|
MockFlutterVersion mockUnstableFlutterVersion;
|
||||||
|
MockStdio mockStdio;
|
||||||
|
|
||||||
setUpAll(() {
|
setUpAll(() {
|
||||||
Cache.disableLocking();
|
Cache.disableLocking();
|
||||||
@ -51,6 +52,10 @@ void main() {
|
|||||||
mockUnstableFlutterVersion = MockFlutterVersion(isStable: false);
|
mockUnstableFlutterVersion = MockFlutterVersion(isStable: false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setUp((){
|
||||||
|
mockStdio = MockStdio()..stdout.terminalColumns = 80;
|
||||||
|
});
|
||||||
|
|
||||||
testUsingContext('fails when target not found', () async {
|
testUsingContext('fails when target not found', () async {
|
||||||
final RunCommand command = RunCommand();
|
final RunCommand command = RunCommand();
|
||||||
applyMocksToCommand(command);
|
applyMocksToCommand(command);
|
||||||
@ -145,7 +150,7 @@ void main() {
|
|||||||
FileSystem: () => MemoryFileSystem.test(),
|
FileSystem: () => MemoryFileSystem.test(),
|
||||||
ProcessManager: () => FakeProcessManager.any(),
|
ProcessManager: () => FakeProcessManager.any(),
|
||||||
DeviceManager: () => MockDeviceManager(),
|
DeviceManager: () => MockDeviceManager(),
|
||||||
Stdio: () => MockStdio(),
|
Stdio: () => mockStdio,
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
|
testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
|
||||||
|
@ -22,7 +22,7 @@ void main() {
|
|||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
Cache.disableLocking();
|
Cache.disableLocking();
|
||||||
mockStdio = MockStdio();
|
mockStdio = MockStdio()..stdout.terminalColumns = 80;
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('generates bash initialization script to stdout', () async {
|
testUsingContext('generates bash initialization script to stdout', () async {
|
||||||
|
@ -337,7 +337,7 @@ void main() {
|
|||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
mockProcessManager = MockProcessManager();
|
mockProcessManager = MockProcessManager();
|
||||||
mockStdio = MockStdio();
|
mockStdio = MockStdio()..stdout.terminalColumns = 80;
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('test without bot', () async {
|
testUsingContext('test without bot', () async {
|
||||||
|
@ -290,8 +290,12 @@ void main() {
|
|||||||
environment: anyNamed('environment'),
|
environment: anyNamed('environment'),
|
||||||
)).called(1);
|
)).called(1);
|
||||||
|
|
||||||
expect(testLogger.statusText, contains("Successfully switched to flutter channel 'beta'."));
|
expect(testLogger.statusText, containsIgnoringWhitespace(
|
||||||
expect(testLogger.statusText, contains("To ensure that you're on the latest build from this channel, run 'flutter upgrade'"));
|
"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));
|
expect(testLogger.errorText, hasLength(0));
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
FileSystem: () => MemoryFileSystem(),
|
FileSystem: () => MemoryFileSystem(),
|
||||||
|
@ -433,8 +433,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
}, throwsToolExit());
|
}, throwsToolExit());
|
||||||
|
|
||||||
expect(testLogger.statusText, contains("Your app isn't using AndroidX"));
|
expect(testLogger.statusText, containsIgnoringWhitespace("Your app isn't using AndroidX"));
|
||||||
expect(testLogger.statusText, contains(
|
expect(testLogger.statusText, containsIgnoringWhitespace(
|
||||||
'To avoid potential build failures, you can quickly migrate your app by '
|
'To avoid potential build failures, you can quickly migrate your app by '
|
||||||
'following the steps on https://goo.gl/CP92wY'
|
'following the steps on https://goo.gl/CP92wY'
|
||||||
)
|
)
|
||||||
|
@ -361,8 +361,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
}, throwsToolExit());
|
}, throwsToolExit());
|
||||||
|
|
||||||
expect(testLogger.statusText, contains("Your app isn't using AndroidX"));
|
expect(testLogger.statusText, containsIgnoringWhitespace("Your app isn't using AndroidX"));
|
||||||
expect(testLogger.statusText, contains(
|
expect(testLogger.statusText, containsIgnoringWhitespace(
|
||||||
'To avoid potential build failures, you can quickly migrate your app by '
|
'To avoid potential build failures, you can quickly migrate your app by '
|
||||||
'following the steps on https://goo.gl/CP92wY'
|
'following the steps on https://goo.gl/CP92wY'
|
||||||
)
|
)
|
||||||
@ -412,13 +412,12 @@ void main() {
|
|||||||
);
|
);
|
||||||
}, throwsToolExit());
|
}, throwsToolExit());
|
||||||
|
|
||||||
expect(testLogger.statusText.contains("Your app isn't using AndroidX"), isFalse);
|
expect(testLogger.statusText,
|
||||||
|
not(containsIgnoringWhitespace("Your app isn't using AndroidX")));
|
||||||
expect(
|
expect(
|
||||||
testLogger.statusText.contains(
|
testLogger.statusText, not(containsIgnoringWhitespace(
|
||||||
'To avoid potential build failures, you can quickly migrate your app by '
|
'To avoid potential build failures, you can quickly migrate your app by '
|
||||||
'following the steps on https://goo.gl/CP92wY'
|
'following the steps on https://goo.gl/CP92wY'))
|
||||||
),
|
|
||||||
isFalse,
|
|
||||||
);
|
);
|
||||||
verify(mockUsage.sendEvent(
|
verify(mockUsage.sendEvent(
|
||||||
'build',
|
'build',
|
||||||
@ -451,6 +450,10 @@ Future<BuildAppBundleCommand> runBuildAppBundleCommand(
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matcher not(Matcher target){
|
||||||
|
return isNot(target);
|
||||||
|
}
|
||||||
|
|
||||||
class MockAndroidSdk extends Mock implements AndroidSdk {}
|
class MockAndroidSdk extends Mock implements AndroidSdk {}
|
||||||
class MockProcessManager extends Mock implements ProcessManager {}
|
class MockProcessManager extends Mock implements ProcessManager {}
|
||||||
class MockProcess extends Mock implements Process {}
|
class MockProcess extends Mock implements Process {}
|
||||||
|
62
packages/flutter_tools/test/general.shard/common_test.dart
Normal file
62
packages/flutter_tools/test/general.shard/common_test.dart
Normal file
@ -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!'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -145,6 +145,15 @@ Future<void> expectToolExitLater(Future<dynamic> 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.
|
/// Executes a test body in zone that does not allow context-based injection.
|
||||||
///
|
///
|
||||||
/// For classes which have been refactored to excluded context-based injection
|
/// For classes which have been refactored to excluded context-based injection
|
||||||
|
Loading…
Reference in New Issue
Block a user