Unverified Commit d457287f authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Migrate more integration tests to process result matcher (#130994)

Part of https://github.com/flutter/flutter/issues/127135
parent 773b667b
...@@ -147,7 +147,7 @@ void main() { ...@@ -147,7 +147,7 @@ void main() {
tempDir.path, tempDir.path,
'--project-name=testapp', '--project-name=testapp',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
// Adds intent filters for app links // Adds intent filters for app links
final String androidManifestPath = fileSystem.path.join(tempDir.path, 'android', 'app', 'src', 'main', 'AndroidManifest.xml'); final String androidManifestPath = fileSystem.path.join(tempDir.path, 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
final io.File androidManifestFile = io.File(androidManifestPath); final io.File androidManifestFile = io.File(androidManifestPath);
...@@ -166,7 +166,7 @@ void main() { ...@@ -166,7 +166,7 @@ void main() {
'apk', 'apk',
'--config-only', '--config-only',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
final Directory androidApp = tempDir.childDirectory('android'); final Directory androidApp = tempDir.childDirectory('android');
result = await processManager.run(<String>[ result = await processManager.run(<String>[
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
'printDebugAppLinkDomains', 'printDebugAppLinkDomains',
], workingDirectory: androidApp.path); ], workingDirectory: androidApp.path);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
const List<String> expectedLines = <String>[ const List<String> expectedLines = <String>[
// Should only pick up the pure and hybrid intent filters // Should only pick up the pure and hybrid intent filters
......
...@@ -35,7 +35,7 @@ void main() { ...@@ -35,7 +35,7 @@ void main() {
tempDir.path, tempDir.path,
'--project-name=testapp', '--project-name=testapp',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
// Ensure that gradle files exists from templates. // Ensure that gradle files exists from templates.
result = await processManager.run(<String>[ result = await processManager.run(<String>[
flutterBin, flutterBin,
...@@ -43,7 +43,7 @@ void main() { ...@@ -43,7 +43,7 @@ void main() {
'apk', 'apk',
'--config-only', '--config-only',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
final Directory androidApp = tempDir.childDirectory('android'); final Directory androidApp = tempDir.childDirectory('android');
result = await processManager.run(<String>[ result = await processManager.run(<String>[
...@@ -53,7 +53,7 @@ void main() { ...@@ -53,7 +53,7 @@ void main() {
'printDebugApplicationId', 'printDebugApplicationId',
], workingDirectory: androidApp.path); ], workingDirectory: androidApp.path);
// Verify that gradlew has a javaVersion task. // Verify that gradlew has a javaVersion task.
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
// Verify the format is a number on its own line. // Verify the format is a number on its own line.
const List<String> expectedLines = <String>[ const List<String> expectedLines = <String>[
'ApplicationId: com.example.testapp', 'ApplicationId: com.example.testapp',
......
...@@ -36,13 +36,7 @@ void main() { ...@@ -36,13 +36,7 @@ void main() {
]; ];
final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory); final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
printOnFailure('Output of flutter build macOS:'); expect(firstRunResult, const ProcessResultMatcher(stdoutPattern: 'Running pod install'));
final String firstRunStdout = firstRunResult.stdout.toString();
printOnFailure('First run stdout: $firstRunStdout');
printOnFailure('First run stderr: ${firstRunResult.stderr}');
expect(firstRunResult.exitCode, 0);
expect(firstRunStdout, contains('Running pod install'));
final File generatedConfig = fileSystem.file(fileSystem.path.join( final File generatedConfig = fileSystem.file(fileSystem.path.join(
workingDirectory, workingDirectory,
...@@ -73,10 +67,7 @@ void main() { ...@@ -73,10 +67,7 @@ void main() {
// Run again with no changes. // Run again with no changes.
final ProcessResult secondRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory); final ProcessResult secondRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
final String secondRunStdout = secondRunResult.stdout.toString();
printOnFailure('Second run stdout: $secondRunStdout');
printOnFailure('Second run stderr: ${secondRunResult.stderr}');
expect(secondRunResult.exitCode, 0); expect(secondRunResult, const ProcessResultMatcher());
}, skip: !platform.isMacOS); // [intended] macOS builds only work on macos. }, skip: !platform.isMacOS); // [intended] macOS builds only work on macos.
} }
...@@ -158,8 +158,10 @@ void main() { ...@@ -158,8 +158,10 @@ void main() {
'--debug-url=http://127.0.0.1:3333*/', '--debug-url=http://127.0.0.1:3333*/',
], workingDirectory: helloWorld); ], workingDirectory: helloWorld);
expect(result.exitCode, 1); expect(
expect(result.stderr, contains('Invalid `--debug-url`: http://127.0.0.1:3333*/')); result,
const ProcessResultMatcher(exitCode: 1, stderrPattern: 'Invalid `--debug-url`: http://127.0.0.1:3333*/'),
);
}); });
testWithoutContext('--debug-uri is an alias for --debug-url', () async { testWithoutContext('--debug-uri is an alias for --debug-url', () async {
...@@ -175,8 +177,14 @@ void main() { ...@@ -175,8 +177,14 @@ void main() {
'--debug-uri=http://127.0.0.1:3333*/', // "uri" not "url" '--debug-uri=http://127.0.0.1:3333*/', // "uri" not "url"
], workingDirectory: helloWorld); ], workingDirectory: helloWorld);
expect(result.exitCode, 1); expect(
expect(result.stderr, contains('Invalid `--debug-url`: http://127.0.0.1:3333*/')); // _"url"_ not "uri"! result,
const ProcessResultMatcher(
exitCode: 1,
// _"url"_ not "uri"!
stderrPattern: 'Invalid `--debug-url`: http://127.0.0.1:3333*/',
),
);
}); });
testWithoutContext('will load bootstrap script before starting', () async { testWithoutContext('will load bootstrap script before starting', () async {
...@@ -211,8 +219,10 @@ void main() { ...@@ -211,8 +219,10 @@ void main() {
'--bundle-sksl-path=foo/bar/baz.json', // This file does not exist. '--bundle-sksl-path=foo/bar/baz.json', // This file does not exist.
], workingDirectory: helloWorld); ], workingDirectory: helloWorld);
expect(result.exitCode, 1); expect(result, const ProcessResultMatcher(
expect(result.stderr, contains('No SkSL shader bundle found at foo/bar/baz.json')); exitCode: 1,
stderrPattern: 'No SkSL shader bundle found at foo/bar/baz.json'),
);
}); });
testWithoutContext('flutter attach does not support --release', () async { testWithoutContext('flutter attach does not support --release', () async {
...@@ -257,7 +267,7 @@ void main() { ...@@ -257,7 +267,7 @@ void main() {
'json', 'json',
], workingDirectory: helloWorld); ], workingDirectory: helloWorld);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
expect(result.stderr, isEmpty); expect(result.stderr, isEmpty);
}); });
} }
...@@ -39,10 +39,7 @@ void main() { ...@@ -39,10 +39,7 @@ void main() {
'--target-platform=android-arm64', '--target-platform=android-arm64',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
printOnFailure('stdout:\n${result.stdout}'); expect(result, const ProcessResultMatcher(stdoutPattern: 'app-release.aab'));
printOnFailure('stderr:\n${result.stderr}');
expect(result.exitCode, 0);
expect(result.stdout.toString(), contains('app-release.aab'));
expect(result.stdout.toString(), contains('Deferred components prebuild validation passed.')); expect(result.stdout.toString(), contains('Deferred components prebuild validation passed.'));
expect(result.stdout.toString(), contains('Deferred components gen_snapshot validation passed.')); expect(result.stdout.toString(), contains('Deferred components gen_snapshot validation passed.'));
...@@ -106,7 +103,7 @@ void main() { ...@@ -106,7 +103,7 @@ void main() {
expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, true); expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, true);
expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true); expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true);
expect(result.exitCode, 0); expect(result, const ProcessResultMatcher());
}); });
testWithoutContext('simple build appbundle no-deferred-components succeeds', () async { testWithoutContext('simple build appbundle no-deferred-components succeeds', () async {
...@@ -121,11 +118,9 @@ void main() { ...@@ -121,11 +118,9 @@ void main() {
'--no-deferred-components', '--no-deferred-components',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
printOnFailure('stdout:\n${result.stdout}'); expect(result, const ProcessResultMatcher(stdoutPattern: 'app-release.aab'));
printOnFailure('stderr:\n${result.stderr}'); expect(result.stdout.toString(), isNot(contains('Deferred components prebuild validation passed.')));
expect(result.stdout.toString().contains('app-release.aab'), true); expect(result.stdout.toString(), isNot(contains('Deferred components gen_snapshot validation passed.')));
expect(result.stdout.toString().contains('Deferred components prebuild validation passed.'), false);
expect(result.stdout.toString().contains('Deferred components gen_snapshot validation passed.'), false);
final String line = result.stdout.toString() final String line = result.stdout.toString()
.split('\n') .split('\n')
...@@ -153,8 +148,6 @@ void main() { ...@@ -153,8 +148,6 @@ void main() {
expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, false); expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, false);
expect(archive.findFile('base/assets/flutter_assets/test_assets/asset2.txt') != null, true); expect(archive.findFile('base/assets/flutter_assets/test_assets/asset2.txt') != null, true);
expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true); expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true);
expect(result.exitCode, 0);
}); });
testWithoutContext('simple build appbundle mismatched golden no-validate-deferred-components succeeds', () async { testWithoutContext('simple build appbundle mismatched golden no-validate-deferred-components succeeds', () async {
...@@ -169,14 +162,13 @@ void main() { ...@@ -169,14 +162,13 @@ void main() {
'--no-validate-deferred-components', '--no-validate-deferred-components',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result, const ProcessResultMatcher(stdoutPattern: 'app-release.aab'));
printOnFailure('stdout:\n${result.stdout}'); printOnFailure('stdout:\n${result.stdout}');
printOnFailure('stderr:\n${result.stderr}'); printOnFailure('stderr:\n${result.stderr}');
expect(result.stdout.toString().contains('app-release.aab'), true); expect(result.stdout.toString(), isNot(contains('Deferred components prebuild validation passed.')));
expect(result.stdout.toString().contains('Deferred components prebuild validation passed.'), false); expect(result.stdout.toString(), isNot(contains('Deferred components gen_snapshot validation passed.')));
expect(result.stdout.toString().contains('Deferred components gen_snapshot validation passed.'), false); expect(result.stdout.toString(), isNot(contains('New loading units were found:')));
expect(result.stdout.toString(), isNot(contains('Previously existing loading units no longer exist:')));
expect(result.stdout.toString().contains('New loading units were found:'), false);
expect(result.stdout.toString().contains('Previously existing loading units no longer exist:'), false);
final String line = result.stdout.toString() final String line = result.stdout.toString()
.split('\n') .split('\n')
...@@ -202,8 +194,6 @@ void main() { ...@@ -202,8 +194,6 @@ void main() {
expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, true); expect(archive.findFile('component1/assets/flutter_assets/test_assets/asset2.txt') != null, true);
expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true); expect(archive.findFile('base/assets/flutter_assets/test_assets/asset1.txt') != null, true);
expect(result.exitCode, 0);
}); });
testWithoutContext('simple build appbundle missing android dynamic feature module fails', () async { testWithoutContext('simple build appbundle missing android dynamic feature module fails', () async {
...@@ -217,16 +207,15 @@ void main() { ...@@ -217,16 +207,15 @@ void main() {
'appbundle', 'appbundle',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.stdout.toString().contains('app-release.aab'), false); expect(result, const ProcessResultMatcher(exitCode: 1, stdoutPattern: 'Newly generated android files:'));
expect(result.stdout.toString().contains('Deferred components prebuild validation passed.'), false);
expect(result.stdout.toString().contains('Deferred components gen_snapshot validation passed.'), false); expect(result.stdout.toString(), isNot(contains('app-release.aab')));
expect(result.stdout.toString(), isNot(contains('Deferred components prebuild validation passed.')));
expect(result.stdout.toString(), isNot(contains('Deferred components gen_snapshot validation passed.')));
expect(result.stdout.toString(), contains('Newly generated android files:'));
final String pathSeparator = fileSystem.path.separator; final String pathSeparator = fileSystem.path.separator;
expect(result.stdout.toString(), contains('build${pathSeparator}android_deferred_components_setup_files${pathSeparator}component1${pathSeparator}build.gradle')); expect(result.stdout.toString(), contains('build${pathSeparator}android_deferred_components_setup_files${pathSeparator}component1${pathSeparator}build.gradle'));
expect(result.stdout.toString(), contains('build${pathSeparator}android_deferred_components_setup_files${pathSeparator}component1${pathSeparator}src${pathSeparator}main${pathSeparator}AndroidManifest.xml')); expect(result.stdout.toString(), contains('build${pathSeparator}android_deferred_components_setup_files${pathSeparator}component1${pathSeparator}src${pathSeparator}main${pathSeparator}AndroidManifest.xml'));
expect(result.exitCode, 1);
}); });
testWithoutContext('simple build appbundle missing golden fails', () async { testWithoutContext('simple build appbundle missing golden fails', () async {
...@@ -240,16 +229,15 @@ void main() { ...@@ -240,16 +229,15 @@ void main() {
'appbundle', 'appbundle',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.stdout.toString().contains('app-release.aab'), false); expect(result, const ProcessResultMatcher(exitCode: 1));
expect(result.stdout.toString().contains('Deferred components prebuild validation passed.'), true); expect(result.stdout.toString(), isNot(contains('app-release.aab')));
expect(result.stdout.toString().contains('Deferred components gen_snapshot validation passed.'), false); expect(result.stdout.toString(), contains('Deferred components prebuild validation passed.'));
expect(result.stdout.toString(), isNot(contains('Deferred components gen_snapshot validation passed.')));
expect(result.stdout.toString(), contains('New loading units were found:')); expect(result.stdout.toString(), contains('New loading units were found:'));
expect(result.stdout.toString(), contains('- package:test/deferred_library.dart')); expect(result.stdout.toString(), contains('- package:test/deferred_library.dart'));
expect(result.stdout.toString().contains('Previously existing loading units no longer exist:'), false); expect(result.stdout.toString(), isNot(contains('Previously existing loading units no longer exist:')));
expect(result.exitCode, 1);
}); });
testWithoutContext('simple build appbundle mismatched golden fails', () async { testWithoutContext('simple build appbundle mismatched golden fails', () async {
...@@ -263,9 +251,15 @@ void main() { ...@@ -263,9 +251,15 @@ void main() {
'appbundle', 'appbundle',
], workingDirectory: tempDir.path); ], workingDirectory: tempDir.path);
expect(result.stdout.toString().contains('app-release.aab'), false); expect(
expect(result.stdout.toString().contains('Deferred components prebuild validation passed.'), true); result,
expect(result.stdout.toString().contains('Deferred components gen_snapshot validation passed.'), false); const ProcessResultMatcher(
exitCode: 1,
stdoutPattern: 'Deferred components prebuild validation passed.',
),
);
expect(result.stdout.toString(), isNot(contains('app-release.aab')));
expect(result.stdout.toString(), isNot(contains('Deferred components gen_snapshot validation passed.')));
expect(result.stdout.toString(), contains('New loading units were found:')); expect(result.stdout.toString(), contains('New loading units were found:'));
expect(result.stdout.toString(), contains('- package:test/deferred_library.dart')); expect(result.stdout.toString(), contains('- package:test/deferred_library.dart'));
...@@ -275,6 +269,5 @@ void main() { ...@@ -275,6 +269,5 @@ void main() {
expect(result.stdout.toString(), contains('This loading unit check will not fail again on the next build attempt')); expect(result.stdout.toString(), contains('This loading unit check will not fail again on the next build attempt'));
expect(result.exitCode, 1);
}); });
} }
...@@ -18,6 +18,7 @@ import 'package:flutter_tools/src/globals.dart' as globals; ...@@ -18,6 +18,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/test_flutter_command_runner.dart'; import '../src/test_flutter_command_runner.dart';
import 'test_utils.dart';
void main() { void main() {
late Directory tempDir; late Directory tempDir;
...@@ -275,7 +276,7 @@ Future<void> _ensureFlutterToolsSnapshot() async { ...@@ -275,7 +276,7 @@ Future<void> _ensureFlutterToolsSnapshot() async {
printOnFailure('Output of dart ${snapshotArgs.join(" ")}:'); printOnFailure('Output of dart ${snapshotArgs.join(" ")}:');
printOnFailure(snapshotResult.stdout.toString()); printOnFailure(snapshotResult.stdout.toString());
printOnFailure(snapshotResult.stderr.toString()); printOnFailure(snapshotResult.stderr.toString());
expect(snapshotResult.exitCode, 0); expect(snapshotResult, const ProcessResultMatcher());
} }
Future<void> _restoreFlutterToolsSnapshot() async { Future<void> _restoreFlutterToolsSnapshot() async {
...@@ -415,10 +416,7 @@ Future<void> _analyzeEntity(FileSystemEntity target) async { ...@@ -415,10 +416,7 @@ Future<void> _analyzeEntity(FileSystemEntity target) async {
args, args,
workingDirectory: target is Directory ? target.path : target.dirname, workingDirectory: target is Directory ? target.path : target.dirname,
); );
printOnFailure('Output of flutter analyze:'); expect(exec, const ProcessResultMatcher());
printOnFailure(exec.stdout.toString());
printOnFailure(exec.stderr.toString());
expect(exec.exitCode, 0);
} }
Future<void> _buildWebProject(Directory workingDir) async { Future<void> _buildWebProject(Directory workingDir) async {
...@@ -445,17 +443,14 @@ Future<void> _runFlutterSnapshot(List<String> flutterCommandArgs, Directory work ...@@ -445,17 +443,14 @@ Future<void> _runFlutterSnapshot(List<String> flutterCommandArgs, Directory work
); );
final List<String> args = <String>[ final List<String> args = <String>[
globals.artifacts!.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
flutterToolsSnapshotPath, flutterToolsSnapshotPath,
...flutterCommandArgs ...flutterCommandArgs
]; ];
final ProcessResult exec = await Process.run( final ProcessResult exec = await globals.processManager.run(
globals.artifacts!.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
args, args,
workingDirectory: workingDir.path, workingDirectory: workingDir.path,
); );
printOnFailure('Output of flutter ${flutterCommandArgs.join(" ")}:'); expect(exec, const ProcessResultMatcher());
printOnFailure(exec.stdout.toString());
printOnFailure(exec.stderr.toString());
expect(exec.exitCode, 0);
} }
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