Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/compiler/dart2js/analyze_all_test.dart

Issue 1525423002: Handle malformed elements in onElementResolved. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This is a regression test, testing that we can handle annotations on
81 // malformed elements. Depending on the order of analysis, annotations on such
82 // elements might not be resolved which caused a crash when trying to detect
83 // a `@NoInline()` annotation.
84 test3() async {
85 String source = '''
86 import 'package:expect/expect.dart';
87
88 class A {
89 @NoInline
90 m() {
91 => print(0);
92 }
93 }
94
95 @NoInline()
96 main() => new A().m();
97 ''';
98
99 DiagnosticCollector collector =
100 await run(source, analyzeAll: true, expectSuccess: false);
101
102 Expect.isTrue(collector.warnings.isEmpty,
103 'unexpected warnings: ${collector.warnings}');
104 Expect.equals(1, collector.errors.length,
105 'expected exactly one error, but got ${collector.errors}');
106 }
107
30 main() { 108 main() {
31 Uri uri = Uri.parse('test:code'); 109 asyncTest(() async {
32 var compiler1 = compilerFor(SOURCE, uri, analyzeAll: false); 110 await test1();
33 asyncTest(() => compiler1.run(uri).then((compilationSucceded) { 111 await test2();
34 DiagnosticCollector collector = compiler1.diagnosticCollector; 112 await test3();
35 Expect.isTrue(compilationSucceded); 113 });
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 } 114 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698