Unverified Commit ea1b5e3f authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

allow flutterManifest to handle empty lists, add unit tests (#81324)

parent 25c72078
......@@ -495,22 +495,41 @@ void _validateFlutter(YamlMap? yaml, List<String> errors) {
}
break;
case 'assets':
if (yamlValue is! YamlList || yamlValue[0] is! String) {
if (yamlValue is! YamlList) {
errors.add('Expected "$yamlKey" to be a list, but got $yamlValue (${yamlValue.runtimeType}).');
} else if (yamlValue.isEmpty) {
break;
} else if (yamlValue[0] is! String) {
errors.add(
'Expected "$yamlKey" to be a list of strings, but the first element is $yamlValue (${yamlValue.runtimeType}).',
);
}
break;
case 'fonts':
if (yamlValue is! YamlList || yamlValue[0] is! YamlMap) {
if (yamlValue is! YamlList) {
errors.add('Expected "$yamlKey" to be a list, but got $yamlValue (${yamlValue.runtimeType}).');
} else if (yamlValue.isEmpty) {
break;
} else if (yamlValue.first is! YamlMap) {
errors.add(
'Expected "$yamlKey" to contain maps, but the first element is $yamlValue (${yamlValue.runtimeType}).',
);
} else {
_validateFonts(yamlValue, errors);
}
break;
case 'licenses':
if (yamlValue is YamlList) {
_validateListType<String>(yamlValue, errors, '"$yamlKey"', 'files');
} else {
if (yamlValue is! YamlList) {
errors.add('Expected "$yamlKey" to be a list of files, but got $yamlValue (${yamlValue.runtimeType})');
} else if (yamlValue.isEmpty) {
break;
} else if (yamlValue.first is! String) {
errors.add(
'Expected "$yamlKey" to contain strings, but the first element is $yamlValue (${yamlValue.runtimeType}).',
);
} else {
_validateListType<String>(yamlValue, errors, '"$yamlKey"', 'files');
}
break;
case 'module':
......
......@@ -767,6 +767,44 @@ flutter:
contains('Expected "fonts" to either be null or a list.'));
});
testWithoutContext('FlutterManifest ignores empty list of fonts', () {
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
fonts: []
''';
final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, isNotNull);
expect(flutterManifest!.fonts.length, 0);
});
testWithoutContext('FlutterManifest ignores empty list of assets', () {
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
assets: []
''';
final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, isNotNull);
expect(flutterManifest!.assets.length, 0);
});
testWithoutContext('FlutterManifest returns proper error when font detail is '
'not a list of maps', () {
const String manifest = '''
......@@ -1086,6 +1124,25 @@ flutter:
contains('Cannot find the `flutter.plugin.platforms` key in the `pubspec.yaml` file. '));
});
testWithoutContext('FlutterManifest handles empty licenses list', () async {
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
licenses: []
''';
final BufferLogger logger = BufferLogger.test();
final FlutterManifest? flutterManifest = FlutterManifest.createFromString(
manifest,
logger: logger,
);
expect(flutterManifest, isNotNull);
expect(flutterManifest!.additionalLicenses.length, 0);
});
testWithoutContext('FlutterManifest can specify additional LICENSE files', () async {
const String manifest = '''
name: test
......
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