| 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'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 /// See [addFile] for more information about how to encode expectations in | 55 /// See [addFile] for more information about how to encode expectations in |
| 56 /// the file text. | 56 /// the file text. |
| 57 /// | 57 /// |
| 58 /// Returns the main resolved library. This can be used for further checks. | 58 /// Returns the main resolved library. This can be used for further checks. |
| 59 CompilationUnit check( | 59 CompilationUnit check( |
| 60 {bool implicitCasts: true, | 60 {bool implicitCasts: true, |
| 61 bool implicitDynamic: true, | 61 bool implicitDynamic: true, |
| 62 List<String> nonnullableTypes: AnalysisOptionsImpl.NONNULLABLE_TYPES}) { | 62 List<String> nonnullableTypes: AnalysisOptionsImpl.NONNULLABLE_TYPES}) { |
| 63 _checkCalled = true; | 63 _checkCalled = true; |
| 64 | 64 |
| 65 expect(files.getFile(files.convertPath('/main.dart')).exists, true, | 65 File mainFile = files.getFile(files.convertPath('/main.dart')); |
| 66 reason: '`/main.dart` is missing'); | 66 expect(mainFile.exists, true, reason: '`/main.dart` is missing'); |
| 67 | 67 |
| 68 var uriResolver = new _TestUriResolver(files); | 68 var uriResolver = new _TestUriResolver(files); |
| 69 // Enable task model strong mode | 69 // Enable task model strong mode |
| 70 var context = AnalysisEngine.instance.createAnalysisContext(); | 70 var context = AnalysisEngine.instance.createAnalysisContext(); |
| 71 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; | 71 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; |
| 72 options.strongMode = true; | 72 options.strongMode = true; |
| 73 options.strongModeHints = true; | 73 options.strongModeHints = true; |
| 74 options.implicitCasts = implicitCasts; | 74 options.implicitCasts = implicitCasts; |
| 75 options.implicitDynamic = implicitDynamic; | 75 options.implicitDynamic = implicitDynamic; |
| 76 options.nonnullableTypes = nonnullableTypes; | 76 options.nonnullableTypes = nonnullableTypes; |
| 77 var mockSdk = new MockSdk(); | 77 var mockSdk = new MockSdk(resourceProvider: files); |
| 78 (mockSdk.context.analysisOptions as AnalysisOptionsImpl).strongMode = true; | 78 (mockSdk.context.analysisOptions as AnalysisOptionsImpl).strongMode = true; |
| 79 context.sourceFactory = | 79 context.sourceFactory = |
| 80 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); | 80 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); |
| 81 | 81 |
| 82 // Run the checker on /main.dart. | 82 // Run the checker on /main.dart. |
| 83 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 83 Source mainSource = uriResolver.resolveAbsolute(mainFile.toUri()); |
| 84 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); | 84 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); |
| 85 | 85 |
| 86 var collector = new _ErrorCollector(context); | 86 var collector = new _ErrorCollector(context); |
| 87 | 87 |
| 88 // Extract expectations from the comments in the test files, and | 88 // Extract expectations from the comments in the test files, and |
| 89 // check that all errors we emit are included in the expected map. | 89 // check that all errors we emit are included in the expected map. |
| 90 var allLibraries = _reachableLibraries(initialLibrary.element.library); | 90 var allLibraries = _reachableLibraries(initialLibrary.element.library); |
| 91 for (var lib in allLibraries) { | 91 for (var lib in allLibraries) { |
| 92 for (var unit in lib.units) { | 92 for (var unit in lib.units) { |
| 93 var errors = <AnalysisError>[]; | 93 var errors = <AnalysisError>[]; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 393 |
| 394 class _TestUriResolver extends ResourceUriResolver { | 394 class _TestUriResolver extends ResourceUriResolver { |
| 395 final MemoryResourceProvider provider; | 395 final MemoryResourceProvider provider; |
| 396 _TestUriResolver(provider) | 396 _TestUriResolver(provider) |
| 397 : provider = provider, | 397 : provider = provider, |
| 398 super(provider); | 398 super(provider); |
| 399 | 399 |
| 400 @override | 400 @override |
| 401 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 401 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 402 if (uri.scheme == 'package') { | 402 if (uri.scheme == 'package') { |
| 403 return (provider.getResource('/packages/' + uri.path) as File) | 403 return (provider.getResource( |
| 404 provider.convertPath('/packages/' + uri.path)) as File) |
| 404 .createSource(uri); | 405 .createSource(uri); |
| 405 } | 406 } |
| 406 return super.resolveAbsolute(uri, actualUri); | 407 return super.resolveAbsolute(uri, actualUri); |
| 407 } | 408 } |
| 408 } | 409 } |
| OLD | NEW |