| 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 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 runCompiler("Foo foo; // Unresolved but not analyzed.", [Flags.analyzeOnly], | 107 runCompiler("Foo foo; // Unresolved but not analyzed.", [Flags.analyzeOnly], |
| 108 (String code, List errors, List warnings) { | 108 (String code, List errors, List warnings) { |
| 109 Expect.isNull(code); | 109 Expect.isNull(code); |
| 110 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); | 110 Expect.isTrue(errors.isEmpty, 'errors is not empty: $errors'); |
| 111 MessageTemplate template = | 111 MessageTemplate template = |
| 112 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; | 112 MessageTemplate.TEMPLATES[MessageKind.CONSIDER_ANALYZE_ALL]; |
| 113 Expect.equals("${template.message({'main': 'main'})}", warnings.single); | 113 Expect.equals("${template.message({'main': 'main'})}", warnings.single); |
| 114 }); | 114 }); |
| 115 | 115 |
| 116 runCompiler( | 116 runCompiler("""main() { |
| 117 """main() { | |
| 118 Foo foo; // Unresolved and analyzed. | 117 Foo foo; // Unresolved and analyzed. |
| 119 }""", | 118 }""", [Flags.analyzeOnly], (String code, List errors, List warnings) { |
| 120 [Flags.analyzeOnly], (String code, List errors, List warnings) { | |
| 121 Expect.isNull(code); | 119 Expect.isNull(code); |
| 122 Expect.isTrue(errors.isEmpty); | 120 Expect.isTrue(errors.isEmpty); |
| 123 Expect.equals(1, warnings.length); | 121 Expect.equals(1, warnings.length); |
| 124 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); | 122 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 125 }); | 123 }); |
| 126 | 124 |
| 127 runCompiler( | 125 runCompiler("""main() { |
| 128 """main() { | |
| 129 Foo foo; // Unresolved and analyzed. | 126 Foo foo; // Unresolved and analyzed. |
| 130 }""", | 127 }""", [Flags.analyzeOnly, Flags.analyzeSignaturesOnly], |
| 131 [Flags.analyzeOnly, Flags.analyzeSignaturesOnly], | |
| 132 (String code, List errors, List warnings) { | 128 (String code, List errors, List warnings) { |
| 133 Expect.isNull(code); | 129 Expect.isNull(code); |
| 134 Expect.isTrue(errors.isEmpty); | 130 Expect.isTrue(errors.isEmpty); |
| 135 Expect.isTrue(warnings.isEmpty); | 131 Expect.isTrue(warnings.isEmpty); |
| 136 }); | 132 }); |
| 137 | 133 |
| 138 runCompiler("Foo foo; // Unresolved and analyzed.", [ | 134 runCompiler("Foo foo; // Unresolved and analyzed.", [ |
| 139 Flags.analyzeOnly, | 135 Flags.analyzeOnly, |
| 140 Flags.analyzeAll | 136 Flags.analyzeAll |
| 141 ], (String code, List errors, List warnings) { | 137 ], (String code, List errors, List warnings) { |
| 142 Expect.isNull(code); | 138 Expect.isNull(code); |
| 143 Expect.isTrue(errors.isEmpty); | 139 Expect.isTrue(errors.isEmpty); |
| 144 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); | 140 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 145 }); | 141 }); |
| 146 | 142 |
| 147 runCompiler( | 143 runCompiler("""Foo foo; // Unresolved and analyzed. |
| 148 """Foo foo; // Unresolved and analyzed. | 144 main() {}""", [Flags.analyzeOnly, Flags.analyzeAll], |
| 149 main() {}""", | |
| 150 [Flags.analyzeOnly, Flags.analyzeAll], | |
| 151 (String code, List errors, List warnings) { | 145 (String code, List errors, List warnings) { |
| 152 Expect.isNull(code); | 146 Expect.isNull(code); |
| 153 Expect.isTrue(errors.isEmpty, 'Unexpected errors: $errors.'); | 147 Expect.isTrue(errors.isEmpty, 'Unexpected errors: $errors.'); |
| 154 Expect.equals(1, warnings.length, 'Unexpected warning count: $warnings.'); | 148 Expect.equals(1, warnings.length, 'Unexpected warning count: $warnings.'); |
| 155 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); | 149 Expect.equals("Cannot resolve type 'Foo'.", warnings[0].toString()); |
| 156 }); | 150 }); |
| 157 | 151 |
| 158 runCompiler("", [Flags.analyzeOnly, Flags.analyzeAll], | 152 runCompiler("", [Flags.analyzeOnly, Flags.analyzeAll], |
| 159 (String code, List errors, List warnings) { | 153 (String code, List errors, List warnings) { |
| 160 Expect.isNull(code); | 154 Expect.isNull(code); |
| 161 Expect.isTrue(errors.isEmpty); | 155 Expect.isTrue(errors.isEmpty); |
| 162 Expect.isTrue(warnings.isEmpty); | 156 Expect.isTrue(warnings.isEmpty); |
| 163 }); | 157 }); |
| 164 | 158 |
| 165 // --analyze-signatures-only implies --analyze-only | 159 // --analyze-signatures-only implies --analyze-only |
| 166 runCompiler("", [Flags.analyzeSignaturesOnly, Flags.analyzeAll], | 160 runCompiler("", [Flags.analyzeSignaturesOnly, Flags.analyzeAll], |
| 167 (String code, List errors, List warnings) { | 161 (String code, List errors, List warnings) { |
| 168 Expect.isNull(code); | 162 Expect.isNull(code); |
| 169 Expect.isTrue(errors.isEmpty); | 163 Expect.isTrue(errors.isEmpty); |
| 170 Expect.isTrue(warnings.isEmpty); | 164 Expect.isTrue(warnings.isEmpty); |
| 171 }); | 165 }); |
| 172 | 166 |
| 173 // Test that --allow-native-extensions works. | 167 // Test that --allow-native-extensions works. |
| 174 runCompiler( | 168 runCompiler("""main() {} |
| 175 """main() {} | 169 foo() native 'foo';""", [Flags.analyzeOnly, Flags.allowNativeExtensions], |
| 176 foo() native 'foo';""", | |
| 177 [Flags.analyzeOnly, Flags.allowNativeExtensions], | |
| 178 (String code, List errors, List warnings) { | 170 (String code, List errors, List warnings) { |
| 179 Expect.isNull(code); | 171 Expect.isNull(code); |
| 180 Expect.isTrue(errors.isEmpty); | 172 Expect.isTrue(errors.isEmpty); |
| 181 Expect.isTrue(warnings.isEmpty); | 173 Expect.isTrue(warnings.isEmpty); |
| 182 }); | 174 }); |
| 183 runCompiler( | 175 runCompiler("""main() {} |
| 184 """main() {} | 176 foo() native 'foo';""", [Flags.analyzeOnly], |
| 185 foo() native 'foo';""", | 177 (String code, List errors, List warnings) { |
| 186 [Flags.analyzeOnly], (String code, List errors, List warnings) { | |
| 187 Expect.isNull(code); | 178 Expect.isNull(code); |
| 188 Expect.isTrue( | 179 Expect.isTrue( |
| 189 errors.single.startsWith("'native' modifier is not supported.")); | 180 errors.single.startsWith("'native' modifier is not supported.")); |
| 190 Expect.isTrue(warnings.isEmpty); | 181 Expect.isTrue(warnings.isEmpty); |
| 191 }); | 182 }); |
| 192 } | 183 } |
| OLD | NEW |