mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Update integration tests.
This commit is contained in:
parent
0f8c072054
commit
6e9a411765
@ -104,7 +104,7 @@ Future<TaskResult> _testInstallBogusFlavor() async {
|
||||
Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
final Device device = await devices.workingDevice;
|
||||
await inDirectory(projectDir, () async {
|
||||
// This will put FLAVOR=free in the Flutter/Generated.xcconfig file
|
||||
// This will put DART_DEFINES=FLUTTER_APP_FLAVOR=free in the Flutter/Generated.xcconfig file
|
||||
await flutter(
|
||||
'build',
|
||||
options: <String>['ios', '--config-only', '--debug', '--flavor', 'free'],
|
||||
@ -112,12 +112,7 @@ Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
});
|
||||
|
||||
final File generatedXcconfig = File(path.join(projectDir, 'ios/Flutter/Generated.xcconfig'));
|
||||
if (!generatedXcconfig.existsSync()) {
|
||||
throw TaskResult.failure('Unable to find Generated.xcconfig');
|
||||
}
|
||||
if (!generatedXcconfig.readAsStringSync().contains('FLAVOR=free')) {
|
||||
throw TaskResult.failure('Generated.xcconfig does not contain FLAVOR=free');
|
||||
}
|
||||
await checkFlavorInGeneratedXCConfig(generatedXcconfig, expectedFlavor: 'free');
|
||||
|
||||
const String configuration = 'Debug Paid';
|
||||
const String productName = 'Paid App';
|
||||
@ -147,9 +142,7 @@ Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
throw TaskResult.failure('App not found at $appPath');
|
||||
}
|
||||
|
||||
if (!generatedXcconfig.readAsStringSync().contains('FLAVOR=free')) {
|
||||
throw TaskResult.failure('Generated.xcconfig does not contain FLAVOR=free');
|
||||
}
|
||||
await checkFlavorInGeneratedXCConfig(generatedXcconfig, expectedFlavor: 'free');
|
||||
|
||||
// Despite FLAVOR=free being in the Generated.xcconfig, the flavor found in
|
||||
// the test should be "paid" because it was built with the "Debug Paid" configuration.
|
||||
|
@ -92,7 +92,7 @@ Future<void> main() async {
|
||||
|
||||
Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
await inDirectory(projectDir, () async {
|
||||
// This will put FLAVOR=free in the Flutter/ephemeral/Flutter-Generated.xcconfig file
|
||||
// This will put DART_DEFINES=FLUTTER_APP_FLAVOR=free in the Flutter/ephemeral/Flutter-Generated.xcconfig file
|
||||
await flutter(
|
||||
'build',
|
||||
options: <String>['macos', '--config-only', '--debug', '--flavor', 'free'],
|
||||
@ -102,12 +102,7 @@ Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
final File generatedXcconfig = File(
|
||||
path.join(projectDir, 'macos/Flutter/ephemeral/Flutter-Generated.xcconfig'),
|
||||
);
|
||||
if (!generatedXcconfig.existsSync()) {
|
||||
throw TaskResult.failure('Unable to find Generated.xcconfig');
|
||||
}
|
||||
if (!generatedXcconfig.readAsStringSync().contains('FLAVOR=free')) {
|
||||
throw TaskResult.failure('Generated.xcconfig does not contain FLAVOR=free');
|
||||
}
|
||||
await checkFlavorInGeneratedXCConfig(generatedXcconfig, expectedFlavor: 'free');
|
||||
|
||||
const String configuration = 'Debug-paid';
|
||||
const String productName = 'Debug Paid';
|
||||
@ -138,9 +133,7 @@ Future<TaskResult> _testFlavorWhenBuiltFromXcode(String projectDir) async {
|
||||
throw TaskResult.failure('App not found at $appPath');
|
||||
}
|
||||
|
||||
if (!generatedXcconfig.readAsStringSync().contains('FLAVOR=free')) {
|
||||
throw TaskResult.failure('Generated.xcconfig does not contain FLAVOR=free');
|
||||
}
|
||||
await checkFlavorInGeneratedXCConfig(generatedXcconfig, expectedFlavor: 'free');
|
||||
|
||||
// Despite FLAVOR=free being in the Generated.xcconfig, the flavor found in
|
||||
// the test should be "paid" because it was built with the "Debug-paid" configuration.
|
||||
|
@ -8,6 +8,7 @@ import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'host_agent.dart';
|
||||
import 'task_result.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
typedef SimulatorFunction = Future<void> Function(String deviceId);
|
||||
@ -295,3 +296,54 @@ File? _createDisabledSandboxEntitlementFile(String platformDirectory, String con
|
||||
Future<String> dumpSymbolTable(String filePath) {
|
||||
return eval('nm', <String>['--extern-only', '--just-symbol-name', filePath, '-arch', 'arm64']);
|
||||
}
|
||||
|
||||
/// Given a `Flutter-Generated.xcconfig` file, checks for `DART_DEFINES=<FLUTTER_APP_FLAVOR=$expectedFlavor>`.
|
||||
Future<void> checkFlavorInGeneratedXCConfig(
|
||||
File generatedXcconfig, {
|
||||
required String expectedFlavor,
|
||||
}) async {
|
||||
if (!generatedXcconfig.existsSync()) {
|
||||
throw TaskResult.failure('Unable to find Generated.xcconfig');
|
||||
}
|
||||
final Map<String, String> generatedXcconfigVars = _extractFlutterGeneratedXCConfig(
|
||||
generatedXcconfig,
|
||||
);
|
||||
if (!generatedXcconfigVars.containsKey('DART_DEFINES')) {
|
||||
throw TaskResult.failure('Unable to find DART_DEFINES=... in $generatedXcconfigVars');
|
||||
}
|
||||
final Map<String, String> dartDefines = _decodeBase64DartDefines(
|
||||
generatedXcconfigVars['DART_DEFINES']!,
|
||||
);
|
||||
if (dartDefines['FLUTTER_APP_FLAVOR'] != expectedFlavor) {
|
||||
throw TaskResult.failure('Unable to find FLUTTER_APP_FLAVOR=$expectedFlavor in $dartDefines');
|
||||
}
|
||||
}
|
||||
|
||||
final RegExp _defineVar = RegExp(r'^([A-Z_][A-Z0-9_]*)=(.*)$');
|
||||
|
||||
(String, String)? _toPair(String define) {
|
||||
final RegExpMatch? match = _defineVar.firstMatch(define);
|
||||
if (match == null) {
|
||||
return null;
|
||||
}
|
||||
final String key = match.group(1)!;
|
||||
final String value = match.group(2)!;
|
||||
return (key, value);
|
||||
}
|
||||
|
||||
/// Extracts key-value pairs defined in a `Flutter-Generated.xcconfig` file.
|
||||
Map<String, String> _extractFlutterGeneratedXCConfig(File file) {
|
||||
return <String, String>{
|
||||
for (final String line in file.readAsLinesSync())
|
||||
if (_toPair(line) case (final String key, final String value)) key: value,
|
||||
};
|
||||
}
|
||||
|
||||
/// Decodes an encoded `DART_DEFINES` string into individual definitions.
|
||||
Map<String, String> _decodeBase64DartDefines(String base64EncodedDefines) {
|
||||
return <String, String>{
|
||||
for (final String define in base64EncodedDefines.split(','))
|
||||
if (_toPair(utf8.decode(base64Decode(define))) case (final String key, final String value))
|
||||
key: value,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user