| 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 // TODO(jmesserly): this file needs to be refactored, it's a port from | 5 // TODO(jmesserly): this file needs to be refactored, it's a port from |
| 6 // package:dev_compiler's tests | 6 // package:dev_compiler's tests |
| 7 library analyzer.test.src.task.strong.strong_test_helper; | 7 library analyzer.test.src.task.strong.strong_test_helper; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/resolution_accessors.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/error/error.dart'; | 13 import 'package:analyzer/error/error.dart'; |
| 13 import 'package:analyzer/error/listener.dart'; | 14 import 'package:analyzer/error/listener.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 15 import 'package:analyzer/file_system/memory_file_system.dart'; | 16 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 16 import 'package:analyzer/source/error_processor.dart'; | 17 import 'package:analyzer/source/error_processor.dart'; |
| 17 import 'package:analyzer/src/dart/ast/token.dart'; | 18 import 'package:analyzer/src/dart/ast/token.dart'; |
| 18 import 'package:analyzer/src/error/codes.dart'; | 19 import 'package:analyzer/src/error/codes.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); | 81 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); |
| 81 | 82 |
| 82 // Run the checker on /main.dart. | 83 // Run the checker on /main.dart. |
| 83 Source mainSource = uriResolver.resolveAbsolute(mainFile.toUri()); | 84 Source mainSource = uriResolver.resolveAbsolute(mainFile.toUri()); |
| 84 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); | 85 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); |
| 85 | 86 |
| 86 var collector = new _ErrorCollector(context); | 87 var collector = new _ErrorCollector(context); |
| 87 | 88 |
| 88 // Extract expectations from the comments in the test files, and | 89 // Extract expectations from the comments in the test files, and |
| 89 // check that all errors we emit are included in the expected map. | 90 // check that all errors we emit are included in the expected map. |
| 90 var allLibraries = _reachableLibraries(initialLibrary.element.library); | 91 var allLibraries = |
| 92 _reachableLibraries(elementForCompilationUnit(initialLibrary).library); |
| 91 for (var lib in allLibraries) { | 93 for (var lib in allLibraries) { |
| 92 for (var unit in lib.units) { | 94 for (var unit in lib.units) { |
| 93 var errors = <AnalysisError>[]; | 95 var errors = <AnalysisError>[]; |
| 94 collector.errors = errors; | 96 collector.errors = errors; |
| 95 | 97 |
| 96 var source = unit.source; | 98 var source = unit.source; |
| 97 if (source.uri.scheme == 'dart') continue; | 99 if (source.uri.scheme == 'dart') continue; |
| 98 | 100 |
| 99 var librarySource = context.getLibrariesContaining(source).single; | 101 var librarySource = context.getLibrariesContaining(source).single; |
| 100 var resolved = context.resolveCompilationUnit2(source, librarySource); | 102 var resolved = context.resolveCompilationUnit2(source, librarySource); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 278 } |
| 277 | 279 |
| 278 void _reportFailure( | 280 void _reportFailure( |
| 279 AnalysisContext context, | 281 AnalysisContext context, |
| 280 CompilationUnit unit, | 282 CompilationUnit unit, |
| 281 List<_ErrorExpectation> unreported, | 283 List<_ErrorExpectation> unreported, |
| 282 List<AnalysisError> unexpected, | 284 List<AnalysisError> unexpected, |
| 283 Map<_ErrorExpectation, AnalysisError> different) { | 285 Map<_ErrorExpectation, AnalysisError> different) { |
| 284 // Get the source code. This reads the data again, but it's safe because | 286 // Get the source code. This reads the data again, but it's safe because |
| 285 // all tests use memory file system. | 287 // all tests use memory file system. |
| 286 var sourceCode = unit.element.source.contents.data; | 288 var sourceCode = elementForCompilationUnit(unit).source.contents.data; |
| 287 | 289 |
| 288 String formatActualError(AnalysisError error) { | 290 String formatActualError(AnalysisError error) { |
| 289 int offset = error.offset; | 291 int offset = error.offset; |
| 290 int length = error.length; | 292 int length = error.length; |
| 291 var span = _createSpanHelper( | 293 var span = _createSpanHelper(unit.lineInfo, offset, |
| 292 unit.lineInfo, offset, unit.element.source, sourceCode, | 294 elementForCompilationUnit(unit).source, sourceCode, |
| 293 end: offset + length); | 295 end: offset + length); |
| 294 var levelName = _errorSeverity(context, error).displayName; | 296 var levelName = _errorSeverity(context, error).displayName; |
| 295 return '@$offset $levelName:${_errorCodeName(error.errorCode)}\n' + | 297 return '@$offset $levelName:${_errorCodeName(error.errorCode)}\n' + |
| 296 span.message(error.message); | 298 span.message(error.message); |
| 297 } | 299 } |
| 298 | 300 |
| 299 String formatExpectedError(_ErrorExpectation error) { | 301 String formatExpectedError(_ErrorExpectation error) { |
| 300 int offset = error.offset; | 302 int offset = error.offset; |
| 301 var span = _createSpanHelper( | 303 var span = _createSpanHelper(unit.lineInfo, offset, |
| 302 unit.lineInfo, offset, unit.element.source, sourceCode); | 304 elementForCompilationUnit(unit).source, sourceCode); |
| 303 var severity = error.severity.displayName; | 305 var severity = error.severity.displayName; |
| 304 return '@$offset $severity:${error.typeName}\n' + span.message(''); | 306 return '@$offset $severity:${error.typeName}\n' + span.message(''); |
| 305 } | 307 } |
| 306 | 308 |
| 307 var message = new StringBuffer(); | 309 var message = new StringBuffer(); |
| 308 if (unreported.isNotEmpty) { | 310 if (unreported.isNotEmpty) { |
| 309 message.writeln('Expected errors that were not reported:'); | 311 message.writeln('Expected errors that were not reported:'); |
| 310 unreported.map(formatExpectedError).forEach(message.writeln); | 312 unreported.map(formatExpectedError).forEach(message.writeln); |
| 311 message.writeln(); | 313 message.writeln(); |
| 312 } | 314 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 @override | 402 @override |
| 401 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 403 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 402 if (uri.scheme == 'package') { | 404 if (uri.scheme == 'package') { |
| 403 return (provider.getResource( | 405 return (provider.getResource( |
| 404 provider.convertPath('/packages/' + uri.path)) as File) | 406 provider.convertPath('/packages/' + uri.path)) as File) |
| 405 .createSource(uri); | 407 .createSource(uri); |
| 406 } | 408 } |
| 407 return super.resolveAbsolute(uri, actualUri); | 409 return super.resolveAbsolute(uri, actualUri); |
| 408 } | 410 } |
| 409 } | 411 } |
| OLD | NEW |