Unverified Commit 90233746 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

BuildInfo tests without context (#56329)

parent c587d73e
......@@ -273,11 +273,13 @@ void updateLocalProperties({
final String buildName = validatedBuildNameForPlatform(
TargetPlatform.android_arm,
buildInfo.buildName ?? project.manifest.buildName,
globals.logger,
);
changeIfNecessary('flutter.versionName', buildName);
final String buildNumber = validatedBuildNumberForPlatform(
TargetPlatform.android_arm,
buildInfo.buildNumber ?? project.manifest.buildNumber,
globals.logger,
);
changeIfNecessary('flutter.versionCode', buildNumber?.toString());
}
......
......@@ -5,6 +5,7 @@
import 'package:meta/meta.dart';
import 'base/context.dart';
import 'base/logger.dart';
import 'base/utils.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'globals.dart' as globals;
......@@ -265,7 +266,7 @@ BuildMode getBuildModeForName(String name) {
return BuildMode.fromName(name);
}
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber) {
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
if (buildNumber == null) {
return null;
}
......@@ -286,7 +287,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui
}
tmpBuildNumber = segments.join('.');
if (tmpBuildNumber != buildNumber) {
globals.printTrace('Invalid build-number: $buildNumber for iOS/macOS, overridden by $tmpBuildNumber.\n'
logger.printTrace('Invalid build-number: $buildNumber for iOS/macOS, overridden by $tmpBuildNumber.\n'
'See CFBundleVersion at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
}
return tmpBuildNumber;
......@@ -304,7 +305,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui
}
tmpBuildNumberStr = tmpBuildNumberInt.toString();
if (tmpBuildNumberStr != buildNumber) {
globals.printTrace('Invalid build-number: $buildNumber for Android, overridden by $tmpBuildNumberStr.\n'
logger.printTrace('Invalid build-number: $buildNumber for Android, overridden by $tmpBuildNumberStr.\n'
'See versionCode at https://developer.android.com/studio/publish/versioning');
}
return tmpBuildNumberStr;
......@@ -312,7 +313,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui
return buildNumber;
}
String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName) {
String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) {
if (buildName == null) {
return null;
}
......@@ -333,7 +334,7 @@ String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String build
}
tmpBuildName = segments.join('.');
if (tmpBuildName != buildName) {
globals.printTrace('Invalid build-name: $buildName for iOS/macOS, overridden by $tmpBuildName.\n'
logger.printTrace('Invalid build-name: $buildName for iOS/macOS, overridden by $tmpBuildName.\n'
'See CFBundleShortVersionString at https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html');
}
return tmpBuildName;
......
......@@ -125,7 +125,7 @@ String parsedBuildName({
@required BuildInfo buildInfo,
}) {
final String buildNameToParse = buildInfo?.buildName ?? manifest.buildName;
return validatedBuildNameForPlatform(TargetPlatform.ios, buildNameToParse);
return validatedBuildNameForPlatform(TargetPlatform.ios, buildNameToParse, globals.logger);
}
/// Build number parsed and validated from build info and manifest. Used for CFBundleVersion.
......@@ -134,14 +134,22 @@ String parsedBuildNumber({
@required BuildInfo buildInfo,
}) {
String buildNumberToParse = buildInfo?.buildNumber ?? manifest.buildNumber;
final String buildNumber = validatedBuildNumberForPlatform(TargetPlatform.ios, buildNumberToParse);
final String buildNumber = validatedBuildNumberForPlatform(
TargetPlatform.ios,
buildNumberToParse,
globals.logger,
);
if (buildNumber != null && buildNumber.isNotEmpty) {
return buildNumber;
}
// Drop back to parsing build name if build number is not present. Build number is optional in the manifest, but
// FLUTTER_BUILD_NUMBER is required as the backing value for the required CFBundleVersion.
buildNumberToParse = buildInfo?.buildName ?? manifest.buildName;
return validatedBuildNumberForPlatform(TargetPlatform.ios, buildNumberToParse);
return validatedBuildNumberForPlatform(
TargetPlatform.ios,
buildNumberToParse,
globals.logger,
);
}
/// List of lines of build settings. Example: 'FLUTTER_BUILD_DIR=build'
......
......@@ -3,58 +3,60 @@
// found in the LICENSE file.
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
setUpAll(() { });
BufferLogger logger;
setUp(() {
logger = BufferLogger.test();
});
group('Validate build number', () {
setUp(() async { });
testUsingContext('CFBundleVersion for iOS', () async {
String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz');
testWithoutContext('CFBundleVersion for iOS', () async {
String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz', logger);
expect(buildName, isNull);
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1');
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1', logger);
expect(buildName, '0.0.1');
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz');
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz', logger);
expect(buildName, '123');
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz');
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
expect(buildName, '123.456');
});
testUsingContext('versionCode for Android', () async {
String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-');
testWithoutContext('versionCode for Android', () async {
String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
expect(buildName, '123');
buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc');
buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc', logger);
expect(buildName, '1');
});
});
group('Validate build name', () {
setUp(() async { });
testUsingContext('CFBundleShortVersionString for iOS', () async {
String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz');
testWithoutContext('CFBundleShortVersionString for iOS', () async {
String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz', logger);
expect(buildName, isNull);
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1');
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1', logger);
expect(buildName, '0.0.1');
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz');
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
expect(logger.traceText, contains('Invalid build-name'));
expect(buildName, '123.456.0');
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz');
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz', logger);
expect(buildName, '123.0.0');
});
testUsingContext('versionName for Android', () async {
String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-');
testWithoutContext('versionName for Android', () async {
String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
expect(buildName, '123.abc+-');
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-');
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-', logger);
expect(buildName, 'abc+-');
});
test('build mode configuration is correct', () {
testWithoutContext('build mode configuration is correct', () {
expect(BuildMode.debug.isRelease, false);
expect(BuildMode.debug.isPrecompiled, false);
expect(BuildMode.debug.isJit, true);
......@@ -79,14 +81,14 @@ void main() {
});
});
test('getNameForTargetPlatform on Darwin arches', () {
testWithoutContext('getNameForTargetPlatform on Darwin arches', () {
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64');
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7');
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.x86_64), 'ios-x86_64');
expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios')));
});
test('getIOSArchForName on Darwin arches', () {
testWithoutContext('getIOSArchForName on Darwin arches', () {
expect(getIOSArchForName('armv7'), DarwinArch.armv7);
expect(getIOSArchForName('arm64'), DarwinArch.arm64);
expect(getIOSArchForName('arm64e'), DarwinArch.arm64);
......@@ -94,7 +96,7 @@ void main() {
expect(() => getIOSArchForName('bogus'), throwsException);
});
test('toEnvironmentConfig encoding of standard values', () {
testWithoutContext('toEnvironmentConfig encoding of standard values', () {
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
treeShakeIcons: true,
trackWidgetCreation: true,
......
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