| 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 '--hide-package-warnings' option works as intended. | 5 // Test that the '--show-package-warnings' option works as intended. |
| 6 | 6 |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 | 9 |
| 10 import 'memory_compiler.dart'; | 10 import 'memory_compiler.dart'; |
| 11 | 11 |
| 12 /// Error code that creates 1 warning, 1 hint, and 1 info. | 12 /// Error code that creates 1 warning, 1 hint, and 1 info. |
| 13 const ERROR_CODE = """ | 13 const ERROR_CODE = """ |
| 14 m(Object o) { | 14 m(Object o) { |
| 15 if (o is String) { | 15 if (o is String) { |
| 16 o = o.length; | 16 o = o.length; |
| 17 } | 17 } |
| 18 }"""; | 18 }"""; |
| 19 | 19 |
| 20 const SOURCE = const { | 20 const SOURCE = const { |
| 21 'main.dart': """ | 21 'main.dart': """ |
| 22 import 'package:pkg_error1/pkg_error1.dart'; | 22 import 'package:pkg_error1/pkg_error1.dart'; |
| 23 import 'package:pkg_error2/pkg_error2.dart'; | 23 import 'package:pkg_error2/pkg_error2.dart'; |
| 24 import 'package:pkg_noerror/pkg_noerror.dart'; | 24 import 'package:pkg_noerror/pkg_noerror.dart'; |
| 25 import 'error.dart'; | 25 import 'error.dart'; |
| 26 """, | 26 """, |
| 27 | 27 |
| 28 'error.dart': ERROR_CODE, | 28 'error.dart': ERROR_CODE, |
| 29 | 29 |
| 30 'pkg/pkg_error1/pkg_error1.dart': """ | 30 'pkg/pkg_error1/pkg_error1.dart': """ |
| 31 import 'package:pkg_error2/pkg_error2.dart'; | 31 import 'package:pkg_error2/pkg_error2.dart'; |
| 32 import 'package:pkg_noerror/pkg_noerror.dart'; | 32 import 'package:pkg_noerror/pkg_noerror.dart'; |
| 33 $ERROR_CODE""", | 33 $ERROR_CODE""", |
| 34 | 34 |
| 35 'pkg/pkg_error2/pkg_error2.dart': """ | 35 'pkg/pkg_error2/pkg_error2.dart': """ |
| 36 import 'package:pkg_error1/pkg_error1.dart'; | 36 import 'package:pkg_error1/pkg_error1.dart'; |
| 37 import 'package:pkg_noerror/pkg_noerror.dart'; | 37 import 'package:pkg_noerror/pkg_noerror.dart'; |
| 38 $ERROR_CODE""", | 38 $ERROR_CODE""", |
| 39 | 39 |
| 40 'pkg/pkg_noerror/pkg_noerror.dart': """ | 40 'pkg/pkg_noerror/pkg_noerror.dart': """ |
| 41 import 'package:pkg_error1/pkg_error1.dart'; | 41 import 'package:pkg_error1/pkg_error1.dart'; |
| 42 import 'package:pkg_error2/pkg_error2.dart'; | 42 import 'package:pkg_error2/pkg_error2.dart'; |
| 43 """}; | 43 """}; |
| 44 | 44 |
| 45 void test(List<Uri> entryPoints, | 45 void test(List<Uri> entryPoints, |
| 46 {bool hidePackageWarnings: false, | 46 {bool showPackageWarnings: false, |
| 47 int warnings: 0, | 47 int warnings: 0, |
| 48 int hints: 0, | 48 int hints: 0, |
| 49 int infos: 0}) { | 49 int infos: 0}) { |
| 50 var options = ['--analyze-only', '--analyze-all']; | 50 var options = ['--analyze-only', '--analyze-all']; |
| 51 if (hidePackageWarnings) { | 51 if (showPackageWarnings) { |
| 52 options.add('--hide-package-warnings'); | 52 options.add('--show-package-warnings'); |
| 53 } | 53 } |
| 54 var collector = new DiagnosticCollector(); | 54 var collector = new DiagnosticCollector(); |
| 55 var compiler = compilerFor(SOURCE, | 55 var compiler = compilerFor(SOURCE, |
| 56 options: options, | 56 options: options, |
| 57 packageRoot: Uri.parse('memory:pkg/'), | 57 packageRoot: Uri.parse('memory:pkg/'), |
| 58 diagnosticHandler: collector); | 58 diagnosticHandler: collector); |
| 59 Uri mainUri = null; | 59 Uri mainUri = null; |
| 60 if (entryPoints.length == 1) { | 60 if (entryPoints.length == 1) { |
| 61 mainUri = entryPoints[0]; | 61 mainUri = entryPoints[0]; |
| 62 } else { | 62 } else { |
| 63 compiler.librariesToAnalyzeWhenRun = entryPoints; | 63 compiler.librariesToAnalyzeWhenRun = entryPoints; |
| 64 } | 64 } |
| 65 asyncTest(() => compiler.run(mainUri).then((_) { | 65 asyncTest(() => compiler.run(mainUri).then((_) { |
| 66 print('=================================================================='); | 66 print('=================================================================='); |
| 67 print('test: $entryPoints hidePackageWarnings=$hidePackageWarnings'); | 67 print('test: $entryPoints showPackageWarnings=$showPackageWarnings'); |
| 68 Expect.equals(0, collector.errors.length, | 68 Expect.equals(0, collector.errors.length, |
| 69 'Unexpected errors: ${collector.errors}'); | 69 'Unexpected errors: ${collector.errors}'); |
| 70 Expect.equals(warnings, collector.warnings.length, | 70 Expect.equals(warnings, collector.warnings.length, |
| 71 'Unexpected warnings: ${collector.warnings}'); | 71 'Unexpected warnings: ${collector.warnings}'); |
| 72 Expect.equals(hints, collector.hints.length, | 72 Expect.equals(hints, collector.hints.length, |
| 73 'Unexpected hints: ${collector.hints}'); | 73 'Unexpected hints: ${collector.hints}'); |
| 74 Expect.equals(infos, collector.infos.length, | 74 Expect.equals(infos, collector.infos.length, |
| 75 'Unexpected infos: ${collector.infos}'); | 75 'Unexpected infos: ${collector.infos}'); |
| 76 print('=================================================================='); | 76 print('=================================================================='); |
| 77 })); | 77 })); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void main() { | 80 void main() { |
| 81 test([Uri.parse('memory:main.dart')], | 81 test([Uri.parse('memory:main.dart')], |
| 82 hidePackageWarnings: false, | 82 showPackageWarnings: true, |
| 83 // From error.dart, package:pkg_error1 and package:pkg_error2: | 83 // From error.dart, package:pkg_error1 and package:pkg_error2: |
| 84 warnings: 3, hints: 3, infos: 3); | 84 warnings: 3, hints: 3, infos: 3); |
| 85 test([Uri.parse('memory:main.dart')], | 85 test([Uri.parse('memory:main.dart')], |
| 86 hidePackageWarnings: true, | 86 showPackageWarnings: false, |
| 87 // From error.dart only: | 87 // From error.dart only: |
| 88 warnings: 1, hints: 1, infos: 1); | 88 warnings: 1, hints: 1 + 2 /* from summary */, infos: 1); |
| 89 test([Uri.parse('package:pkg_error1/pkg_error1.dart')], | 89 test([Uri.parse('package:pkg_error1/pkg_error1.dart')], |
| 90 hidePackageWarnings: false, | 90 showPackageWarnings: true, |
| 91 // From package:pkg_error1 and package:pkg_error2: | 91 // From package:pkg_error1 and package:pkg_error2: |
| 92 warnings: 2, hints: 2, infos: 2); | 92 warnings: 2, hints: 2, infos: 2); |
| 93 test([Uri.parse('package:pkg_error1/pkg_error1.dart')], | 93 test([Uri.parse('package:pkg_error1/pkg_error1.dart')], |
| 94 hidePackageWarnings: true, | 94 showPackageWarnings: false, |
| 95 // From package:pkg_error1/pkg_error1.dart only: | 95 // From package:pkg_error1/pkg_error1.dart only: |
| 96 warnings: 1, hints: 1, infos: 1); | 96 warnings: 1, hints: 1 + 1 /* from summary */, infos: 1); |
| 97 test([Uri.parse('package:pkg_noerror/pkg_noerror.dart')], | 97 test([Uri.parse('package:pkg_noerror/pkg_noerror.dart')], |
| 98 hidePackageWarnings: false, | 98 showPackageWarnings: true, |
| 99 // From package:pkg_error1 and package:pkg_error2: | 99 // From package:pkg_error1 and package:pkg_error2: |
| 100 warnings: 2, hints: 2, infos: 2); | 100 warnings: 2, hints: 2, infos: 2); |
| 101 test([Uri.parse('package:pkg_noerror/pkg_noerror.dart')], | 101 test([Uri.parse('package:pkg_noerror/pkg_noerror.dart')], |
| 102 hidePackageWarnings: true); | 102 showPackageWarnings: false, |
| 103 hints: 2 /* from summary */); |
| 103 } | 104 } |
| 104 | 105 |
| OLD | NEW |