| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 files.newFile(name, content); | 47 files.newFile(name, content); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// Run the checker on a program, staring from '/main.dart', and verifies that | 50 /// Run the checker on a program, staring from '/main.dart', and verifies that |
| 51 /// errors/warnings/hints match the expected value. | 51 /// errors/warnings/hints match the expected value. |
| 52 /// | 52 /// |
| 53 /// See [addFile] for more information about how to encode expectations in | 53 /// See [addFile] for more information about how to encode expectations in |
| 54 /// the file text. | 54 /// the file text. |
| 55 /// | 55 /// |
| 56 /// Returns the main resolved library. This can be used for further checks. | 56 /// Returns the main resolved library. This can be used for further checks. |
| 57 CompilationUnit check() { | 57 CompilationUnit check({bool implicitCasts: true}) { |
| 58 _checkCalled = true; | 58 _checkCalled = true; |
| 59 | 59 |
| 60 expect(files.getFile('/main.dart').exists, true, | 60 expect(files.getFile('/main.dart').exists, true, |
| 61 reason: '`/main.dart` is missing'); | 61 reason: '`/main.dart` is missing'); |
| 62 | 62 |
| 63 var uriResolver = new _TestUriResolver(files); | 63 var uriResolver = new _TestUriResolver(files); |
| 64 // Enable task model strong mode | 64 // Enable task model strong mode |
| 65 var context = AnalysisEngine.instance.createAnalysisContext(); | 65 var context = AnalysisEngine.instance.createAnalysisContext(); |
| 66 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; | 66 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; |
| 67 options.strongMode = true; | 67 options.strongMode = true; |
| 68 options.strongModeHints = true; | 68 options.strongModeHints = true; |
| 69 options.implicitCasts = implicitCasts; |
| 69 var mockSdk = new MockSdk(); | 70 var mockSdk = new MockSdk(); |
| 70 mockSdk.context.analysisOptions.strongMode = true; | 71 mockSdk.context.analysisOptions.strongMode = true; |
| 71 context.sourceFactory = | 72 context.sourceFactory = |
| 72 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); | 73 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); |
| 73 | 74 |
| 74 // Run the checker on /main.dart. | 75 // Run the checker on /main.dart. |
| 75 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 76 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); |
| 76 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); | 77 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); |
| 77 | 78 |
| 78 var collector = new _ErrorCollector(); | 79 var collector = new _ErrorCollector(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 394 |
| 394 @override | 395 @override |
| 395 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 396 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 396 if (uri.scheme == 'package') { | 397 if (uri.scheme == 'package') { |
| 397 return (provider.getResource('/packages/' + uri.path) as File) | 398 return (provider.getResource('/packages/' + uri.path) as File) |
| 398 .createSource(uri); | 399 .createSource(uri); |
| 399 } | 400 } |
| 400 return super.resolveAbsolute(uri, actualUri); | 401 return super.resolveAbsolute(uri, actualUri); |
| 401 } | 402 } |
| 402 } | 403 } |
| OLD | NEW |