| 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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/error/error.dart'; | 12 import 'package:analyzer/error/error.dart'; |
| 13 import 'package:analyzer/error/listener.dart'; | 13 import 'package:analyzer/error/listener.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 15 import 'package:analyzer/file_system/memory_file_system.dart'; | 15 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 16 import 'package:analyzer/source/error_processor.dart'; | 16 import 'package:analyzer/source/error_processor.dart'; |
| 17 import 'package:analyzer/src/dart/ast/token.dart'; | 17 import 'package:analyzer/src/dart/ast/token.dart'; |
| 18 import 'package:analyzer/src/error/codes.dart'; | 18 import 'package:analyzer/src/error/codes.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:source_span/source_span.dart'; | 21 import 'package:source_span/source_span.dart'; |
| 22 import 'package:unittest/unittest.dart'; | 22 import 'package:test/test.dart'; |
| 23 | 23 |
| 24 import '../../context/mock_sdk.dart'; | 24 import '../../context/mock_sdk.dart'; |
| 25 | 25 |
| 26 MemoryResourceProvider files; | 26 MemoryResourceProvider files; |
| 27 bool _checkCalled; | 27 bool _checkCalled; |
| 28 | 28 |
| 29 /// Adds a file to check. The file should contain: | 29 /// Adds a file to check. The file should contain: |
| 30 /// | 30 /// |
| 31 /// * all expected failures are listed in the source code using comments | 31 /// * all expected failures are listed in the source code using comments |
| 32 /// immediately in front of the AST node that should contain the error. | 32 /// immediately in front of the AST node that should contain the error. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 /// Adds a file using [addFile] and calls [check]. | 118 /// Adds a file using [addFile] and calls [check]. |
| 119 /// | 119 /// |
| 120 /// Also returns the resolved compilation unit. | 120 /// Also returns the resolved compilation unit. |
| 121 CompilationUnit checkFile(String content) { | 121 CompilationUnit checkFile(String content) { |
| 122 addFile(content); | 122 addFile(content); |
| 123 return check(); | 123 return check(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void initStrongModeTests() { | 126 void doSetUp() { |
| 127 setUp(() { | 127 AnalysisEngine.instance.processRequiredPlugins(); |
| 128 AnalysisEngine.instance.processRequiredPlugins(); | 128 files = new MemoryResourceProvider(); |
| 129 files = new MemoryResourceProvider(); | 129 _checkCalled = false; |
| 130 _checkCalled = false; | 130 } |
| 131 }); | |
| 132 | 131 |
| 133 tearDown(() { | 132 void doTearDown() { |
| 134 // This is a sanity check, in case only addFile is called. | 133 // This is a sanity check, in case only addFile is called. |
| 135 expect(_checkCalled, true, reason: 'must call check() method in test case'); | 134 expect(_checkCalled, true, reason: 'must call check() method in test case'); |
| 136 files = null; | 135 files = null; |
| 137 }); | |
| 138 } | 136 } |
| 139 | 137 |
| 140 SourceSpanWithContext _createSpanHelper( | 138 SourceSpanWithContext _createSpanHelper( |
| 141 LineInfo lineInfo, int start, Source source, String content, | 139 LineInfo lineInfo, int start, Source source, String content, |
| 142 {int end}) { | 140 {int end}) { |
| 143 var startLoc = _locationForOffset(lineInfo, source.uri, start); | 141 var startLoc = _locationForOffset(lineInfo, source.uri, start); |
| 144 var endLoc = _locationForOffset(lineInfo, source.uri, end ?? start); | 142 var endLoc = _locationForOffset(lineInfo, source.uri, end ?? start); |
| 145 | 143 |
| 146 var lineStart = startLoc.offset - startLoc.column; | 144 var lineStart = startLoc.offset - startLoc.column; |
| 147 // Find the end of the line. This is not exposed directly on LineInfo, but | 145 // Find the end of the line. This is not exposed directly on LineInfo, but |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 399 |
| 402 @override | 400 @override |
| 403 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 401 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 404 if (uri.scheme == 'package') { | 402 if (uri.scheme == 'package') { |
| 405 return (provider.getResource('/packages/' + uri.path) as File) | 403 return (provider.getResource('/packages/' + uri.path) as File) |
| 406 .createSource(uri); | 404 .createSource(uri); |
| 407 } | 405 } |
| 408 return super.resolveAbsolute(uri, actualUri); | 406 return super.resolveAbsolute(uri, actualUri); |
| 409 } | 407 } |
| 410 } | 408 } |
| OLD | NEW |