Skip to content

Commit

Permalink
await a missed test failure, fix broken test (#3245)
Browse files Browse the repository at this point in the history
This test should be failing but the error is lost because of the way the
async failure interacts with the `runBuilder` error handling zone.
dart-lang/test#1670

Use `await expectLater` instead of `await expect` to ensure the error is
not lost.

Change the setup for the test to include two imports instead of 1 import
and a local class definition. Move the usage to an annotation so that it
is easy to find from the library using it.
  • Loading branch information
natebosch committed Feb 16, 2022
1 parent 2d36ee3 commit 12de04f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions build_resolvers/test/resolver_test.dart
Expand Up @@ -397,25 +397,29 @@ void main() {
}, resolvers: AnalyzerResolvers());
});

test('assetIdForElement throws for ambigious elements', () {
test('assetIdForElement throws for ambiguous elements', () {
return resolveSources({
'a|lib/a.dart': '''
import 'b.dart';
import 'c.dart';
class SomeClass {}
main() {
SomeClass();
} ''',
@SomeClass()
main() {}
''',
'a|lib/b.dart': '''
class SomeClass {}
''',
'a|lib/c.dart': '''
class SomeClass {}
''',
}, (resolver) async {
var entry = await resolver.libraryFor(AssetId('a', 'lib/a.dart'));
var classDefinition = entry.importedLibraries
.map((l) => l.getType('SomeClass'))
.singleWhere((c) => c != null)!;
expect(() => resolver.assetIdForElement(classDefinition),
final element = entry.topLevelElements
.firstWhere((e) => e is FunctionElement && e.name == 'main')
.metadata
.single
.element!;
await expectLater(() => resolver.assetIdForElement(element),
throwsA(isA<UnresolvableAssetException>()));
}, resolvers: AnalyzerResolvers());
});
Expand Down

0 comments on commit 12de04f

Please sign in to comment.