| Index: tests/compiler/dart2js/analyze_all_test.dart
|
| diff --git a/tests/compiler/dart2js/analyze_all_test.dart b/tests/compiler/dart2js/analyze_all_test.dart
|
| index 2bb4808ee60e3ba4f0ae3c25474233fc8a0cdc43..7039f93229a8362da40809e642d9db7e99e945fa 100644
|
| --- a/tests/compiler/dart2js/analyze_all_test.dart
|
| +++ b/tests/compiler/dart2js/analyze_all_test.dart
|
| @@ -2,9 +2,12 @@
|
| // for details. 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:expect/expect.dart";
|
| -import "compiler_helper.dart";
|
| -import "package:async_helper/async_helper.dart";
|
| +import 'dart:async';
|
| +import 'package:async_helper/async_helper.dart';
|
| +import 'package:compiler/src/commandline_options.dart';
|
| +import 'package:compiler/src/diagnostics/messages.dart';
|
| +import 'package:expect/expect.dart';
|
| +import 'memory_compiler.dart';
|
|
|
| const String SOURCE = """
|
| class Foo {
|
| @@ -27,32 +30,85 @@ main() {
|
| }
|
| """;
|
|
|
| +Future<DiagnosticCollector> run(
|
| + String source,
|
| + {bool analyzeAll,
|
| + bool expectSuccess}) async {
|
| + DiagnosticCollector collector = new DiagnosticCollector();
|
| +
|
| + List<String> options = [];
|
| + if (analyzeAll) {
|
| + options.add(Flags.analyzeAll);
|
| + } else {
|
| + options.add(Flags.analyzeOnly);
|
| + }
|
| + CompilationResult result = await runCompiler(
|
| + memorySourceFiles: {'main.dart': source},
|
| + diagnosticHandler: collector,
|
| + options: options);
|
| + Expect.equals(expectSuccess, result.isSuccess);
|
| + return collector;
|
| +}
|
| +
|
| +test1() async {
|
| + DiagnosticCollector collector =
|
| + await run(SOURCE, analyzeAll: false, expectSuccess: true);
|
| + Expect.isTrue(collector.warnings.isEmpty,
|
| + 'Unexpected warnings: ${collector.warnings}');
|
| + Expect.isTrue(collector.errors.isEmpty,
|
| + 'Unexpected errors: ${collector.errors}');
|
| +}
|
| +
|
| +test2() async {
|
| + DiagnosticCollector collector =
|
| + await run(SOURCE, analyzeAll: true, expectSuccess: false);
|
| +
|
| + Expect.isTrue(collector.warnings.isEmpty,
|
| + 'unexpected warnings: ${collector.warnings}');
|
| + Expect.equals(2, collector.errors.length,
|
| + 'expected exactly two errors, but got ${collector.errors}');
|
| +
|
| + CollectedMessage first = collector.errors.first;
|
| + Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind);
|
| + Expect.equals("Foo", SOURCE.substring(first.begin, first.end));
|
| +
|
| + CollectedMessage second = collector.errors.elementAt(1);
|
| + Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind);
|
| + Expect.equals("Foo", SOURCE.substring(second.begin, second.end));
|
| +}
|
| +
|
| +// This is a regression test, testing that we can handle annotations on
|
| +// malformed elements. Depending on the order of analysis, annotations on such
|
| +// elements might not be resolved which caused a crash when trying to detect
|
| +// a `@NoInline()` annotation.
|
| +test3() async {
|
| + String source = '''
|
| +import 'package:expect/expect.dart';
|
| +
|
| +class A {
|
| + @NoInline
|
| + m() {
|
| + => print(0);
|
| + }
|
| +}
|
| +
|
| +@NoInline()
|
| +main() => new A().m();
|
| +''';
|
| +
|
| + DiagnosticCollector collector =
|
| + await run(source, analyzeAll: true, expectSuccess: false);
|
| +
|
| + Expect.isTrue(collector.warnings.isEmpty,
|
| + 'unexpected warnings: ${collector.warnings}');
|
| + Expect.equals(1, collector.errors.length,
|
| + 'expected exactly one error, but got ${collector.errors}');
|
| +}
|
| +
|
| main() {
|
| - Uri uri = Uri.parse('test:code');
|
| - var compiler1 = compilerFor(SOURCE, uri, analyzeAll: false);
|
| - asyncTest(() => compiler1.run(uri).then((compilationSucceded) {
|
| - DiagnosticCollector collector = compiler1.diagnosticCollector;
|
| - Expect.isTrue(compilationSucceded);
|
| - print(collector.warnings);
|
| - Expect.isTrue(collector.warnings.isEmpty, 'unexpected warnings');
|
| - Expect.isTrue(collector.errors.isEmpty, 'unexpected errors');
|
| - }));
|
| -
|
| - var compiler2 = compilerFor(SOURCE, uri, analyzeAll: true);
|
| - asyncTest(() => compiler2.run(uri).then((compilationSucceded) {
|
| - DiagnosticCollector collector = compiler2.diagnosticCollector;
|
| - Expect.isFalse(compilationSucceded);
|
| - Expect.isTrue(collector.warnings.isEmpty,
|
| - 'unexpected warnings: ${collector.warnings}');
|
| - Expect.equals(2, collector.errors.length,
|
| - 'expected exactly two errors, but got ${collector.errors}');
|
| -
|
| - CollectedMessage first = collector.errors.first;
|
| - Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind);
|
| - Expect.equals("Foo", SOURCE.substring(first.begin, first.end));
|
| -
|
| - CollectedMessage second = collector.errors.elementAt(1);
|
| - Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind);
|
| - Expect.equals("Foo", SOURCE.substring(second.begin, second.end));
|
| - }));
|
| + asyncTest(() async {
|
| + await test1();
|
| + await test2();
|
| + await test3();
|
| + });
|
| }
|
|
|