[flutter_tool] Additional flutter manifest yaml validation (#37422)

This commit is contained in:
Zachary Anderson 2019-08-05 13:14:57 -07:00 committed by GitHub
parent 4ccd81199f
commit 500d7c50df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -404,7 +404,12 @@ void _validateFonts(YamlList fonts, List<String> errors) {
const Set<int> fontWeights = <int>{
100, 200, 300, 400, 500, 600, 700, 800, 900,
};
for (final YamlMap fontMap in fonts) {
for (final dynamic fontListEntry in fonts) {
if (fontListEntry is! YamlMap) {
errors.add('Unexpected child "$fontListEntry" found under "fonts". Expected a map.');
continue;
}
final YamlMap fontMap = fontListEntry;
for (dynamic key in fontMap.keys.where((dynamic key) => key != 'family' && key != 'fonts')) {
errors.add('Unexpected child "$key" found under "fonts".');
}

View file

@ -518,6 +518,26 @@ flutter:
expect(flutterManifest, null);
expect(logger.errorText, contains('Expected "fonts" to either be null or a list.'));
});
testUsingContext('Returns proper error when second font family is invalid', () async {
final BufferLogger logger = context.get<Logger>();
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: foo
fonts:
- asset: a/bar
- string
''';
final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest);
expect(flutterManifest, null);
expect(logger.errorText, contains('Expected a map.'));
});
});
group('FlutterManifest with MemoryFileSystem', () {