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

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

Issue 1513263002: Support optional package name arguments to --show-package-warnings (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 | « tests/compiler/dart2js/mock_compiler.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) 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 the '--show-package-warnings' option works as intended. 5 // Test that the '--show-package-warnings' option works as intended.
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/commandline_options.dart'; 10 import 'package:compiler/src/commandline_options.dart';
11 import 'memory_compiler.dart'; 11 import 'memory_compiler.dart';
12 12
13 /// Error code that creates 1 warning, 1 hint, and 1 info. 13 /// Error code that creates 1 warning, 1 hint, and 1 info.
14 const ERROR_CODE = """ 14 const ERROR_CODE = """
15 m(Object o) { 15 m(Object o) {
16 if (o is String) { 16 if (o is String) {
17 o = o.length; 17 o = o.length;
18 } 18 }
19 }"""; 19 }""";
20 20
21 const SOURCE = const { 21 const SOURCE = const {
22 'main.dart': """ 22 'main.dart': """
23 import 'package:pkg_error1/pkg_error1.dart'; 23 import 'package:pkg_error1/pkg_error1.dart' as pkg1;
24 import 'package:pkg_error2/pkg_error2.dart'; 24 import 'package:pkg_error2/pkg_error2.dart' as pkg2;
25 import 'package:pkg_noerror/pkg_noerror.dart'; 25 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3;
26 import 'error.dart'; 26 import 'error.dart' as error;
27
28 main() {
29 pkg1.m(null);
30 pkg2.m(null);
31 pkg3.m(null);
32 error.m(null);
33 }
27 """, 34 """,
28 35
29 'error.dart': ERROR_CODE, 36 'error.dart': ERROR_CODE,
30 37
31 'pkg/pkg_error1/pkg_error1.dart': """ 38 'pkg/pkg_error1/pkg_error1.dart': """
32 import 'package:pkg_error2/pkg_error2.dart'; 39 import 'package:pkg_error2/pkg_error2.dart' as pkg2;
33 import 'package:pkg_noerror/pkg_noerror.dart'; 40 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3;
34 $ERROR_CODE""", 41 $ERROR_CODE
42
43 main() {
44 m(null);
45 pkg2.m(null);
46 pkg3.m(null);
47 }
48 """,
35 49
36 'pkg/pkg_error2/pkg_error2.dart': """ 50 'pkg/pkg_error2/pkg_error2.dart': """
37 import 'package:pkg_error1/pkg_error1.dart'; 51 import 'package:pkg_error1/pkg_error1.dart' as pkg1;
38 import 'package:pkg_noerror/pkg_noerror.dart'; 52 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3;
39 $ERROR_CODE""", 53 $ERROR_CODE
54
55 main() {
56 pkg1.m(null);
57 m(null);
58 pkg3.m(null);
59 }
60 """,
40 61
41 'pkg/pkg_noerror/pkg_noerror.dart': """ 62 'pkg/pkg_noerror/pkg_noerror.dart': """
42 import 'package:pkg_error1/pkg_error1.dart'; 63 import 'package:pkg_error1/pkg_error1.dart' as pkg1;
43 import 'package:pkg_error2/pkg_error2.dart'; 64 import 'package:pkg_error2/pkg_error2.dart' as pkg2;
65 m(o) {}
66
67 main() {
68 pkg1.m(null);
69 m(null);
70 pkg2.m(null);
71 }
44 """}; 72 """};
45 73
46 Future test(Uri entryPoint, 74 Future test(Uri entryPoint,
47 {bool showPackageWarnings: false, 75 {List<String> showPackageWarnings: null,
48 int warnings: 0, 76 int warnings: 0,
49 int hints: 0, 77 int hints: 0,
50 int infos: 0}) async { 78 int infos: 0}) async {
51 var options = [Flags.analyzeOnly, Flags.analyzeAll]; 79 var options = [Flags.analyzeOnly];
52 if (showPackageWarnings) { 80 if (showPackageWarnings != null) {
53 options.add(Flags.showPackageWarnings); 81 if (showPackageWarnings.isEmpty) {
82 options.add(Flags.showPackageWarnings);
83 } else {
84 options.add(
85 '${Flags.showPackageWarnings}=${showPackageWarnings.join(',')}');
86 }
54 } 87 }
55 var collector = new DiagnosticCollector(); 88 var collector = new DiagnosticCollector();
89 print('==================================================================');
90 print('test: $entryPoint showPackageWarnings=$showPackageWarnings');
91 print('------------------------------------------------------------------');
56 await runCompiler( 92 await runCompiler(
57 entryPoint: entryPoint, 93 entryPoint: entryPoint,
58 memorySourceFiles: SOURCE, 94 memorySourceFiles: SOURCE,
59 options: options, 95 options: options,
60 packageRoot: Uri.parse('memory:pkg/'), 96 packageRoot: Uri.parse('memory:pkg/'),
61 diagnosticHandler: collector); 97 diagnosticHandler: collector);
62 print('==================================================================');
63 print('test: $entryPoint showPackageWarnings=$showPackageWarnings');
64 Expect.equals(0, collector.errors.length, 98 Expect.equals(0, collector.errors.length,
65 'Unexpected errors: ${collector.errors}'); 99 'Unexpected errors: ${collector.errors}');
66 Expect.equals(warnings, collector.warnings.length, 100 Expect.equals(warnings, collector.warnings.length,
67 'Unexpected warnings: ${collector.warnings}'); 101 'Unexpected warnings: ${collector.warnings}');
68 checkUriSchemes(collector.warnings); 102 checkUriSchemes(collector.warnings);
69 Expect.equals(hints, collector.hints.length, 103 Expect.equals(hints, collector.hints.length,
70 'Unexpected hints: ${collector.hints}'); 104 'Unexpected hints: ${collector.hints}');
71 checkUriSchemes(collector.hints); 105 checkUriSchemes(collector.hints);
72 Expect.equals(infos, collector.infos.length, 106 Expect.equals(infos, collector.infos.length,
73 'Unexpected infos: ${collector.infos}'); 107 'Unexpected infos: ${collector.infos}');
74 checkUriSchemes(collector.infos); 108 checkUriSchemes(collector.infos);
75 print('==================================================================');
76 } 109 }
77 110
78 void checkUriSchemes(Iterable<CollectedMessage> messages) { 111 void checkUriSchemes(Iterable<CollectedMessage> messages) {
79 for (CollectedMessage message in messages) { 112 for (CollectedMessage message in messages) {
80 if (message.uri != null) { 113 if (message.uri != null) {
81 Expect.notEquals('package', message.uri.scheme, 114 Expect.notEquals('package', message.uri.scheme,
82 "Unexpected package uri `${message.uri}` in message: $message"); 115 "Unexpected package uri `${message.uri}` in message: $message");
83 } 116 }
84 } 117 }
85 } 118 }
86 119
87 void main() { 120 void main() {
88 asyncTest(() async { 121 asyncTest(() async {
89 await test( 122 await test(
90 Uri.parse('memory:main.dart'), 123 Uri.parse('memory:main.dart'),
91 showPackageWarnings: true, 124 showPackageWarnings: [],
92 // From error.dart, package:pkg_error1 and package:pkg_error2: 125 // From error.dart, package:pkg_error1 and package:pkg_error2:
93 warnings: 3, hints: 3, infos: 3); 126 warnings: 3, hints: 3, infos: 3);
94 await test( 127 await test(
95 Uri.parse('memory:main.dart'), 128 Uri.parse('memory:main.dart'),
96 showPackageWarnings: false, 129 showPackageWarnings: ['pkg_error1'],
130 // From error.dart and package:pkg_error1:
131 warnings: 2, hints: 2 + 1 /* from summary */, infos: 2);
132 await test(
133 Uri.parse('memory:main.dart'),
134 showPackageWarnings: ['pkg_error1', 'pkg_error2'],
135 // From error.dart, package:pkg_error1 and package:pkg_error2:
136 warnings: 3, hints: 3, infos: 3);
137 await test(
138 Uri.parse('memory:main.dart'),
139 showPackageWarnings: [],
140 // From error.dart, package:pkg_error1 and package:pkg_error2:
141 warnings: 3, hints: 3, infos: 3);
142 await test(
143 Uri.parse('memory:main.dart'),
144 showPackageWarnings: null,
97 // From error.dart only: 145 // From error.dart only:
98 warnings: 1, hints: 1 + 2 /* from summary */, infos: 1); 146 warnings: 1, hints: 1 + 2 /* from summary */, infos: 1);
99 await test( 147 await test(
100 Uri.parse('package:pkg_error1/pkg_error1.dart'), 148 Uri.parse('package:pkg_error1/pkg_error1.dart'),
101 showPackageWarnings: true, 149 showPackageWarnings: [],
102 // From package:pkg_error1 and package:pkg_error2: 150 // From package:pkg_error1 and package:pkg_error2:
103 warnings: 2, hints: 2, infos: 2); 151 warnings: 2, hints: 2, infos: 2);
104 await test( 152 await test(
105 Uri.parse('package:pkg_error1/pkg_error1.dart'), 153 Uri.parse('package:pkg_error1/pkg_error1.dart'),
106 showPackageWarnings: false, 154 showPackageWarnings: null,
107 // From package:pkg_error1/pkg_error1.dart only: 155 // From package:pkg_error1/pkg_error1.dart only:
108 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1); 156 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1);
109 await test( 157 await test(
110 Uri.parse('package:pkg_noerror/pkg_noerror.dart'), 158 Uri.parse('package:pkg_noerror/pkg_noerror.dart'),
111 showPackageWarnings: true, 159 showPackageWarnings: [],
112 // From package:pkg_error1 and package:pkg_error2: 160 // From package:pkg_error1 and package:pkg_error2:
113 warnings: 2, hints: 2, infos: 2); 161 warnings: 2, hints: 2, infos: 2);
114 await test( 162 await test(
115 Uri.parse('package:pkg_noerror/pkg_noerror.dart'), 163 Uri.parse('package:pkg_noerror/pkg_noerror.dart'),
116 showPackageWarnings: false, 164 showPackageWarnings: ['pkg_error1'],
165 // From package:pkg_error1:
166 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1);
167 await test(
168 Uri.parse('package:pkg_noerror/pkg_noerror.dart'),
169 showPackageWarnings: null,
117 hints: 2 /* from summary */); 170 hints: 2 /* from summary */);
118 }); 171 });
119 } 172 }
120 173
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698