| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'package:compiler/src/commandline_options.dart'; | 7 import 'package:compiler/src/commandline_options.dart'; |
| 8 import 'package:compiler/src/diagnostics/messages.dart'; | 8 import 'package:compiler/src/diagnostics/messages.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'memory_compiler.dart'; | 10 import 'memory_compiler.dart'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 @Foo('x') | 23 @Foo('x') |
| 24 typedef void VoidFunction(); | 24 typedef void VoidFunction(); |
| 25 | 25 |
| 26 @Foo('y') | 26 @Foo('y') |
| 27 class MyClass {} | 27 class MyClass {} |
| 28 | 28 |
| 29 main() { | 29 main() { |
| 30 } | 30 } |
| 31 """; | 31 """; |
| 32 | 32 |
| 33 Future<DiagnosticCollector> run( | 33 Future<DiagnosticCollector> run(String source, |
| 34 String source, | 34 {bool analyzeAll, bool expectSuccess}) async { |
| 35 {bool analyzeAll, | |
| 36 bool expectSuccess}) async { | |
| 37 DiagnosticCollector collector = new DiagnosticCollector(); | 35 DiagnosticCollector collector = new DiagnosticCollector(); |
| 38 | 36 |
| 39 List<String> options = []; | 37 List<String> options = []; |
| 40 if (analyzeAll) { | 38 if (analyzeAll) { |
| 41 options.add(Flags.analyzeAll); | 39 options.add(Flags.analyzeAll); |
| 42 } else { | 40 } else { |
| 43 options.add(Flags.analyzeOnly); | 41 options.add(Flags.analyzeOnly); |
| 44 } | 42 } |
| 45 CompilationResult result = await runCompiler( | 43 CompilationResult result = await runCompiler( |
| 46 memorySourceFiles: {'main.dart': source}, | 44 memorySourceFiles: {'main.dart': source}, |
| 47 diagnosticHandler: collector, | 45 diagnosticHandler: collector, |
| 48 options: options); | 46 options: options); |
| 49 Expect.equals(expectSuccess, result.isSuccess); | 47 Expect.equals(expectSuccess, result.isSuccess); |
| 50 return collector; | 48 return collector; |
| 51 } | 49 } |
| 52 | 50 |
| 53 test1() async { | 51 test1() async { |
| 54 DiagnosticCollector collector = | 52 DiagnosticCollector collector = |
| 55 await run(SOURCE, analyzeAll: false, expectSuccess: true); | 53 await run(SOURCE, analyzeAll: false, expectSuccess: true); |
| 56 Expect.isTrue(collector.warnings.isEmpty, | 54 Expect.isTrue( |
| 57 'Unexpected warnings: ${collector.warnings}'); | 55 collector.warnings.isEmpty, 'Unexpected warnings: ${collector.warnings}'); |
| 58 Expect.isTrue(collector.errors.isEmpty, | 56 Expect.isTrue( |
| 59 'Unexpected errors: ${collector.errors}'); | 57 collector.errors.isEmpty, 'Unexpected errors: ${collector.errors}'); |
| 60 } | 58 } |
| 61 | 59 |
| 62 test2() async { | 60 test2() async { |
| 63 DiagnosticCollector collector = | 61 DiagnosticCollector collector = |
| 64 await run(SOURCE, analyzeAll: true, expectSuccess: false); | 62 await run(SOURCE, analyzeAll: true, expectSuccess: false); |
| 65 | 63 |
| 66 Expect.isTrue(collector.warnings.isEmpty, | 64 Expect.isTrue( |
| 67 'unexpected warnings: ${collector.warnings}'); | 65 collector.warnings.isEmpty, 'unexpected warnings: ${collector.warnings}'); |
| 68 Expect.equals(2, collector.errors.length, | 66 Expect.equals(2, collector.errors.length, |
| 69 'expected exactly two errors, but got ${collector.errors}'); | 67 'expected exactly two errors, but got ${collector.errors}'); |
| 70 | 68 |
| 71 CollectedMessage first = collector.errors.first; | 69 CollectedMessage first = collector.errors.first; |
| 72 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind); | 70 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind); |
| 73 Expect.equals("Foo", SOURCE.substring(first.begin, first.end)); | 71 Expect.equals("Foo", SOURCE.substring(first.begin, first.end)); |
| 74 | 72 |
| 75 CollectedMessage second = collector.errors.elementAt(1); | 73 CollectedMessage second = collector.errors.elementAt(1); |
| 76 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind); | 74 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind); |
| 77 Expect.equals("Foo", SOURCE.substring(second.begin, second.end)); | 75 Expect.equals("Foo", SOURCE.substring(second.begin, second.end)); |
| 78 } | 76 } |
| 79 | 77 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 | 92 |
| 95 @NoInline() | 93 @NoInline() |
| 96 main() => new A().m(); | 94 main() => new A().m(); |
| 97 '''; | 95 '''; |
| 98 | 96 |
| 99 DiagnosticCollector collector = | 97 DiagnosticCollector collector = |
| 100 await run(source, analyzeAll: true, expectSuccess: false); | 98 await run(source, analyzeAll: true, expectSuccess: false); |
| 101 | 99 |
| 102 Expect.isTrue(collector.warnings.isEmpty, | 100 Expect.isTrue( |
| 103 'unexpected warnings: ${collector.warnings}'); | 101 collector.warnings.isEmpty, 'unexpected warnings: ${collector.warnings}'); |
| 104 Expect.equals(1, collector.errors.length, | 102 Expect.equals(1, collector.errors.length, |
| 105 'expected exactly one error, but got ${collector.errors}'); | 103 'expected exactly one error, but got ${collector.errors}'); |
| 106 } | 104 } |
| 107 | 105 |
| 108 main() { | 106 main() { |
| 109 asyncTest(() async { | 107 asyncTest(() async { |
| 110 await test1(); | 108 await test1(); |
| 111 await test2(); | 109 await test2(); |
| 112 await test3(); | 110 await test3(); |
| 113 }); | 111 }); |
| 114 } | 112 } |
| OLD | NEW |