mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[flutter_tools] Migrate more integration tests to process result matcher (#128737)
Part of https://github.com/flutter/flutter/issues/127135
This commit is contained in:
parent
735fc29622
commit
cc83f03822
@ -831,7 +831,6 @@ class FakeAndroidWorkflow extends Fake implements AndroidWorkflow {
|
||||
final bool appliesToHostPlatform;
|
||||
}
|
||||
|
||||
|
||||
class NoOpDoctor implements Doctor {
|
||||
@override
|
||||
bool get canLaunchAnything => true;
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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'));
|
||||
});
|
||||
}
|
||||
|
||||
@ -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(<String>[
|
||||
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(<String>[
|
||||
@ -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)));
|
||||
});
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -26,16 +26,18 @@ void main() {
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
processManager.runSync(<String>[flutterBin, 'config',
|
||||
ProcessResult result = processManager.runSync(<String>[flutterBin, 'config',
|
||||
'--enable-windows-desktop',
|
||||
]);
|
||||
expect(result, const ProcessResultMatcher());
|
||||
|
||||
processManager.runSync(<String>[
|
||||
result = processManager.runSync(<String>[
|
||||
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(<String>[
|
||||
final ProcessResult result = processManager.runSync(<String>[
|
||||
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(<String>[
|
||||
final ProcessResult result = processManager.runSync(<String>[
|
||||
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) {
|
||||
<String>[]
|
||||
);
|
||||
|
||||
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) {
|
||||
<String>[]
|
||||
);
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
throw Exception('GetVersionInfo failed.');
|
||||
}
|
||||
expect(result, const ProcessResultMatcher());
|
||||
|
||||
// Trim trailing new line.
|
||||
final String output = result.stdout as String;
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 <String>['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() {
|
||||
</dict>
|
||||
</plist>
|
||||
''');
|
||||
expect(result.exitCode, 0);
|
||||
expect(result, const ProcessResultMatcher());
|
||||
});
|
||||
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user