Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] Migrate more integration tests to process result matcher #128737

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ class FakeAndroidWorkflow extends Fake implements AndroidWorkflow {
final bool appliesToHostPlatform;
}


class NoOpDoctor implements Doctor {
@override
bool get canLaunchAnything => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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,
'build',
'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>[
Expand All @@ -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)));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);

Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
4 changes: 2 additions & 2 deletions packages/flutter_tools/test/integration.shard/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '========================================================================';
Expand Down Expand Up @@ -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 = '''
Expand Down Expand Up @@ -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']) {
Expand All @@ -137,7 +137,7 @@ void main() {
expect(actualInfoPlist, contains('dartVmService'));
expect(actualInfoPlist, contains('NSLocalNetworkUsageDescription'));

expect(result.exitCode, 0);
expect(result, const ProcessResultMatcher());
});
}

Expand Down Expand Up @@ -181,7 +181,7 @@ void main() {
</dict>
</plist>
''');
expect(result.exitCode, 0);
expect(result, const ProcessResultMatcher());
});
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.
}