forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In service of flutter/flutter#143348. **Issue.** The `equals` implementation of `AssetsEntry` is incorrect. It compares `flavors` lists using reference equality. This PR addresses this. This also adds a test to make sure valid asset `flavors` declarations are parsed correctly. While we are here, this PR also includes a couple of refactorings: * `flutter_manifest_test.dart` is a bit large. To better match our style guide, I've factored out some related tests into their own file. * A couple of changes to the `_validateListType` function in `flutter_manifest.dart`: * The function now returns a list of errors instead of accepting a list to append onto. This is more readable and also allows callers to know which errors were found by the call. * The function is renamed to `_validateList` and now accepts an `Object?` instead of an `YamlList`. If the argument is null, an appropriate error message is contained in the output. This saves callers that are only interested in validation from having to write their own null-check, which they all did before. * Some error strings were tweaked for increased readability and/or grammatical correctness.
- Loading branch information
1 parent
4280d29
commit 14bcc69
Showing
5 changed files
with
229 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
packages/flutter_tools/test/general.shard/flutter_manifest_assets_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter_tools/src/base/logger.dart'; | ||
import 'package:flutter_tools/src/flutter_manifest.dart'; | ||
|
||
import '../src/common.dart'; | ||
|
||
void main() { | ||
group('parsing of assets section in flutter manifests', () { | ||
testWithoutContext('ignores empty list of assets', () { | ||
final BufferLogger logger = BufferLogger.test(); | ||
|
||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
assets: [] | ||
'''; | ||
|
||
final FlutterManifest? flutterManifest = FlutterManifest.createFromString( | ||
manifest, | ||
logger: logger, | ||
); | ||
|
||
expect(flutterManifest, isNotNull); | ||
expect(flutterManifest!.assets, isEmpty); | ||
}); | ||
|
||
testWithoutContext('parses two simple asset declarations', () async { | ||
final BufferLogger logger = BufferLogger.test(); | ||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
uses-material-design: true | ||
assets: | ||
- a/foo | ||
- a/bar | ||
'''; | ||
|
||
final FlutterManifest flutterManifest = FlutterManifest.createFromString( | ||
manifest, | ||
logger: logger, | ||
)!; | ||
|
||
expect(flutterManifest.assets, <AssetsEntry>[ | ||
AssetsEntry(uri: Uri.parse('a/foo')), | ||
AssetsEntry(uri: Uri.parse('a/bar')), | ||
]); | ||
}); | ||
|
||
testWithoutContext('does not crash on empty entry', () { | ||
final BufferLogger logger = BufferLogger.test(); | ||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
uses-material-design: true | ||
assets: | ||
- lib/gallery/example_code.dart | ||
- | ||
'''; | ||
|
||
FlutterManifest.createFromString( | ||
manifest, | ||
logger: logger, | ||
); | ||
|
||
expect(logger.errorText, contains('Asset manifest contains a null or empty uri.')); | ||
}); | ||
|
||
testWithoutContext('handles special characters in asset URIs', () { | ||
final BufferLogger logger = BufferLogger.test(); | ||
|
||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
uses-material-design: true | ||
assets: | ||
- lib/gallery/abc#xyz | ||
- lib/gallery/abc?xyz | ||
- lib/gallery/aaa bbb | ||
'''; | ||
|
||
final FlutterManifest flutterManifest = FlutterManifest.createFromString( | ||
manifest, | ||
logger: logger, | ||
)!; | ||
final List<AssetsEntry> assets = flutterManifest.assets; | ||
|
||
expect(assets, <AssetsEntry>[ | ||
AssetsEntry(uri: Uri.parse('lib/gallery/abc%23xyz')), | ||
AssetsEntry(uri: Uri.parse('lib/gallery/abc%3Fxyz')), | ||
AssetsEntry(uri: Uri.parse('lib/gallery/aaa%20bbb')), | ||
]); | ||
}); | ||
|
||
testWithoutContext('parses an asset with flavors', () async { | ||
final BufferLogger logger = BufferLogger.test(); | ||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
uses-material-design: true | ||
assets: | ||
- path: a/foo | ||
flavors: | ||
- apple | ||
- strawberry | ||
'''; | ||
|
||
final FlutterManifest flutterManifest = FlutterManifest.createFromString( | ||
manifest, | ||
logger: logger, | ||
)!; | ||
|
||
expect(flutterManifest.assets, <AssetsEntry>[ | ||
AssetsEntry( | ||
uri: Uri.parse('a/foo'), | ||
flavors: const <String>{'apple', 'strawberry'}, | ||
), | ||
]); | ||
}); | ||
|
||
testWithoutContext("prints an error when an asset entry's flavor is not a string", () async { | ||
final BufferLogger logger = BufferLogger.test(); | ||
|
||
const String manifest = ''' | ||
name: test | ||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
flutter: | ||
uses-material-design: true | ||
assets: | ||
- assets/folder/ | ||
- path: assets/vanilla/ | ||
flavors: | ||
- key1: value1 | ||
key2: value2 | ||
'''; | ||
FlutterManifest.createFromString(manifest, logger: logger); | ||
expect(logger.errorText, contains( | ||
'Asset manifest entry is malformed. ' | ||
'Expected "flavors" entry to be a list of strings.', | ||
)); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.