From cc83f03822c2fbd55aa0225f22db44d2d654db34 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Thu, 15 Jun 2023 13:25:32 -0700 Subject: [PATCH] [flutter_tools] Migrate more integration tests to process result matcher (#128737) Part of https://github.com/flutter/flutter/issues/127135 --- .../commands.shard/hermetic/doctor_test.dart | 1 - .../integration.shard/analyze_once_test.dart | 5 +---- .../android_e2e_api_test.dart | 5 ++--- .../android_gradle_java_version_test.dart | 6 ++--- .../build_ios_config_only_test.dart | 12 ++-------- .../integration.shard/exit_code_test.dart | 10 ++------- .../flutter_build_wasm_test.dart | 2 +- .../flutter_build_windows_test.dart | 22 +++++++++---------- ...ter_build_with_compilation_error_test.dart | 8 ++++--- .../test/integration.shard/test_test.dart | 4 ++-- .../integration.shard/xcode_backend_test.dart | 10 ++++----- 11 files changed, 34 insertions(+), 51 deletions(-) diff --git a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart index 65fe083b2be..0927707d727 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -831,7 +831,6 @@ class FakeAndroidWorkflow extends Fake implements AndroidWorkflow { final bool appliesToHostPlatform; } - class NoOpDoctor implements Doctor { @override bool get canLaunchAnything => true; diff --git a/packages/flutter_tools/test/integration.shard/analyze_once_test.dart b/packages/flutter_tools/test/integration.shard/analyze_once_test.dart index 7424bd4a48e..6c993dd0dae 100644 --- a/packages/flutter_tools/test/integration.shard/analyze_once_test.dart +++ b/packages/flutter_tools/test/integration.shard/analyze_once_test.dart @@ -27,10 +27,7 @@ void main() { '--no-color', ...arguments, ], workingDirectory: projectPath); - printOnFailure('Output of flutter ${arguments.join(" ")}'); - printOnFailure(result.stdout.toString()); - printOnFailure(result.stderr.toString()); - expect(result.exitCode, exitCode, reason: 'Expected to exit with non-zero exit code.'); + expect(result, ProcessResultMatcher(exitCode: exitCode)); assertContains(result.stdout.toString(), statusTextContains); assertContains(result.stdout.toString(), errorTextContains); expect(result.stderr, contains(exitMessageContains)); diff --git a/packages/flutter_tools/test/integration.shard/android_e2e_api_test.dart b/packages/flutter_tools/test/integration.shard/android_e2e_api_test.dart index a409a96fb34..73d11c688b1 100644 --- a/packages/flutter_tools/test/integration.shard/android_e2e_api_test.dart +++ b/packages/flutter_tools/test/integration.shard/android_e2e_api_test.dart @@ -27,7 +27,7 @@ void main() { tempDir.path, '--project-name=testapp', ], workingDirectory: tempDir.path); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); final File api33File = tempDir .childDirectory('android') @@ -68,7 +68,6 @@ public final class Android33Api extends Activity { 'build', 'apk', ], workingDirectory: tempDir.path); - expect(result.exitCode, 0); - expect(result.stdout.toString(), contains('app-release.apk')); + expect(result, const ProcessResultMatcher(stdoutPattern: 'app-release.apk')); }); } diff --git a/packages/flutter_tools/test/integration.shard/android_gradle_java_version_test.dart b/packages/flutter_tools/test/integration.shard/android_gradle_java_version_test.dart index cfc9cef09ac..6dea44867ad 100644 --- a/packages/flutter_tools/test/integration.shard/android_gradle_java_version_test.dart +++ b/packages/flutter_tools/test/integration.shard/android_gradle_java_version_test.dart @@ -32,7 +32,7 @@ void main() { tempDir.path, '--project-name=testapp', ], workingDirectory: tempDir.path); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); // Ensure that gradle files exists from templates. result = await processManager.run([ flutterBin, @@ -40,7 +40,7 @@ void main() { 'apk', '--config-only', ], workingDirectory: tempDir.path); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); final Directory androidApp = tempDir.childDirectory('android'); result = await processManager.run([ @@ -50,7 +50,7 @@ void main() { 'javaVersion', ], workingDirectory: androidApp.path); // 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. expect(result.stdout.toString(), matches(RegExp(r'\d+$', multiLine: true))); }); diff --git a/packages/flutter_tools/test/integration.shard/build_ios_config_only_test.dart b/packages/flutter_tools/test/integration.shard/build_ios_config_only_test.dart index 21d7141da86..86adcfba17f 100644 --- a/packages/flutter_tools/test/integration.shard/build_ios_config_only_test.dart +++ b/packages/flutter_tools/test/integration.shard/build_ios_config_only_test.dart @@ -37,13 +37,7 @@ void main() { ]; final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory); - printOnFailure('Output of flutter build ios:'); - 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')); + expect(firstRunResult, const ProcessResultMatcher(stdoutPattern: 'Running pod install')); final File generatedConfig = fileSystem.file(fileSystem.path.join( workingDirectory, @@ -71,10 +65,8 @@ void main() { // Run again with no changes. 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()); // Do not run "pod install" when nothing changes. expect(secondRunStdout, isNot(contains('pod install'))); }, skip: !platform.isMacOS); // [intended] iOS builds only work on macos. diff --git a/packages/flutter_tools/test/integration.shard/exit_code_test.dart b/packages/flutter_tools/test/integration.shard/exit_code_test.dart index 88d07b3930c..e919a6efc0d 100644 --- a/packages/flutter_tools/test/integration.shard/exit_code_test.dart +++ b/packages/flutter_tools/test/integration.shard/exit_code_test.dart @@ -34,10 +34,7 @@ void main() { fileSystem.path.join(tempDir.path, 'main.dart'), ]); - printOnFailure('Output of dart main.dart:'); - printOnFailure(result.stdout.toString()); - printOnFailure(result.stderr.toString()); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); testWithoutContext('dart.sh/bat can return a non-zero exit code', () async { @@ -54,9 +51,6 @@ void main() { fileSystem.path.join(tempDir.path, 'main.dart'), ]); - printOnFailure('Output of dart main.dart:'); - printOnFailure(result.stdout.toString()); - printOnFailure(result.stderr.toString()); - expect(result.exitCode, 1); + expect(result, const ProcessResultMatcher(exitCode: 1)); }); } diff --git a/packages/flutter_tools/test/integration.shard/flutter_build_wasm_test.dart b/packages/flutter_tools/test/integration.shard/flutter_build_wasm_test.dart index 593aeb3c149..4290db33756 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_build_wasm_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_build_wasm_test.dart @@ -46,7 +46,7 @@ void main() { flutterWebWasm.environmentOverride!: 'true' }, ); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); final Directory appBuildDir = fileSystem.directory(fileSystem.path.join( exampleAppDir.path, diff --git a/packages/flutter_tools/test/integration.shard/flutter_build_windows_test.dart b/packages/flutter_tools/test/integration.shard/flutter_build_windows_test.dart index 8311419c469..c90a940e92d 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_build_windows_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_build_windows_test.dart @@ -26,16 +26,18 @@ void main() { 'bin', 'flutter', ); - processManager.runSync([flutterBin, 'config', + ProcessResult result = processManager.runSync([flutterBin, 'config', '--enable-windows-desktop', ]); + expect(result, const ProcessResultMatcher()); - processManager.runSync([ + result = processManager.runSync([ flutterBin, ...getLocalEngineArguments(), 'create', 'hello', ], workingDirectory: tempDir.path); + expect(result, const ProcessResultMatcher()); projectRoot = tempDir.childDirectory('hello'); @@ -65,8 +67,8 @@ void main() { 'windows', '--no-pub', ], workingDirectory: projectRoot.path); + expect(result, const ProcessResultMatcher()); - expect(result.exitCode, 0); expect(releaseDir, exists); expect(exeFile, exists); @@ -79,7 +81,7 @@ void main() { }); testWithoutContext('flutter build windows sets build name', () { - processManager.runSync([ + final ProcessResult result = processManager.runSync([ flutterBin, ...getLocalEngineArguments(), 'build', @@ -88,6 +90,7 @@ void main() { '--build-name', '1.2.3', ], workingDirectory: projectRoot.path); + expect(result, const ProcessResultMatcher()); final String fileVersion = _getFileVersion(exeFile); final String productVersion = _getProductVersion(exeFile); @@ -97,7 +100,7 @@ void main() { }); testWithoutContext('flutter build windows sets build name and build number', () { - processManager.runSync([ + final ProcessResult result = processManager.runSync([ flutterBin, ...getLocalEngineArguments(), 'build', @@ -108,6 +111,7 @@ void main() { '--build-number', '4', ], workingDirectory: projectRoot.path); + expect(result, const ProcessResultMatcher()); final String fileVersion = _getFileVersion(exeFile); final String productVersion = _getProductVersion(exeFile); @@ -129,9 +133,7 @@ String _getFileVersion(File file) { [] ); - if (result.exitCode != 0) { - throw Exception('GetVersionInfo failed.'); - } + expect(result, const ProcessResultMatcher()); // Trim trailing new line. final String output = result.stdout as String; @@ -144,9 +146,7 @@ String _getProductVersion(File file) { [] ); - if (result.exitCode != 0) { - throw Exception('GetVersionInfo failed.'); - } + expect(result, const ProcessResultMatcher()); // Trim trailing new line. final String output = result.stdout as String; diff --git a/packages/flutter_tools/test/integration.shard/flutter_build_with_compilation_error_test.dart b/packages/flutter_tools/test/integration.shard/flutter_build_with_compilation_error_test.dart index fa997263b5f..36d15e90859 100644 --- a/packages/flutter_tools/test/integration.shard/flutter_build_with_compilation_error_test.dart +++ b/packages/flutter_tools/test/integration.shard/flutter_build_with_compilation_error_test.dart @@ -64,11 +64,13 @@ int x = 'String'; ], workingDirectory: projectRoot.path); expect( - result.stderr, - contains("A value of type 'String' can't be assigned to a variable of type 'int'."), + result, + const ProcessResultMatcher( + exitCode: 1, + stderrPattern: "A value of type 'String' can't be assigned to a variable of type 'int'.", + ), ); expect(result.stderr, isNot(contains("Warning: The 'dart2js' entrypoint script is deprecated"))); - expect(result.exitCode, 1); }); } } diff --git a/packages/flutter_tools/test/integration.shard/test_test.dart b/packages/flutter_tools/test/integration.shard/test_test.dart index a5979e36cb8..86e0d11bdc2 100644 --- a/packages/flutter_tools/test/integration.shard/test_test.dart +++ b/packages/flutter_tools/test/integration.shard/test_test.dart @@ -235,7 +235,7 @@ void main() { if ((result.stderr as String).isNotEmpty) { fail('unexpected error output from test:\n\n${result.stderr}\n-- end stderr --\n\n'); } - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); testWithoutContext('flutter test should run all tests inside of a directory with no trailing slash', () async { @@ -250,7 +250,7 @@ void main() { if ((result.stderr as String).isNotEmpty) { fail('unexpected error output from test:\n\n${result.stderr}\n-- end stderr --\n\n'); } - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); testWithoutContext('flutter gold skips tests where the expectations are missing', () async { diff --git a/packages/flutter_tools/test/integration.shard/xcode_backend_test.dart b/packages/flutter_tools/test/integration.shard/xcode_backend_test.dart index 36cfa614c5a..d34d2426251 100644 --- a/packages/flutter_tools/test/integration.shard/xcode_backend_test.dart +++ b/packages/flutter_tools/test/integration.shard/xcode_backend_test.dart @@ -9,6 +9,7 @@ import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/globals.dart' as globals; import '../src/common.dart'; +import 'test_utils.dart'; const String xcodeBackendPath = 'bin/xcode_backend.sh'; const String xcodeBackendErrorHeader = '========================================================================'; @@ -85,8 +86,7 @@ void main() { 'INFOPLIST_PATH': 'Info.plist', }, ); - expect(result.stdout, contains('Info.plist does not exist.')); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher(stdoutPattern: 'Info.plist does not exist.')); }); const String emptyPlist = ''' @@ -115,7 +115,7 @@ void main() { expect(actualInfoPlist, isNot(contains('dartVmService'))); expect(actualInfoPlist, isNot(contains('NSLocalNetworkUsageDescription'))); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); for (final String buildConfiguration in ['Debug', 'Profile']) { @@ -137,7 +137,7 @@ void main() { expect(actualInfoPlist, contains('dartVmService')); expect(actualInfoPlist, contains('NSLocalNetworkUsageDescription')); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); } @@ -181,7 +181,7 @@ void main() { '''); - expect(result.exitCode, 0); + expect(result, const ProcessResultMatcher()); }); }, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain. }