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 "package:expect/expect.dart"; | 5 import 'dart:async'; |
6 import "compiler_helper.dart"; | 6 import 'package:async_helper/async_helper.dart'; |
7 import "package:async_helper/async_helper.dart"; | 7 import 'package:compiler/src/commandline_options.dart'; |
8 import 'package:compiler/src/diagnostics/messages.dart'; | |
9 import 'package:expect/expect.dart'; | |
10 import 'memory_compiler.dart'; | |
8 | 11 |
9 const String SOURCE = """ | 12 const String SOURCE = """ |
10 class Foo { | 13 class Foo { |
11 // Deliberately not const to ensure compile error. | 14 // Deliberately not const to ensure compile error. |
12 Foo(_); | 15 Foo(_); |
13 } | 16 } |
14 | 17 |
15 @Bar() | 18 @Bar() |
16 class Bar { | 19 class Bar { |
17 const Bar(); | 20 const Bar(); |
18 } | 21 } |
19 | 22 |
20 @Foo('x') | 23 @Foo('x') |
21 typedef void VoidFunction(); | 24 typedef void VoidFunction(); |
22 | 25 |
23 @Foo('y') | 26 @Foo('y') |
24 class MyClass {} | 27 class MyClass {} |
25 | 28 |
26 main() { | 29 main() { |
27 } | 30 } |
28 """; | 31 """; |
29 | 32 |
33 Future<DiagnosticCollector> run( | |
34 String source, | |
35 {bool analyzeAll, | |
36 bool expectSuccess}) async { | |
37 DiagnosticCollector collector = new DiagnosticCollector(); | |
38 | |
39 List<String> options = []; | |
40 if (analyzeAll) { | |
41 options.add(Flags.analyzeAll); | |
42 } else { | |
43 options.add(Flags.analyzeOnly); | |
44 } | |
45 CompilationResult result = await runCompiler( | |
46 memorySourceFiles: {'main.dart': source}, | |
47 diagnosticHandler: collector, | |
48 options: options); | |
49 Expect.equals(expectSuccess, result.isSuccess); | |
50 return collector; | |
51 } | |
52 | |
53 test1() async { | |
54 DiagnosticCollector collector = | |
55 await run(SOURCE, analyzeAll: false, expectSuccess: true); | |
56 Expect.isTrue(collector.warnings.isEmpty, | |
57 'Unexpected warnings: ${collector.warnings}'); | |
58 Expect.isTrue(collector.errors.isEmpty, | |
59 'Unexpected errors: ${collector.errors}'); | |
60 } | |
61 | |
62 test2() async { | |
63 DiagnosticCollector collector = | |
64 await run(SOURCE, analyzeAll: true, expectSuccess: false); | |
65 | |
66 Expect.isTrue(collector.warnings.isEmpty, | |
67 'unexpected warnings: ${collector.warnings}'); | |
68 Expect.equals(2, collector.errors.length, | |
69 'expected exactly two errors, but got ${collector.errors}'); | |
70 | |
71 CollectedMessage first = collector.errors.first; | |
72 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind); | |
73 Expect.equals("Foo", SOURCE.substring(first.begin, first.end)); | |
74 | |
75 CollectedMessage second = collector.errors.elementAt(1); | |
76 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind); | |
77 Expect.equals("Foo", SOURCE.substring(second.begin, second.end)); | |
78 } | |
79 | |
80 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.
| |
81 String source = ''' | |
82 import 'package:expect/expect.dart'; | |
83 | |
84 class A { | |
85 @NoInline | |
86 m() { | |
87 => print(0); | |
88 } | |
89 } | |
90 | |
91 @NoInline() | |
92 main() => new A().m(); | |
93 '''; | |
94 | |
95 DiagnosticCollector collector = | |
96 await run(source, analyzeAll: true, expectSuccess: false); | |
97 | |
98 Expect.isTrue(collector.warnings.isEmpty, | |
99 'unexpected warnings: ${collector.warnings}'); | |
100 Expect.equals(1, collector.errors.length, | |
101 'expected exactly one error, but got ${collector.errors}'); | |
102 } | |
103 | |
30 main() { | 104 main() { |
31 Uri uri = Uri.parse('test:code'); | 105 asyncTest(() async { |
32 var compiler1 = compilerFor(SOURCE, uri, analyzeAll: false); | 106 await test1(); |
33 asyncTest(() => compiler1.run(uri).then((compilationSucceded) { | 107 await test2(); |
34 DiagnosticCollector collector = compiler1.diagnosticCollector; | 108 await test3(); |
35 Expect.isTrue(compilationSucceded); | 109 }); |
36 print(collector.warnings); | |
37 Expect.isTrue(collector.warnings.isEmpty, 'unexpected warnings'); | |
38 Expect.isTrue(collector.errors.isEmpty, 'unexpected errors'); | |
39 })); | |
40 | |
41 var compiler2 = compilerFor(SOURCE, uri, analyzeAll: true); | |
42 asyncTest(() => compiler2.run(uri).then((compilationSucceded) { | |
43 DiagnosticCollector collector = compiler2.diagnosticCollector; | |
44 Expect.isFalse(compilationSucceded); | |
45 Expect.isTrue(collector.warnings.isEmpty, | |
46 'unexpected warnings: ${collector.warnings}'); | |
47 Expect.equals(2, collector.errors.length, | |
48 'expected exactly two errors, but got ${collector.errors}'); | |
49 | |
50 CollectedMessage first = collector.errors.first; | |
51 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, first.message.kind); | |
52 Expect.equals("Foo", SOURCE.substring(first.begin, first.end)); | |
53 | |
54 CollectedMessage second = collector.errors.elementAt(1); | |
55 Expect.equals(MessageKind.CONSTRUCTOR_IS_NOT_CONST, second.message.kind); | |
56 Expect.equals("Foo", SOURCE.substring(second.begin, second.end)); | |
57 })); | |
58 } | 110 } |
OLD | NEW |