mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[flutter_tools] android test cleanups (#59996)
Fixes several tests that were failing under tester. Minor style cleanups otherwise
This commit is contained in:
parent
a734693ff5
commit
09f1764d14
@ -28,14 +28,12 @@ const Map<String, dynamic> macStudioInfoPlist = <String, dynamic>{
|
||||
},
|
||||
};
|
||||
|
||||
class MockPlistUtils extends Mock implements PlistParser {}
|
||||
final Platform linuxPlatform = FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': homeLinux},
|
||||
);
|
||||
|
||||
Platform linuxPlatform() {
|
||||
return FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': homeLinux},
|
||||
);
|
||||
}
|
||||
class MockPlistUtils extends Mock implements PlistParser {}
|
||||
|
||||
Platform macPlatform() {
|
||||
return FakePlatform(
|
||||
@ -45,45 +43,47 @@ Platform macPlatform() {
|
||||
}
|
||||
|
||||
void main() {
|
||||
MemoryFileSystem fs;
|
||||
MockPlistUtils plistUtils;
|
||||
FileSystem fileSystem;
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem();
|
||||
plistUtils = MockPlistUtils();
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
group('pluginsPath on Linux', () {
|
||||
testUsingContext('extracts custom paths from home dir', () {
|
||||
const String installPath = '/opt/android-studio-with-cheese-5.0';
|
||||
const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
|
||||
const String homeFile = '$studioHome/system/.home';
|
||||
globals.fs.directory(installPath).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).writeAsStringSync(installPath);
|
||||
testUsingContext('pluginsPath on Linux extracts custom paths from home dir', () {
|
||||
const String installPath = '/opt/android-studio-with-cheese-5.0';
|
||||
const String studioHome = '$homeLinux/.AndroidStudioWithCheese5.0';
|
||||
const String homeFile = '$studioHome/system/.home';
|
||||
globals.fs.directory(installPath).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).writeAsStringSync(installPath);
|
||||
|
||||
final AndroidStudio studio =
|
||||
final AndroidStudio studio =
|
||||
AndroidStudio.fromHomeDot(globals.fs.directory(studioHome));
|
||||
expect(studio, isNotNull);
|
||||
expect(studio.pluginsPath,
|
||||
equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
// Custom home paths are not supported on macOS nor Windows yet,
|
||||
// so we force the platform to fake Linux here.
|
||||
Platform: () => linuxPlatform(),
|
||||
});
|
||||
expect(studio, isNotNull);
|
||||
expect(studio.pluginsPath,
|
||||
equals('/home/me/.AndroidStudioWithCheese5.0/config/plugins'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
// Custom home paths are not supported on macOS nor Windows yet,
|
||||
// so we force the platform to fake Linux here.
|
||||
Platform: () => linuxPlatform,
|
||||
FileSystemUtils: () => FileSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
platform: linuxPlatform,
|
||||
),
|
||||
});
|
||||
|
||||
group('pluginsPath on Mac', () {
|
||||
FileSystemUtils fsUtils;
|
||||
Platform platform;
|
||||
MockPlistUtils plistUtils;
|
||||
|
||||
setUp(() {
|
||||
plistUtils = MockPlistUtils();
|
||||
platform = macPlatform();
|
||||
fsUtils = FileSystemUtils(
|
||||
fileSystem: fs,
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
);
|
||||
});
|
||||
@ -110,7 +110,7 @@ void main() {
|
||||
'AndroidStudio3.3',
|
||||
)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
FileSystemUtils: () => fsUtils,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
// Custom home paths are not supported on macOS nor Windows yet,
|
||||
@ -168,7 +168,7 @@ void main() {
|
||||
'AndroidStudio3.3',
|
||||
)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FileSystem: () => fileSystem,
|
||||
FileSystemUtils: () => fsUtils,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
// Custom home paths are not supported on macOS nor Windows yet,
|
||||
@ -176,6 +176,5 @@ void main() {
|
||||
Platform: () => platform,
|
||||
PlistParser: () => plistUtils,
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -17,59 +17,56 @@ import '../../src/context.dart';
|
||||
|
||||
const String home = '/home/me';
|
||||
|
||||
Platform linuxPlatform() {
|
||||
return FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': home}
|
||||
);
|
||||
}
|
||||
final Platform linuxPlatform = FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{'HOME': home}
|
||||
);
|
||||
|
||||
void main() {
|
||||
FileSystem fileSystem;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
group('NoAndroidStudioValidator', () {
|
||||
testUsingContext('shows Android Studio as "not available" when not available.', () async {
|
||||
final NoAndroidStudioValidator validator = NoAndroidStudioValidator();
|
||||
expect((await validator.validate()).type, equals(ValidationType.notAvailable));
|
||||
}, overrides: <Type, Generator>{
|
||||
// Custom home paths are not supported on macOS nor Windows yet,
|
||||
// so we force the platform to fake Linux here.
|
||||
Platform: () => linuxPlatform(),
|
||||
Platform: () => linuxPlatform,
|
||||
});
|
||||
});
|
||||
|
||||
group('AndroidStudioValidator', () {
|
||||
MemoryFileSystem fs;
|
||||
MockProcessManager mockProcessManager;
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem();
|
||||
mockProcessManager = MockProcessManager();
|
||||
testUsingContext('AndroidStudioValidator gives doctor error on java crash', () async {
|
||||
when(globals.processManager.canRun(any)).thenReturn(true);
|
||||
when(globals.processManager.runSync(any)).thenAnswer((Invocation _) {
|
||||
throw const ProcessException('java', <String>['--version']);
|
||||
});
|
||||
const String installPath = '/opt/android-studio-with-cheese-5.0';
|
||||
const String studioHome = '$home/.AndroidStudioWithCheese5.0';
|
||||
const String homeFile = '$studioHome/system/.home';
|
||||
globals.fs.directory(installPath).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).writeAsStringSync(installPath);
|
||||
|
||||
testUsingContext('gives doctor error on java crash', () async {
|
||||
when(mockProcessManager.canRun(any)).thenReturn(true);
|
||||
when(mockProcessManager.runSync(any)).thenAnswer((Invocation _) {
|
||||
throw const ProcessException('java', <String>['--version']);
|
||||
});
|
||||
const String installPath = '/opt/android-studio-with-cheese-5.0';
|
||||
const String studioHome = '$home/.AndroidStudioWithCheese5.0';
|
||||
const String homeFile = '$studioHome/system/.home';
|
||||
globals.fs.directory(installPath).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).createSync(recursive: true);
|
||||
globals.fs.file(homeFile).writeAsStringSync(installPath);
|
||||
|
||||
// This checks that running the validator doesn't throw an unhandled
|
||||
// exception and that the ProcessException makes it into the error
|
||||
// message list.
|
||||
for (final DoctorValidator validator in AndroidStudioValidator.allValidators) {
|
||||
final ValidationResult result = await validator.validate();
|
||||
expect(result.messages.where((ValidationMessage message) {
|
||||
return message.isError && message.message.contains('ProcessException');
|
||||
}).isNotEmpty, true);
|
||||
}
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => linuxPlatform(),
|
||||
});
|
||||
// This checks that running the validator doesn't throw an unhandled
|
||||
// exception and that the ProcessException makes it into the error
|
||||
// message list.
|
||||
for (final DoctorValidator validator in AndroidStudioValidator.allValidators) {
|
||||
final ValidationResult result = await validator.validate();
|
||||
expect(result.messages.where((ValidationMessage message) {
|
||||
return message.isError && message.message.contains('ProcessException');
|
||||
}).isNotEmpty, true);
|
||||
}
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Platform: () => linuxPlatform,
|
||||
FileSystemUtils: () => FileSystemUtils(
|
||||
fileSystem: fileSystem,
|
||||
platform: linuxPlatform,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ at org.gradle.wrapper.Install.createDist(Install.java:48)
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -80,7 +80,7 @@ at org.gradle.wrapper.Install.createDist(Install.java:48)
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -99,7 +99,7 @@ Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -134,7 +134,7 @@ Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host clos
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -161,7 +161,7 @@ Exception in thread "main" java.io.FileNotFoundException: https://downloads.grad
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -199,7 +199,7 @@ Exception in thread "main" java.net.SocketException: Connection reset
|
||||
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
|
||||
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -224,7 +224,7 @@ A problem occurred configuring root project 'android'.
|
||||
> Could not get resource 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'.
|
||||
> Could not GET 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'. Received status code 504 from server: Gateway Time-out''';
|
||||
|
||||
expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
|
||||
expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry));
|
||||
|
||||
expect(testLogger.errorText,
|
||||
@ -242,7 +242,7 @@ A problem occurred configuring root project 'android'.
|
||||
Permission denied
|
||||
Command: /home/android/gradlew assembleRelease
|
||||
''';
|
||||
expect(testErrorMessage(errorMessage, permissionDeniedErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, permissionDeniedErrorHandler), isTrue);
|
||||
expect(await permissionDeniedErrorHandler.handler(), equals(GradleBuildStatus.exit));
|
||||
|
||||
expect(
|
||||
@ -303,7 +303,7 @@ Command: /home/android/gradlew assembleRelease
|
||||
|
||||
expect(status, equals(GradleBuildStatus.exit));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
@ -335,7 +335,7 @@ Command: /home/android/gradlew assembleRelease
|
||||
|
||||
expect(status, equals(GradleBuildStatus.exit));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
@ -361,7 +361,7 @@ Command: /home/android/gradlew assembleRelease
|
||||
|
||||
expect(status, equals(GradleBuildStatus.exit));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
@ -392,7 +392,7 @@ Command: /home/android/gradlew assembleRelease
|
||||
)).called(1);
|
||||
expect(status, equals(GradleBuildStatus.retryWithAarPlugins));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => MemoryFileSystem(),
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => MockProcessManager(),
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
@ -404,7 +404,7 @@ Command: /home/android/gradlew assembleRelease
|
||||
Permission denied
|
||||
Command: /home/android/gradlew assembleRelease
|
||||
''';
|
||||
expect(testErrorMessage(errorMessage, permissionDeniedErrorHandler), isTrue);
|
||||
expect(formatTestErrorMessage(errorMessage, permissionDeniedErrorHandler), isTrue);
|
||||
});
|
||||
|
||||
testUsingContext('handler', () async {
|
||||
@ -539,6 +539,7 @@ assembleFooTest
|
||||
GradleUtils: () => FakeGradleUtils(),
|
||||
Platform: () => fakePlatform('android'),
|
||||
ProcessManager: () => mockProcessManager,
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
});
|
||||
|
||||
testUsingContext('handler - without flavor', () async {
|
||||
@ -586,13 +587,14 @@ assembleProfile
|
||||
GradleUtils: () => FakeGradleUtils(),
|
||||
Platform: () => fakePlatform('android'),
|
||||
ProcessManager: () => mockProcessManager,
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockUsage extends Mock implements Usage {}
|
||||
|
||||
bool testErrorMessage(String errorMessage, GradleHandledError error) {
|
||||
bool formatTestErrorMessage(String errorMessage, GradleHandledError error) {
|
||||
return errorMessage
|
||||
.split('\n')
|
||||
.any((String line) => error.test(line));
|
||||
@ -600,7 +602,9 @@ bool testErrorMessage(String errorMessage, GradleHandledError error) {
|
||||
|
||||
Platform fakePlatform(String name) {
|
||||
return FakePlatform(
|
||||
environment: <String, String>{},
|
||||
environment: <String, String>{
|
||||
'HOME': '/',
|
||||
},
|
||||
operatingSystem: name,
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user