OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test that duplicate library names result in different messages depending | 5 // Test that duplicate library names result in different messages depending |
6 // on whether the libraries are based on the same resource. | 6 // on whether the libraries are based on the same resource. |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
11 import 'package:compiler/src/commandline_options.dart'; | 11 import 'package:compiler/src/commandline_options.dart'; |
12 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; | 12 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; |
13 import 'memory_compiler.dart'; | 13 import 'memory_compiler.dart'; |
14 | 14 |
15 void check(String kind, | 15 void check(String kind, Iterable<CollectedMessage> messages, |
16 Iterable<CollectedMessage> messages, | 16 List<MessageKind> expectedMessageKinds) { |
17 List<MessageKind> expectedMessageKinds) { | |
18 Expect.equals(messages.length, expectedMessageKinds.length, | 17 Expect.equals(messages.length, expectedMessageKinds.length, |
19 "Unexpected $kind count: $messages"); | 18 "Unexpected $kind count: $messages"); |
20 int i = 0; | 19 int i = 0; |
21 messages.forEach((CollectedMessage message) { | 20 messages.forEach((CollectedMessage message) { |
22 Expect.equals(expectedMessageKinds[i++], message.messageKind); | 21 Expect.equals(expectedMessageKinds[i++], message.messageKind); |
23 }); | 22 }); |
24 } | 23 } |
25 | 24 |
26 Future test(Map<String, String> source, | 25 Future test(Map<String, String> source, |
27 {List<MessageKind> warnings: const <MessageKind>[], | 26 {List<MessageKind> warnings: const <MessageKind>[], |
28 List<MessageKind> hints: const <MessageKind>[]}) async { | 27 List<MessageKind> hints: const <MessageKind>[]}) async { |
29 DiagnosticCollector collector = new DiagnosticCollector(); | 28 DiagnosticCollector collector = new DiagnosticCollector(); |
30 await runCompiler( | 29 await runCompiler( |
31 memorySourceFiles: source, | 30 memorySourceFiles: source, |
32 diagnosticHandler: collector, | 31 diagnosticHandler: collector, |
33 showDiagnostics: true, | 32 showDiagnostics: true, |
34 options: [Flags.analyzeOnly, Flags.analyzeAll], | 33 options: [Flags.analyzeOnly, Flags.analyzeAll], |
35 packageRoot: Uri.parse('memory:pkg/')); | 34 packageRoot: Uri.parse('memory:pkg/')); |
36 | 35 |
37 Expect.isTrue(collector.errors.isEmpty); | 36 Expect.isTrue(collector.errors.isEmpty); |
38 check('warning', collector.warnings, warnings); | 37 check('warning', collector.warnings, warnings); |
39 check('hint', collector.hints, hints); | 38 check('hint', collector.hints, hints); |
40 Expect.isTrue(collector.infos.isEmpty); | 39 Expect.isTrue(collector.infos.isEmpty); |
41 } | 40 } |
42 | 41 |
43 void main() { | 42 void main() { |
44 asyncTest(runTests); | 43 asyncTest(runTests); |
45 } | 44 } |
46 | 45 |
47 Future runTests() async { | 46 Future runTests() async { |
48 await test({ | 47 await test({ |
49 'main.dart': """ | 48 'main.dart': """ |
50 library main; | 49 library main; |
51 | 50 |
52 import 'package:lib/foo.dart'; | 51 import 'package:lib/foo.dart'; |
53 import 'pkg/lib/foo.dart'; | 52 import 'pkg/lib/foo.dart'; |
54 """, | 53 """, |
55 'pkg/lib/foo.dart': """ | 54 'pkg/lib/foo.dart': """ |
56 library lib.foo; | 55 library lib.foo; |
57 """}, | 56 """ |
58 warnings: [MessageKind.DUPLICATED_LIBRARY_RESOURCE]); | 57 }, warnings: [ |
| 58 MessageKind.DUPLICATED_LIBRARY_RESOURCE |
| 59 ]); |
59 | 60 |
60 await test({ | 61 await test({ |
61 'main.dart': """ | 62 'main.dart': """ |
62 library main; | 63 library main; |
63 | 64 |
64 import 'package:lib/bar.dart'; | 65 import 'package:lib/bar.dart'; |
65 import 'pkg/foo.dart'; | 66 import 'pkg/foo.dart'; |
66 """, | 67 """, |
67 'pkg/foo.dart': """ | 68 'pkg/foo.dart': """ |
68 library foo; | 69 library foo; |
69 | 70 |
70 import 'lib/bar.dart'; | 71 import 'lib/bar.dart'; |
71 """, | 72 """, |
72 'pkg/lib/bar.dart': """ | 73 'pkg/lib/bar.dart': """ |
73 library lib.bar; | 74 library lib.bar; |
74 """}, | 75 """ |
75 warnings: [MessageKind.DUPLICATED_LIBRARY_RESOURCE]); | 76 }, warnings: [ |
| 77 MessageKind.DUPLICATED_LIBRARY_RESOURCE |
| 78 ]); |
76 | 79 |
77 await test({ | 80 await test({ |
78 'main.dart': """ | 81 'main.dart': """ |
79 library main; | 82 library main; |
80 | 83 |
81 import 'foo.dart'; | 84 import 'foo.dart'; |
82 import 'pkg/lib/baz.dart'; | 85 import 'pkg/lib/baz.dart'; |
83 """, | 86 """, |
84 'foo.dart': """ | 87 'foo.dart': """ |
85 library foo; | 88 library foo; |
86 | 89 |
87 import 'package:lib/baz.dart'; | 90 import 'package:lib/baz.dart'; |
88 """, | 91 """, |
89 'pkg/lib/baz.dart': """ | 92 'pkg/lib/baz.dart': """ |
90 library lib.baz; | 93 library lib.baz; |
91 """}, | 94 """ |
92 warnings: [MessageKind.DUPLICATED_LIBRARY_RESOURCE]); | 95 }, warnings: [ |
| 96 MessageKind.DUPLICATED_LIBRARY_RESOURCE |
| 97 ]); |
93 | 98 |
94 await test({ | 99 await test({ |
95 'main.dart': """ | 100 'main.dart': """ |
96 library main; | 101 library main; |
97 | 102 |
98 import 'foo.dart'; | 103 import 'foo.dart'; |
99 import 'pkg/bar.dart'; | 104 import 'pkg/bar.dart'; |
100 """, | 105 """, |
101 'foo.dart': """ | 106 'foo.dart': """ |
102 library foo; | 107 library foo; |
103 | 108 |
104 import 'package:lib/boz.dart'; | 109 import 'package:lib/boz.dart'; |
105 """, | 110 """, |
106 'pkg/bar.dart': """ | 111 'pkg/bar.dart': """ |
107 library bar; | 112 library bar; |
108 | 113 |
109 import 'lib/boz.dart'; | 114 import 'lib/boz.dart'; |
110 """, | 115 """, |
111 'pkg/lib/boz.dart': """ | 116 'pkg/lib/boz.dart': """ |
112 library lib.boz; | 117 library lib.boz; |
113 """}, | 118 """ |
114 warnings: [MessageKind.DUPLICATED_LIBRARY_RESOURCE]); | 119 }, warnings: [ |
| 120 MessageKind.DUPLICATED_LIBRARY_RESOURCE |
| 121 ]); |
115 | 122 |
116 await test({ | 123 await test({ |
117 'main.dart': """ | 124 'main.dart': """ |
118 library main; | 125 library main; |
119 | 126 |
120 import 'package:lib/qux.dart'; | 127 import 'package:lib/qux.dart'; |
121 import 'pkg/lib/qux.dart'; | 128 import 'pkg/lib/qux.dart'; |
122 """, | 129 """, |
123 'pkg/lib/qux.dart': """ | 130 'pkg/lib/qux.dart': """ |
124 // No library tag. | 131 // No library tag. |
125 """}, | 132 """ |
126 hints: [MessageKind.DUPLICATED_RESOURCE]); | 133 }, hints: [ |
| 134 MessageKind.DUPLICATED_RESOURCE |
| 135 ]); |
127 | 136 |
128 await test({ | 137 await test({ |
129 'main.dart': """ | 138 'main.dart': """ |
130 library main; | 139 library main; |
131 | 140 |
132 import 'foo.dart'; | 141 import 'foo.dart'; |
133 import 'bar.dart'; | 142 import 'bar.dart'; |
134 """, | 143 """, |
135 'foo.dart': """ | 144 'foo.dart': """ |
136 library lib; | 145 library lib; |
137 """, | 146 """, |
138 'bar.dart': """ | 147 'bar.dart': """ |
139 library lib; | 148 library lib; |
140 """}, | 149 """ |
141 warnings: [MessageKind.DUPLICATED_LIBRARY_NAME, | 150 }, warnings: [ |
142 MessageKind.DUPLICATED_LIBRARY_NAME]); | 151 MessageKind.DUPLICATED_LIBRARY_NAME, |
| 152 MessageKind.DUPLICATED_LIBRARY_NAME |
| 153 ]); |
143 } | 154 } |
144 | |
OLD | NEW |