Chromium Code Reviews| 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..596e4a132ba0a8d87a1673167c8cf34ad049760d 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,81 @@ 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)); |
| +} |
| + |
| +test3() async { |
|
sigurdm
2015/12/16 13:20:38
Maybe add a comment that this is a regression test
Johnni Winther
2015/12/18 13:28:17
Done.
|
| + 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(); |
| + }); |
| } |