From 12de04ff992aae49709d35ce8841a4f3d79c9ed8 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Wed, 16 Feb 2022 07:33:21 -0800 Subject: [PATCH] await a missed test failure, fix broken test (#3245) This test should be failing but the error is lost because of the way the async failure interacts with the `runBuilder` error handling zone. https://github.com/dart-lang/test/issues/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. --- build_resolvers/test/resolver_test.dart | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/build_resolvers/test/resolver_test.dart b/build_resolvers/test/resolver_test.dart index ad4d60a2c..3d1ba16fd 100644 --- a/build_resolvers/test/resolver_test.dart +++ b/build_resolvers/test/resolver_test.dart @@ -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())); }, resolvers: AnalyzerResolvers()); });