| 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 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'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; | 25 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; |
| 26 import 'error.dart' as error; | 26 import 'error.dart' as error; |
| 27 | 27 |
| 28 main() { | 28 main() { |
| 29 pkg1.m(null); | 29 pkg1.m(null); |
| 30 pkg2.m(null); | 30 pkg2.m(null); |
| 31 pkg3.m(null); | 31 pkg3.m(null); |
| 32 error.m(null); | 32 error.m(null); |
| 33 } | 33 } |
| 34 """, | 34 """, |
| 35 | |
| 36 'error.dart': ERROR_CODE, | 35 'error.dart': ERROR_CODE, |
| 37 | |
| 38 'pkg/pkg_error1/pkg_error1.dart': """ | 36 'pkg/pkg_error1/pkg_error1.dart': """ |
| 39 import 'package:pkg_error2/pkg_error2.dart' as pkg2; | 37 import 'package:pkg_error2/pkg_error2.dart' as pkg2; |
| 40 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; | 38 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; |
| 41 $ERROR_CODE | 39 $ERROR_CODE |
| 42 | 40 |
| 43 main() { | 41 main() { |
| 44 m(null); | 42 m(null); |
| 45 pkg2.m(null); | 43 pkg2.m(null); |
| 46 pkg3.m(null); | 44 pkg3.m(null); |
| 47 } | 45 } |
| 48 """, | 46 """, |
| 49 | |
| 50 'pkg/pkg_error2/pkg_error2.dart': """ | 47 'pkg/pkg_error2/pkg_error2.dart': """ |
| 51 import 'package:pkg_error1/pkg_error1.dart' as pkg1; | 48 import 'package:pkg_error1/pkg_error1.dart' as pkg1; |
| 52 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; | 49 import 'package:pkg_noerror/pkg_noerror.dart' as pkg3; |
| 53 $ERROR_CODE | 50 $ERROR_CODE |
| 54 | 51 |
| 55 main() { | 52 main() { |
| 56 pkg1.m(null); | 53 pkg1.m(null); |
| 57 m(null); | 54 m(null); |
| 58 pkg3.m(null); | 55 pkg3.m(null); |
| 59 } | 56 } |
| 60 """, | 57 """, |
| 61 | |
| 62 'pkg/pkg_noerror/pkg_noerror.dart': """ | 58 'pkg/pkg_noerror/pkg_noerror.dart': """ |
| 63 import 'package:pkg_error1/pkg_error1.dart' as pkg1; | 59 import 'package:pkg_error1/pkg_error1.dart' as pkg1; |
| 64 import 'package:pkg_error2/pkg_error2.dart' as pkg2; | 60 import 'package:pkg_error2/pkg_error2.dart' as pkg2; |
| 65 m(o) {} | 61 m(o) {} |
| 66 | 62 |
| 67 main() { | 63 main() { |
| 68 pkg1.m(null); | 64 pkg1.m(null); |
| 69 m(null); | 65 m(null); |
| 70 pkg2.m(null); | 66 pkg2.m(null); |
| 71 } | 67 } |
| 72 """}; | 68 """ |
| 69 }; |
| 73 | 70 |
| 74 Future test(Uri entryPoint, | 71 Future test(Uri entryPoint, |
| 75 {List<String> showPackageWarnings: null, | 72 {List<String> showPackageWarnings: null, |
| 76 int warnings: 0, | 73 int warnings: 0, |
| 77 int hints: 0, | 74 int hints: 0, |
| 78 int infos: 0}) async { | 75 int infos: 0}) async { |
| 79 var options = [Flags.analyzeOnly]; | 76 var options = [Flags.analyzeOnly]; |
| 80 if (showPackageWarnings != null) { | 77 if (showPackageWarnings != null) { |
| 81 if (showPackageWarnings.isEmpty) { | 78 if (showPackageWarnings.isEmpty) { |
| 82 options.add(Flags.showPackageWarnings); | 79 options.add(Flags.showPackageWarnings); |
| 83 } else { | 80 } else { |
| 84 options.add( | 81 options |
| 85 '${Flags.showPackageWarnings}=${showPackageWarnings.join(',')}'); | 82 .add('${Flags.showPackageWarnings}=${showPackageWarnings.join(',')}'); |
| 86 } | 83 } |
| 87 } | 84 } |
| 88 var collector = new DiagnosticCollector(); | 85 var collector = new DiagnosticCollector(); |
| 89 print('=================================================================='); | 86 print('=================================================================='); |
| 90 print('test: $entryPoint showPackageWarnings=$showPackageWarnings'); | 87 print('test: $entryPoint showPackageWarnings=$showPackageWarnings'); |
| 91 print('------------------------------------------------------------------'); | 88 print('------------------------------------------------------------------'); |
| 92 await runCompiler( | 89 await runCompiler( |
| 93 entryPoint: entryPoint, | 90 entryPoint: entryPoint, |
| 94 memorySourceFiles: SOURCE, | 91 memorySourceFiles: SOURCE, |
| 95 options: options, | 92 options: options, |
| 96 packageRoot: Uri.parse('memory:pkg/'), | 93 packageRoot: Uri.parse('memory:pkg/'), |
| 97 diagnosticHandler: collector); | 94 diagnosticHandler: collector); |
| 98 Expect.equals(0, collector.errors.length, | 95 Expect.equals( |
| 99 'Unexpected errors: ${collector.errors}'); | 96 0, collector.errors.length, 'Unexpected errors: ${collector.errors}'); |
| 100 Expect.equals(warnings, collector.warnings.length, | 97 Expect.equals(warnings, collector.warnings.length, |
| 101 'Unexpected warnings: ${collector.warnings}'); | 98 'Unexpected warnings: ${collector.warnings}'); |
| 102 checkUriSchemes(collector.warnings); | 99 checkUriSchemes(collector.warnings); |
| 103 Expect.equals(hints, collector.hints.length, | 100 Expect.equals( |
| 104 'Unexpected hints: ${collector.hints}'); | 101 hints, collector.hints.length, 'Unexpected hints: ${collector.hints}'); |
| 105 checkUriSchemes(collector.hints); | 102 checkUriSchemes(collector.hints); |
| 106 Expect.equals(infos, collector.infos.length, | 103 Expect.equals( |
| 107 'Unexpected infos: ${collector.infos}'); | 104 infos, collector.infos.length, 'Unexpected infos: ${collector.infos}'); |
| 108 checkUriSchemes(collector.infos); | 105 checkUriSchemes(collector.infos); |
| 109 } | 106 } |
| 110 | 107 |
| 111 void checkUriSchemes(Iterable<CollectedMessage> messages) { | 108 void checkUriSchemes(Iterable<CollectedMessage> messages) { |
| 112 for (CollectedMessage message in messages) { | 109 for (CollectedMessage message in messages) { |
| 113 if (message.uri != null) { | 110 if (message.uri != null) { |
| 114 Expect.notEquals('package', message.uri.scheme, | 111 Expect.notEquals('package', message.uri.scheme, |
| 115 "Unexpected package uri `${message.uri}` in message: $message"); | 112 "Unexpected package uri `${message.uri}` in message: $message"); |
| 116 } | 113 } |
| 117 } | 114 } |
| 118 } | 115 } |
| 119 | 116 |
| 120 void main() { | 117 void main() { |
| 121 asyncTest(() async { | 118 asyncTest(() async { |
| 122 await test( | 119 await test(Uri.parse('memory:main.dart'), |
| 123 Uri.parse('memory:main.dart'), | |
| 124 showPackageWarnings: [], | 120 showPackageWarnings: [], |
| 125 // From error.dart, package:pkg_error1 and package:pkg_error2: | 121 // From error.dart, package:pkg_error1 and package:pkg_error2: |
| 126 warnings: 3, hints: 3, infos: 3); | 122 warnings: 3, |
| 127 await test( | 123 hints: 3, |
| 128 Uri.parse('memory:main.dart'), | 124 infos: 3); |
| 125 await test(Uri.parse('memory:main.dart'), |
| 129 showPackageWarnings: ['pkg_error1'], | 126 showPackageWarnings: ['pkg_error1'], |
| 130 // From error.dart and package:pkg_error1: | 127 // From error.dart and package:pkg_error1: |
| 131 warnings: 2, hints: 2 + 1 /* from summary */, infos: 2); | 128 warnings: 2, |
| 132 await test( | 129 hints: 2 + 1 /* from summary */, |
| 133 Uri.parse('memory:main.dart'), | 130 infos: 2); |
| 131 await test(Uri.parse('memory:main.dart'), |
| 134 showPackageWarnings: ['pkg_error1', 'pkg_error2'], | 132 showPackageWarnings: ['pkg_error1', 'pkg_error2'], |
| 135 // From error.dart, package:pkg_error1 and package:pkg_error2: | 133 // From error.dart, package:pkg_error1 and package:pkg_error2: |
| 136 warnings: 3, hints: 3, infos: 3); | 134 warnings: 3, |
| 137 await test( | 135 hints: 3, |
| 138 Uri.parse('memory:main.dart'), | 136 infos: 3); |
| 137 await test(Uri.parse('memory:main.dart'), |
| 139 showPackageWarnings: [], | 138 showPackageWarnings: [], |
| 140 // From error.dart, package:pkg_error1 and package:pkg_error2: | 139 // From error.dart, package:pkg_error1 and package:pkg_error2: |
| 141 warnings: 3, hints: 3, infos: 3); | 140 warnings: 3, |
| 142 await test( | 141 hints: 3, |
| 143 Uri.parse('memory:main.dart'), | 142 infos: 3); |
| 143 await test(Uri.parse('memory:main.dart'), |
| 144 showPackageWarnings: null, | 144 showPackageWarnings: null, |
| 145 // From error.dart only: | 145 // From error.dart only: |
| 146 warnings: 1, hints: 1 + 2 /* from summary */, infos: 1); | 146 warnings: 1, |
| 147 await test( | 147 hints: 1 + 2 /* from summary */, |
| 148 Uri.parse('package:pkg_error1/pkg_error1.dart'), | 148 infos: 1); |
| 149 await test(Uri.parse('package:pkg_error1/pkg_error1.dart'), |
| 149 showPackageWarnings: [], | 150 showPackageWarnings: [], |
| 150 // From package:pkg_error1 and package:pkg_error2: | 151 // From package:pkg_error1 and package:pkg_error2: |
| 151 warnings: 2, hints: 2, infos: 2); | 152 warnings: 2, |
| 152 await test( | 153 hints: 2, |
| 153 Uri.parse('package:pkg_error1/pkg_error1.dart'), | 154 infos: 2); |
| 155 await test(Uri.parse('package:pkg_error1/pkg_error1.dart'), |
| 154 showPackageWarnings: null, | 156 showPackageWarnings: null, |
| 155 // From package:pkg_error1/pkg_error1.dart only: | 157 // From package:pkg_error1/pkg_error1.dart only: |
| 156 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1); | 158 warnings: 1, |
| 157 await test( | 159 hints: 1 + 1 /* from summary */, |
| 158 Uri.parse('package:pkg_noerror/pkg_noerror.dart'), | 160 infos: 1); |
| 161 await test(Uri.parse('package:pkg_noerror/pkg_noerror.dart'), |
| 159 showPackageWarnings: [], | 162 showPackageWarnings: [], |
| 160 // From package:pkg_error1 and package:pkg_error2: | 163 // From package:pkg_error1 and package:pkg_error2: |
| 161 warnings: 2, hints: 2, infos: 2); | 164 warnings: 2, |
| 162 await test( | 165 hints: 2, |
| 163 Uri.parse('package:pkg_noerror/pkg_noerror.dart'), | 166 infos: 2); |
| 167 await test(Uri.parse('package:pkg_noerror/pkg_noerror.dart'), |
| 164 showPackageWarnings: ['pkg_error1'], | 168 showPackageWarnings: ['pkg_error1'], |
| 165 // From package:pkg_error1: | 169 // From package:pkg_error1: |
| 166 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1); | 170 warnings: 1, |
| 167 await test( | 171 hints: 1 + 1 /* from summary */, |
| 168 Uri.parse('package:pkg_noerror/pkg_noerror.dart'), | 172 infos: 1); |
| 169 showPackageWarnings: null, | 173 await test(Uri.parse('package:pkg_noerror/pkg_noerror.dart'), |
| 170 hints: 2 /* from summary */); | 174 showPackageWarnings: null, hints: 2 /* from summary */); |
| 171 }); | 175 }); |
| 172 } | 176 } |
| 173 | |
| OLD | NEW |