| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 hint on empty combinators works as intended. | 5 // Test that the hint on empty combinators 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 'package:compiler/src/compiler.dart'; | 11 import 'package:compiler/src/compiler.dart'; |
| 12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
| 13 | 13 |
| 14 const SOURCE = const { | 14 const SOURCE = const { |
| 15 'show_local.dart': """ | 15 'show_local.dart': """ |
| 16 import 'lib.dart' show Foo; | 16 import 'lib.dart' show Foo; |
| 17 | 17 |
| 18 main() {} | 18 main() {} |
| 19 """, | 19 """, |
| 20 | |
| 21 'hide_local.dart': """ | 20 'hide_local.dart': """ |
| 22 import 'lib.dart' hide Foo; | 21 import 'lib.dart' hide Foo; |
| 23 | 22 |
| 24 main() {} | 23 main() {} |
| 25 """, | 24 """, |
| 26 | |
| 27 'show_package.dart': """ | 25 'show_package.dart': """ |
| 28 import 'package:pkg/pkg.dart' show Foo; | 26 import 'package:pkg/pkg.dart' show Foo; |
| 29 | 27 |
| 30 main() {} | 28 main() {} |
| 31 """, | 29 """, |
| 32 | |
| 33 'hide_package.dart': """ | 30 'hide_package.dart': """ |
| 34 import 'package:pkg/pkg.dart' hide Foo; | 31 import 'package:pkg/pkg.dart' hide Foo; |
| 35 | 32 |
| 36 main() {} | 33 main() {} |
| 37 """, | 34 """, |
| 38 | |
| 39 'lib.dart': '', | 35 'lib.dart': '', |
| 40 | |
| 41 'pkg/pkg/pkg.dart': '', | 36 'pkg/pkg/pkg.dart': '', |
| 42 }; | 37 }; |
| 43 | 38 |
| 44 Future<Compiler> test(Uri entryPoint, | 39 Future<Compiler> test(Uri entryPoint, |
| 45 {bool showPackageWarnings: false, | 40 {bool showPackageWarnings: false, |
| 46 bool suppressHints: false, | 41 bool suppressHints: false, |
| 47 int hints: 0, | 42 int hints: 0, |
| 48 Compiler cachedCompiler}) async { | 43 Compiler cachedCompiler}) async { |
| 49 print('=================================================================='); | 44 print('=================================================================='); |
| 50 print('test: $entryPoint showPackageWarnings=$showPackageWarnings ' | 45 print('test: $entryPoint showPackageWarnings=$showPackageWarnings ' |
| 51 'suppressHints=$suppressHints'); | 46 'suppressHints=$suppressHints'); |
| 52 var options = [Flags.analyzeOnly]; | 47 var options = [Flags.analyzeOnly]; |
| 53 if (showPackageWarnings) { | 48 if (showPackageWarnings) { |
| 54 options.add(Flags.showPackageWarnings); | 49 options.add(Flags.showPackageWarnings); |
| 55 } | 50 } |
| 56 if (suppressHints) { | 51 if (suppressHints) { |
| 57 options.add(Flags.suppressHints); | 52 options.add(Flags.suppressHints); |
| 58 } | 53 } |
| 59 var collector = new DiagnosticCollector(); | 54 var collector = new DiagnosticCollector(); |
| 60 CompilationResult result = await runCompiler( | 55 CompilationResult result = await runCompiler( |
| 61 entryPoint: entryPoint, | 56 entryPoint: entryPoint, |
| 62 memorySourceFiles: SOURCE, | 57 memorySourceFiles: SOURCE, |
| 63 options: options, | 58 options: options, |
| 64 packageRoot: Uri.parse('memory:pkg/'), | 59 packageRoot: Uri.parse('memory:pkg/'), |
| 65 diagnosticHandler: collector, | 60 diagnosticHandler: collector, |
| 66 cachedCompiler: cachedCompiler); | 61 cachedCompiler: cachedCompiler); |
| 67 Expect.equals(0, collector.errors.length, | 62 Expect.equals( |
| 68 'Unexpected errors: ${collector.errors}'); | 63 0, collector.errors.length, 'Unexpected errors: ${collector.errors}'); |
| 69 Expect.equals(0, collector.warnings.length, | 64 Expect.equals(0, collector.warnings.length, |
| 70 'Unexpected warnings: ${collector.warnings}'); | 65 'Unexpected warnings: ${collector.warnings}'); |
| 71 Expect.equals(hints, collector.hints.length, | 66 Expect.equals( |
| 72 'Unexpected hints: ${collector.hints}'); | 67 hints, collector.hints.length, 'Unexpected hints: ${collector.hints}'); |
| 73 Expect.equals(0, collector.infos.length, | 68 Expect.equals( |
| 74 'Unexpected infos: ${collector.infos}'); | 69 0, collector.infos.length, 'Unexpected infos: ${collector.infos}'); |
| 75 print('=================================================================='); | 70 print('=================================================================='); |
| 76 return result.compiler; | 71 return result.compiler; |
| 77 } | 72 } |
| 78 | 73 |
| 79 Future<Compiler> testUri(Uri entrypoint, | 74 Future<Compiler> testUri(Uri entrypoint, |
| 80 {bool suppressed: false, | 75 {bool suppressed: false, Compiler cachedCompiler}) async { |
| 81 Compiler cachedCompiler}) async { | 76 cachedCompiler = await test(entrypoint, |
| 82 cachedCompiler = await test( | |
| 83 entrypoint, | |
| 84 showPackageWarnings: true, | 77 showPackageWarnings: true, |
| 85 suppressHints: false, | 78 suppressHints: false, |
| 86 hints: 1, | 79 hints: 1, |
| 87 cachedCompiler: cachedCompiler); | 80 cachedCompiler: cachedCompiler); |
| 88 cachedCompiler = await test( | 81 cachedCompiler = await test(entrypoint, |
| 89 entrypoint, | |
| 90 showPackageWarnings: false, | 82 showPackageWarnings: false, |
| 91 suppressHints: false, | 83 suppressHints: false, |
| 92 hints: suppressed ? 0 : 1, | 84 hints: suppressed ? 0 : 1, |
| 93 cachedCompiler: cachedCompiler); | 85 cachedCompiler: cachedCompiler); |
| 94 cachedCompiler = await test( | 86 cachedCompiler = await test(entrypoint, |
| 95 entrypoint, | |
| 96 showPackageWarnings: true, | 87 showPackageWarnings: true, |
| 97 suppressHints: true, | 88 suppressHints: true, |
| 98 hints: 0, | 89 hints: 0, |
| 99 cachedCompiler: cachedCompiler); | 90 cachedCompiler: cachedCompiler); |
| 100 cachedCompiler = await test( | 91 cachedCompiler = await test(entrypoint, |
| 101 entrypoint, | |
| 102 showPackageWarnings: false, | 92 showPackageWarnings: false, |
| 103 suppressHints: true, | 93 suppressHints: true, |
| 104 hints: 0, | 94 hints: 0, |
| 105 cachedCompiler: cachedCompiler); | 95 cachedCompiler: cachedCompiler); |
| 106 return cachedCompiler; | 96 return cachedCompiler; |
| 107 } | 97 } |
| 108 | 98 |
| 109 void main() { | 99 void main() { |
| 110 asyncTest(() async { | 100 asyncTest(() async { |
| 111 Compiler cachedCompiler = await testUri( | 101 Compiler cachedCompiler = |
| 112 Uri.parse('memory:show_local.dart')); | 102 await testUri(Uri.parse('memory:show_local.dart')); |
| 113 cachedCompiler = await testUri( | 103 cachedCompiler = await testUri(Uri.parse('memory:hide_local.dart'), |
| 114 Uri.parse('memory:hide_local.dart'), | |
| 115 cachedCompiler: cachedCompiler); | 104 cachedCompiler: cachedCompiler); |
| 116 cachedCompiler = await testUri( | 105 cachedCompiler = await testUri(Uri.parse('memory:show_package.dart'), |
| 117 Uri.parse('memory:show_package.dart'), | |
| 118 cachedCompiler: cachedCompiler); | 106 cachedCompiler: cachedCompiler); |
| 119 cachedCompiler = await testUri( | 107 cachedCompiler = await testUri(Uri.parse('memory:hide_package.dart'), |
| 120 Uri.parse('memory:hide_package.dart'), | 108 suppressed: true, cachedCompiler: cachedCompiler); |
| 121 suppressed: true, | |
| 122 cachedCompiler: cachedCompiler); | |
| 123 }); | 109 }); |
| 124 } | 110 } |
| 125 | |
| OLD | NEW |