Unverified Commit bb23a110 authored by Florian Loitsch's avatar Florian Loitsch Committed by GitHub

Fix test (#18603)

Fix test.

This makes the buildbot green again.
parent 08d1ec36
...@@ -12,6 +12,19 @@ import 'package:flutter_devicelab/framework/utils.dart'; ...@@ -12,6 +12,19 @@ import 'package:flutter_devicelab/framework/utils.dart';
String javaHome; String javaHome;
String errorMessage; String errorMessage;
/// Runs the given [testFunction] in a clean temporary directory.
Future<void> runTest(Future<void> testFunction(FlutterProject project, FlutterPluginProject pluginProject)) async {
final Directory tmp = await Directory.systemTemp.createTemp('gradle');
final FlutterProject project = await FlutterProject.create(tmp, 'hello');
final FlutterPluginProject pluginProject = await FlutterPluginProject.create(tmp, 'aaa');
try {
await testFunction(project, pluginProject);
} finally {
project.parent.deleteSync(recursive: true);
}
}
void main() async { void main() async {
await task(() async { await task(() async {
section('Running flutter doctor to get JAVA_HOME'); section('Running flutter doctor to get JAVA_HOME');
...@@ -19,81 +32,101 @@ void main() async { ...@@ -19,81 +32,101 @@ void main() async {
final RegExp javaHomeExtractor = new RegExp(r'Android Studio at (.*)'); final RegExp javaHomeExtractor = new RegExp(r'Android Studio at (.*)');
javaHome = javaHomeExtractor.firstMatch(flutterDoctor).group(1) + '/jre'; javaHome = javaHomeExtractor.firstMatch(flutterDoctor).group(1) + '/jre';
section('Setting up flutter projects');
final Directory tmp = await Directory.systemTemp.createTemp('gradle');
final FlutterProject project = await FlutterProject.create(tmp, 'hello');
final FlutterPluginProject pluginProject = await FlutterPluginProject.create(tmp, 'aaa');
try { try {
section('gradlew assembleDebug'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
await project.runGradleTask('assembleDebug'); section('gradlew assembleDebug');
errorMessage = _validateSnapshotDependency(project, 'build/app.dill'); await project.runGradleTask('assembleDebug');
if (errorMessage != null) { errorMessage = _validateSnapshotDependency(project, 'build/app.dill');
return new TaskResult.failure(errorMessage); if (errorMessage != null) {
} throw new TaskResult.failure(errorMessage);
}
section('gradlew assembleDebug no-preview-dart-2'); });
await project.runGradleTask('assembleDebug', options: <String>['-Ppreview-dart-2=false']);
errorMessage = _validateSnapshotDependency(project, await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
'${project.rootPath}/build/app/intermediates/flutter/debug/snapshot_blob.bin'); section('gradlew assembleDebug no-preview-dart-2');
if (errorMessage != null) { await project.runGradleTask('assembleDebug',
return new TaskResult.failure(errorMessage); options: <String>['-Ppreview-dart-2=false']);
} });
section('gradlew assembleProfile'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
await project.runGradleTask('assembleProfile'); section('gradlew assembleProfile');
await project.runGradleTask('assembleProfile');
section('gradlew assembleRelease'); });
await project.runGradleTask('assembleRelease');
await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
section('gradlew assembleLocal (custom debug build)'); section('gradlew assembleRelease');
await project.addCustomBuildType('local', initWith: 'debug'); await project.runGradleTask('assembleRelease');
await project.runGradleTask('assembleLocal'); });
section('gradlew assembleBeta (custom release build)'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
await project.addCustomBuildType('beta', initWith: 'release'); section('gradlew assembleLocal (custom debug build)');
await project.runGradleTask('assembleBeta'); await project.addCustomBuildType('local', initWith: 'debug');
await project.runGradleTask('assembleLocal');
section('gradlew assembleFreeDebug (product flavor)'); });
await project.addProductFlavor('free');
await project.runGradleTask('assembleFreeDebug'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
section('gradlew assembleBeta (custom release build)');
await project.introduceError(); await project.addCustomBuildType('beta', initWith: 'release');
await project.runGradleTask('assembleBeta');
section('gradlew on build script with error'); });
{
final ProcessResult result = await project.resultOfGradleTask('assembleRelease'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
section('gradlew assembleFreeDebug (product flavor)');
await project.addProductFlavor('free');
await project.runGradleTask('assembleFreeDebug');
await project.introduceError();
});
await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
section('gradlew on build script with error');
final ProcessResult result =
await project.resultOfGradleTask('assembleRelease');
if (result.exitCode == 0) if (result.exitCode == 0)
return _failure('Gradle did not exit with error as expected', result); return _failure(
'Gradle did not exit with error as expected', result);
final String output = result.stdout + '\n' + result.stderr; final String output = result.stdout + '\n' + result.stderr;
if (output.contains('GradleException') || output.contains('Failed to notify') || output.contains('at org.gradle')) if (output.contains('GradleException') ||
return _failure('Gradle output should not contain stacktrace', result); output.contains('Failed to notify') ||
output.contains('at org.gradle'))
return _failure(
'Gradle output should not contain stacktrace', result);
if (!output.contains('Build failed') || !output.contains('builTypes')) if (!output.contains('Build failed') || !output.contains('builTypes'))
return _failure('Gradle output should contain a readable error message', result); return _failure(
} 'Gradle output should contain a readable error message',
result);
});
section('flutter build apk on build script with error'); await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
{ section('flutter build apk on build script with error');
final ProcessResult result = await project.resultOfFlutterCommand('build', <String>['apk']); final ProcessResult result = await project.resultOfFlutterCommand('build', <String>['apk']);
if (result.exitCode == 0) if (result.exitCode == 0)
return _failure('flutter build apk should fail when Gradle does', result); return _failure(
'flutter build apk should fail when Gradle does', result);
final String output = result.stdout + '\n' + result.stderr; final String output = result.stdout + '\n' + result.stderr;
if (!output.contains('Build failed') || !output.contains('builTypes')) if (!output.contains('Build failed') || !output.contains('builTypes'))
return _failure('flutter build apk output should contain a readable Gradle error message', result); return _failure(
'flutter build apk output should contain a readable Gradle error message',
result);
if (_hasMultipleOccurrences(output, 'builTypes')) if (_hasMultipleOccurrences(output, 'builTypes'))
return _failure('flutter build apk should not invoke Gradle repeatedly on error', result); return _failure(
} 'flutter build apk should not invoke Gradle repeatedly on error',
result);
section('gradlew assembleDebug on plugin example'); });
await pluginProject.runGradleTask('assembleDebug');
if (!pluginProject.hasDebugApk) await runTest((FlutterProject project, FlutterPluginProject pluginProject) async {
return new TaskResult.failure('Gradle did not produce an apk file at the expected place'); section('gradlew assembleDebug on plugin example');
await pluginProject.runGradleTask('assembleDebug');
if (!pluginProject.hasDebugApk)
throw new TaskResult.failure(
'Gradle did not produce an apk file at the expected place');
});
return new TaskResult.success(null); return new TaskResult.success(null);
} on TaskResult catch (taskResult) {
return taskResult;
} catch (e) { } catch (e) {
return new TaskResult.failure(e.toString()); return new TaskResult.failure(e.toString());
} finally {
project.parent.deleteSync(recursive: true);
} }
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment