| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 main() { | 26 main() { |
| 27 // Use a group() wrapper to specify the timeout. | 27 // Use a group() wrapper to specify the timeout. |
| 28 group('front_end_inference_test', () { | 28 group('front_end_inference_test', () { |
| 29 defineReflectiveSuite(() { | 29 defineReflectiveSuite(() { |
| 30 defineReflectiveTests(RunFrontEndInferenceTest); | 30 defineReflectiveTests(RunFrontEndInferenceTest); |
| 31 }); | 31 }); |
| 32 }, timeout: new Timeout(const Duration(seconds: 60))); | 32 }, timeout: new Timeout(const Duration(seconds: 60))); |
| 33 } | 33 } |
| 34 | 34 |
| 35 /// Set this to `true` to cause expectation comments to be updated. |
| 36 const bool fixProblems = false; |
| 37 |
| 35 @reflectiveTest | 38 @reflectiveTest |
| 36 class RunFrontEndInferenceTest { | 39 class RunFrontEndInferenceTest { |
| 37 test_run() async { | 40 test_run() async { |
| 38 String pkgPath = _findPkgRoot(); | 41 String pkgPath = _findPkgRoot(); |
| 39 String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference'); | 42 String fePath = pathos.join(pkgPath, 'front_end', 'testcases', 'inference'); |
| 40 List<File> dartFiles = new Directory(fePath) | 43 List<File> dartFiles = new Directory(fePath) |
| 41 .listSync() | 44 .listSync() |
| 42 .where((entry) => entry is File && entry.path.endsWith('.dart')) | 45 .where((entry) => entry is File && entry.path.endsWith('.dart')) |
| 43 .map((entry) => entry as File) | 46 .map((entry) => entry as File) |
| 44 .toList(); | 47 .toList(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 await validation.loadExpectations(uri); | 95 await validation.loadExpectations(uri); |
| 93 | 96 |
| 94 provider.newFile(path, code); | 97 provider.newFile(path, code); |
| 95 | 98 |
| 96 AnalysisResult result = await driver.getResult(path); | 99 AnalysisResult result = await driver.getResult(path); |
| 97 result.unit.accept(new _InstrumentationVisitor(validation, uri)); | 100 result.unit.accept(new _InstrumentationVisitor(validation, uri)); |
| 98 | 101 |
| 99 validation.finish(); | 102 validation.finish(); |
| 100 | 103 |
| 101 if (validation.hasProblems) { | 104 if (validation.hasProblems) { |
| 102 return validation.problemsAsString; | 105 if (fixProblems) { |
| 106 validation.fixSource(uri); |
| 107 return null; |
| 108 } else { |
| 109 return validation.problemsAsString; |
| 110 } |
| 103 } else { | 111 } else { |
| 104 return null; | 112 return null; |
| 105 } | 113 } |
| 106 } | 114 } |
| 107 } | 115 } |
| 108 | 116 |
| 109 /** | 117 /** |
| 110 * Instance of [InstrumentationValue] describing a [DartType]. | 118 * Instance of [InstrumentationValue] describing a [DartType]. |
| 111 */ | 119 */ |
| 112 class _InstrumentationValueForType extends fasta.InstrumentationValue { | 120 class _InstrumentationValueForType extends fasta.InstrumentationValue { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 240 } |
| 233 } | 241 } |
| 234 } | 242 } |
| 235 | 243 |
| 236 visitInstanceCreationExpression(InstanceCreationExpression node) { | 244 visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 237 super.visitInstanceCreationExpression(node); | 245 super.visitInstanceCreationExpression(node); |
| 238 DartType type = node.staticType; | 246 DartType type = node.staticType; |
| 239 if (type is InterfaceType) { | 247 if (type is InterfaceType) { |
| 240 if (type.typeParameters.isNotEmpty && | 248 if (type.typeParameters.isNotEmpty && |
| 241 node.constructorName.type.typeArguments == null) { | 249 node.constructorName.type.typeArguments == null) { |
| 242 _recordTypeArguments(node.offset, type.typeArguments); | 250 _recordTypeArguments(node.constructorName.offset, type.typeArguments); |
| 243 } | 251 } |
| 244 } | 252 } |
| 245 } | 253 } |
| 246 | 254 |
| 247 visitListLiteral(ListLiteral node) { | 255 visitListLiteral(ListLiteral node) { |
| 248 super.visitListLiteral(node); | 256 super.visitListLiteral(node); |
| 249 if (node.typeArguments == null) { | 257 if (node.typeArguments == null) { |
| 250 DartType type = node.staticType; | 258 DartType type = node.staticType; |
| 251 if (type is InterfaceType) { | 259 if (type is InterfaceType) { |
| 252 _recordTypeArguments(node.offset, type.typeArguments); | 260 _recordTypeArguments(node.offset, type.typeArguments); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void _recordType(int offset, DartType type) { | 310 void _recordType(int offset, DartType type) { |
| 303 _instrumentation.record( | 311 _instrumentation.record( |
| 304 uri, offset, 'type', new _InstrumentationValueForType(type)); | 312 uri, offset, 'type', new _InstrumentationValueForType(type)); |
| 305 } | 313 } |
| 306 | 314 |
| 307 void _recordTypeArguments(int offset, List<DartType> typeArguments) { | 315 void _recordTypeArguments(int offset, List<DartType> typeArguments) { |
| 308 _instrumentation.record(uri, offset, 'typeArgs', | 316 _instrumentation.record(uri, offset, 'typeArgs', |
| 309 new _InstrumentationValueForTypeArgs(typeArguments)); | 317 new _InstrumentationValueForTypeArgs(typeArguments)); |
| 310 } | 318 } |
| 311 } | 319 } |
| OLD | NEW |