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({bool implicitCasts: true, bool implicitDynamic: true}) { | 57 CompilationUnit check( |
| 58 {bool implicitCasts: true, |
| 59 bool implicitDynamic: true, |
| 60 List<String> nonnullableTypes: AnalysisOptionsImpl.NONNULLABLE_TYPES}) { |
58 _checkCalled = true; | 61 _checkCalled = true; |
59 | 62 |
60 expect(files.getFile('/main.dart').exists, true, | 63 expect(files.getFile('/main.dart').exists, true, |
61 reason: '`/main.dart` is missing'); | 64 reason: '`/main.dart` is missing'); |
62 | 65 |
63 var uriResolver = new _TestUriResolver(files); | 66 var uriResolver = new _TestUriResolver(files); |
64 // Enable task model strong mode | 67 // Enable task model strong mode |
65 var context = AnalysisEngine.instance.createAnalysisContext(); | 68 var context = AnalysisEngine.instance.createAnalysisContext(); |
66 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; | 69 AnalysisOptionsImpl options = context.analysisOptions as AnalysisOptionsImpl; |
67 options.strongMode = true; | 70 options.strongMode = true; |
68 options.strongModeHints = true; | 71 options.strongModeHints = true; |
69 options.implicitCasts = implicitCasts; | 72 options.implicitCasts = implicitCasts; |
70 options.implicitDynamic = implicitDynamic; | 73 options.implicitDynamic = implicitDynamic; |
| 74 options.nonnullableTypes = nonnullableTypes; |
71 var mockSdk = new MockSdk(); | 75 var mockSdk = new MockSdk(); |
72 (mockSdk.context.analysisOptions as AnalysisOptionsImpl).strongMode = true; | 76 (mockSdk.context.analysisOptions as AnalysisOptionsImpl).strongMode = true; |
73 context.sourceFactory = | 77 context.sourceFactory = |
74 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); | 78 new SourceFactory([new DartUriResolver(mockSdk), uriResolver]); |
75 | 79 |
76 // Run the checker on /main.dart. | 80 // Run the checker on /main.dart. |
77 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 81 Source mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); |
78 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); | 82 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); |
79 | 83 |
80 var collector = new _ErrorCollector(context); | 84 var collector = new _ErrorCollector(context); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 399 |
396 @override | 400 @override |
397 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 401 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
398 if (uri.scheme == 'package') { | 402 if (uri.scheme == 'package') { |
399 return (provider.getResource('/packages/' + uri.path) as File) | 403 return (provider.getResource('/packages/' + uri.path) as File) |
400 .createSource(uri); | 404 .createSource(uri); |
401 } | 405 } |
402 return super.resolveAbsolute(uri, actualUri); | 406 return super.resolveAbsolute(uri, actualUri); |
403 } | 407 } |
404 } | 408 } |
OLD | NEW |