| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Smoke test of the dart2js compiler API. | 5 // Smoke test of the dart2js compiler API. |
| 6 library analyze_only; | 6 library analyze_only; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| 11 | 11 |
| 12 import '../../utils/dummy_compiler_test.dart' as dummy; | 12 import '../../utils/dummy_compiler_test.dart' as dummy; |
| 13 import 'package:compiler/compiler.dart'; | 13 import 'package:compiler/compiler.dart'; |
| 14 | 14 import 'package:compiler/src/commandline_options.dart'; |
| 15 import 'package:compiler/src/diagnostics/messages.dart' show | 15 import 'package:compiler/src/diagnostics/messages.dart' show |
| 16 MessageKind, MessageTemplate; | 16 MessageKind, MessageTemplate; |
| 17 | 17 |
| 18 import 'output_collector.dart'; | 18 import 'output_collector.dart'; |
| 19 | 19 |
| 20 runCompiler(String main, List<String> options, | 20 runCompiler(String main, List<String> options, |
| 21 onValue(String code, List errors, List warnings)) { | 21 onValue(String code, List errors, List warnings)) { |
| 22 List errors = new List(); | 22 List errors = new List(); |
| 23 List warnings = new List(); | 23 List warnings = new List(); |
| 24 | 24 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 print('options: $options\n'); | 57 print('options: $options\n'); |
| 58 print('threw:\n $error\n$stack'); | 58 print('threw:\n $error\n$stack'); |
| 59 print('-----------------------------------------------\n\n'); | 59 print('-----------------------------------------------\n\n'); |
| 60 throw error; | 60 throw error; |
| 61 }); | 61 }); |
| 62 } | 62 } |
| 63 | 63 |
| 64 main() { | 64 main() { |
| 65 runCompiler( | 65 runCompiler( |
| 66 "", | 66 "", |
| 67 ['--generate-code-with-compile-time-errors'], | 67 [Flags.generateCodeWithCompileTimeErrors], |
| 68 (String code, List errors, List warnings) { | 68 (String code, List errors, List warnings) { |
| 69 Expect.isNotNull(code); | 69 Expect.isNotNull(code); |
| 70 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); | 70 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); |
| 71 MessageTemplate template = | 71 MessageTemplate template = |
| 72 MessageTemplate.TEMPLATES[MessageKind.MISSING_MAIN]; | 72 MessageTemplate.TEMPLATES[MessageKind.MISSING_MAIN]; |
| 73 Expect.equals( | 73 Expect.equals( |
| 74 "${template.message({'main': 'main'})}", | 74 "${template.message({'main': 'main'})}", |
| 75 warnings.single); | 75 warnings.single); |
| 76 }); | 76 }); |
| 77 | 77 |
| 78 runCompiler( | 78 runCompiler( |
| 79 "main() {}", | 79 "main() {}", |
| 80 ['--generate-code-with-compile-time-errors'], | 80 [Flags.generateCodeWithCompileTimeErrors], |
| 81 (String code, List errors, List warnings) { | 81 (String code, List errors, List warnings) { |
| 82 Expect.isNotNull(code); | 82 Expect.isNotNull(code); |
| 83 Expect.isTrue(errors.isEmpty); | 83 Expect.isTrue(errors.isEmpty); |
| 84 Expect.isTrue(warnings.isEmpty); | 84 Expect.isTrue(warnings.isEmpty); |
| 85 }); | 85 }); |
| 86 | 86 |
| 87 runCompiler( | 87 runCompiler( |
| 88 "", | 88 "", |
| 89 ['--analyze-only'], | 89 [Flags.analyzeOnly], |
| 90 (String code, List errors, List warnings) { | 90 (String code, List errors, List warnings) { |
| 91 Expect.isNull(code); | 91 Expect.isNull(code); |
| 92 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); | 92 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); |
| 93 MessageTemplate template = | 93 MessageTemplate template = |
| 94 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; | 94 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; |
| 95 Expect.equals( | 95 Expect.equals( |
| 96 "${template.message({'main': 'main'})}", | 96 "${template.message({'main': 'main'})}", |
| 97 warnings.single); | 97 warnings.single); |
| 98 }); | 98 }); |
| 99 | 99 |
| 100 runCompiler( | 100 runCompiler( |
| 101 "main() {}", | 101 "main() {}", |
| 102 ['--analyze-only'], | 102 [Flags.analyzeOnly], |
| 103 (String code, List errors, List warnings) { | 103 (String code, List errors, List warnings) { |
| 104 Expect.isNull(code); | 104 Expect.isNull(code); |
| 105 Expect.isTrue(errors.isEmpty); | 105 Expect.isTrue(errors.isEmpty); |
| 106 Expect.isTrue(warnings.isEmpty); | 106 Expect.isTrue(warnings.isEmpty); |
| 107 }); | 107 }); |
| 108 | 108 |
| 109 runCompiler( | 109 runCompiler( |
| 110 "Foo foo; // Unresolved but not analyzed.", | 110 "Foo foo; // Unresolved but not analyzed.", |
| 111 ['--analyze-only'], | 111 [Flags.analyzeOnly], |
| 112 (String code, List errors, List warnings) { | 112 (String code, List errors, List warnings) { |
| 113 Expect.isNull(code); | 113 Expect.isNull(code); |
| 114 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); | 114 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); |
| 115 MessageTemplate template = | 115 MessageTemplate template = |
| 116 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; | 116 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; |
| 117 Expect.equals( | 117 Expect.equals( |
| 118 "${template.message({'main': 'main'})}", | 118 "${template.message({'main': 'main'})}", |
| 119 warnings.single); | 119 warnings.single); |
| 120 }); | 120 }); |
| 121 | 121 |
| 122 runCompiler( | 122 runCompiler( |
| 123 """main() { | 123 """main() { |
| 124 Foo foo; // Unresolved and analyzed. | 124 Foo foo; // Unresolved and analyzed. |
| 125 }""", | 125 }""", |
| 126 ['--analyze-only'], | 126 [Flags.analyzeOnly], |
| 127 (String code, List errors, List warnings) { | 127 (String code, List errors, List warnings) { |
| 128 Expect.isNull(code); | 128 Expect.isNull(code); |
| 129 Expect.isTrue(errors.isEmpty); | 129 Expect.isTrue(errors.isEmpty); |
| 130 Expect.equals(1, warnings.length); | 130 Expect.equals(1, warnings.length); |
| 131 Expect.equals( | 131 Expect.equals( |
| 132 "Cannot resolve type 'Foo'.", warnings[0].toString()); | 132 "Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 133 }); | 133 }); |
| 134 | 134 |
| 135 runCompiler( | 135 runCompiler( |
| 136 """main() { | 136 """main() { |
| 137 Foo foo; // Unresolved and analyzed. | 137 Foo foo; // Unresolved and analyzed. |
| 138 }""", | 138 }""", |
| 139 ['--analyze-only', '--analyze-signatures-only'], | 139 [Flags.analyzeOnly, Flags.analyzeSignaturesOnly], |
| 140 (String code, List errors, List warnings) { | 140 (String code, List errors, List warnings) { |
| 141 Expect.isNull(code); | 141 Expect.isNull(code); |
| 142 Expect.isTrue(errors.isEmpty); | 142 Expect.isTrue(errors.isEmpty); |
| 143 Expect.isTrue(warnings.isEmpty); | 143 Expect.isTrue(warnings.isEmpty); |
| 144 }); | 144 }); |
| 145 | 145 |
| 146 runCompiler( | 146 runCompiler( |
| 147 "Foo foo; // Unresolved and analyzed.", | 147 "Foo foo; // Unresolved and analyzed.", |
| 148 ['--analyze-only', '--analyze-all'], | 148 [Flags.analyzeOnly, Flags.analyzeAll], |
| 149 (String code, List errors, List warnings) { | 149 (String code, List errors, List warnings) { |
| 150 Expect.isNull(code); | 150 Expect.isNull(code); |
| 151 Expect.isTrue(errors.isEmpty); | 151 Expect.isTrue(errors.isEmpty); |
| 152 Expect.equals( | 152 Expect.equals( |
| 153 "Cannot resolve type 'Foo'.", warnings[0].toString()); | 153 "Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 154 }); | 154 }); |
| 155 | 155 |
| 156 runCompiler( | 156 runCompiler( |
| 157 """Foo foo; // Unresolved and analyzed. | 157 """Foo foo; // Unresolved and analyzed. |
| 158 main() {}""", | 158 main() {}""", |
| 159 ['--analyze-only', '--analyze-all'], | 159 [Flags.analyzeOnly, Flags.analyzeAll], |
| 160 (String code, List errors, List warnings) { | 160 (String code, List errors, List warnings) { |
| 161 Expect.isNull(code); | 161 Expect.isNull(code); |
| 162 Expect.isTrue(errors.isEmpty, 'Unexpected errors: $errors.'); | 162 Expect.isTrue(errors.isEmpty, 'Unexpected errors: $errors.'); |
| 163 Expect.equals(1, warnings.length, 'Unexpected warning count: $warnings.'); | 163 Expect.equals(1, warnings.length, 'Unexpected warning count: $warnings.'); |
| 164 Expect.equals( | 164 Expect.equals( |
| 165 "Cannot resolve type 'Foo'.", warnings[0].toString()); | 165 "Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 166 }); | 166 }); |
| 167 | 167 |
| 168 runCompiler( | 168 runCompiler( |
| 169 "", | 169 "", |
| 170 ['--analyze-only', '--analyze-all'], | 170 [Flags.analyzeOnly, Flags.analyzeAll], |
| 171 (String code, List errors, List warnings) { | 171 (String code, List errors, List warnings) { |
| 172 Expect.isNull(code); | 172 Expect.isNull(code); |
| 173 Expect.isTrue(errors.isEmpty); | 173 Expect.isTrue(errors.isEmpty); |
| 174 Expect.isTrue(warnings.isEmpty); | 174 Expect.isTrue(warnings.isEmpty); |
| 175 }); | 175 }); |
| 176 | 176 |
| 177 // --analyze-signatures-only implies --analyze-only | 177 // --analyze-signatures-only implies --analyze-only |
| 178 runCompiler( | 178 runCompiler( |
| 179 "", | 179 "", |
| 180 ['--analyze-signatures-only', '--analyze-all'], | 180 [Flags.analyzeSignaturesOnly, Flags.analyzeAll], |
| 181 (String code, List errors, List warnings) { | 181 (String code, List errors, List warnings) { |
| 182 Expect.isNull(code); | 182 Expect.isNull(code); |
| 183 Expect.isTrue(errors.isEmpty); | 183 Expect.isTrue(errors.isEmpty); |
| 184 Expect.isTrue(warnings.isEmpty); | 184 Expect.isTrue(warnings.isEmpty); |
| 185 }); | 185 }); |
| 186 } | 186 } |
| OLD | NEW |