| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Tests code generation. | 5 /// Tests code generation. |
| 6 /// | 6 /// |
| 7 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 7 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks |
| 8 /// that the output is what we expected. | 8 /// that the output is what we expected. |
| 9 library dev_compiler.test.codegen_test; | 9 library dev_compiler.test.codegen_test; |
| 10 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 var exception, stackTrace; | 161 var exception, stackTrace; |
| 162 try { | 162 try { |
| 163 module = compiler.compile(unit, options); | 163 module = compiler.compile(unit, options); |
| 164 } catch (e, st) { | 164 } catch (e, st) { |
| 165 exception = e; | 165 exception = e; |
| 166 stackTrace = st; | 166 stackTrace = st; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // This covers tests where the intent of the test is to validate that | 169 // This covers tests where the intent of the test is to validate that |
| 170 // some static error is produced. | 170 // some static error is produced. |
| 171 var intentionalCompileError = contents.contains(': compile-time error') || | 171 var intentionalCompileError = |
| 172 contents.contains('/*@compile-error='); | 172 (contents.contains(': compile-time error') || |
| 173 contents.contains('/*@compile-error=')) && |
| 174 !status.contains(Expectation.missingCompileTimeError); |
| 173 | 175 |
| 174 var crashing = status.contains(Expectation.crash); | 176 var crashing = status.contains(Expectation.crash); |
| 175 if (module == null) { | 177 if (module == null) { |
| 176 expect(crashing, isTrue, | 178 expect(crashing, isTrue, |
| 177 reason: "test $name crashes during compilation.\n" | 179 reason: "test $name crashes during compilation.\n" |
| 178 "$exception\n$stackTrace"); | 180 "$exception\n$stackTrace"); |
| 179 return; | 181 return; |
| 180 } | 182 } |
| 181 | 183 |
| 182 // Write out JavaScript and/or compilation errors/warnings. | 184 // Write out JavaScript and/or compilation errors/warnings. |
| 183 _writeModule( | 185 _writeModule( |
| 184 path.join(codegenOutputDir, name), | 186 path.join(codegenOutputDir, name), |
| 185 isTopLevelTest ? path.join(codegenExpectDir, name) : null, | 187 isTopLevelTest ? path.join(codegenExpectDir, name) : null, |
| 186 moduleFormat, | 188 moduleFormat, |
| 187 module); | 189 module); |
| 188 | 190 |
| 189 expect(crashing, isFalse, reason: "test $name no longer crashes."); | 191 expect(crashing, isFalse, reason: "test $name no longer crashes."); |
| 190 | 192 |
| 191 var knownCompileError = status.contains(Expectation.compileTimeError); | 193 var knownCompileError = status.contains(Expectation.compileTimeError) || |
| 194 status.contains(Expectation.fail); |
| 195 // TODO(jmesserly): we could also invert negative_test, however analyzer |
| 196 // in test.dart does not do this. |
| 197 // name.endsWith('negative_test') && !status.contains(Expectation.fail) |
| 192 if (module.isValid) { | 198 if (module.isValid) { |
| 193 expect(knownCompileError, isFalse, | 199 expect(knownCompileError, isFalse, |
| 194 reason: "test $name expected static errors, but compiled."); | 200 reason: "test $name expected static errors, but compiled."); |
| 195 } else { | 201 } else { |
| 196 var reason = intentionalCompileError ? "intended" : "unexpected"; | 202 var reason = intentionalCompileError ? "intended" : "unexpected"; |
| 197 expect(intentionalCompileError || knownCompileError, isTrue, | 203 expect(intentionalCompileError || knownCompileError, isTrue, |
| 198 reason: "test $name failed to compile due to $reason errors:" | 204 reason: "test $name failed to compile due to $reason errors:" |
| 199 "\n\n${module.errors.join('\n')}."); | 205 "\n\n${module.errors.join('\n')}."); |
| 200 } | 206 } |
| 201 }); | 207 }); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 274 } |
| 269 | 275 |
| 270 void _writeRuntimeStatus(Map<String, Set<Expectation>> testFiles) { | 276 void _writeRuntimeStatus(Map<String, Set<Expectation>> testFiles) { |
| 271 var runtimeStatus = <String, String>{}; | 277 var runtimeStatus = <String, String>{}; |
| 272 testFiles.forEach((name, status) { | 278 testFiles.forEach((name, status) { |
| 273 name = path.withoutExtension(path.relative(name, from: codegenTestDir)); | 279 name = path.withoutExtension(path.relative(name, from: codegenTestDir)); |
| 274 // Skip tests that we don't expect to compile. | 280 // Skip tests that we don't expect to compile. |
| 275 if (status.contains(Expectation.compileTimeError) || | 281 if (status.contains(Expectation.compileTimeError) || |
| 276 status.contains(Expectation.crash) || | 282 status.contains(Expectation.crash) || |
| 277 status.contains(Expectation.skip) || | 283 status.contains(Expectation.skip) || |
| 284 status.contains(Expectation.fail) || |
| 278 status.contains(Expectation.skipByDesign)) { | 285 status.contains(Expectation.skipByDesign)) { |
| 279 return; | 286 return; |
| 280 } | 287 } |
| 281 // Normalize the expectations for the Karma language_test.js runner. | 288 // Normalize the expectations for the Karma language_test.js runner. |
| 282 if (status.remove(Expectation.ok)) assert(status.isNotEmpty); | 289 if (status.remove(Expectation.ok)) assert(status.isNotEmpty); |
| 283 if (status.remove(Expectation.missingCompileTimeError) || | 290 if (status.remove(Expectation.missingCompileTimeError) || |
| 284 status.remove(Expectation.missingRuntimeError)) { | 291 status.remove(Expectation.missingRuntimeError)) { |
| 285 status.add(Expectation.pass); | 292 status.add(Expectation.pass); |
| 286 } | 293 } |
| 287 | 294 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 StringLiteral uriLiteral = directive.uri; | 453 StringLiteral uriLiteral = directive.uri; |
| 447 String uriContent = uriLiteral.stringValue; | 454 String uriContent = uriLiteral.stringValue; |
| 448 if (uriContent != null) { | 455 if (uriContent != null) { |
| 449 uriContent = uriContent.trim(); | 456 uriContent = uriContent.trim(); |
| 450 directive.uriContent = uriContent; | 457 directive.uriContent = uriContent; |
| 451 } | 458 } |
| 452 return (directive as UriBasedDirectiveImpl).validate() == null | 459 return (directive as UriBasedDirectiveImpl).validate() == null |
| 453 ? uriContent | 460 ? uriContent |
| 454 : null; | 461 : null; |
| 455 } | 462 } |
| OLD | NEW |