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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 void addFile(String content, {String name: '/main.dart'}) { | 45 void addFile(String content, {String name: '/main.dart'}) { |
46 name = name.replaceFirst('^package:', '/packages/'); | 46 name = name.replaceFirst('^package:', '/packages/'); |
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 void check() { | 55 /// |
| 56 /// Returns the main resolved library. This can be used for further checks. |
| 57 CompilationUnit check() { |
56 _checkCalled = true; | 58 _checkCalled = true; |
57 | 59 |
58 expect(files.getFile('/main.dart').exists, true, | 60 expect(files.getFile('/main.dart').exists, true, |
59 reason: '`/main.dart` is missing'); | 61 reason: '`/main.dart` is missing'); |
60 | 62 |
61 var uriResolver = new _TestUriResolver(files); | 63 var uriResolver = new _TestUriResolver(files); |
62 // Enable task model strong mode | 64 // Enable task model strong mode |
63 var context = AnalysisEngine.instance.createAnalysisContext(); | 65 var context = AnalysisEngine.instance.createAnalysisContext(); |
64 context.analysisOptions.strongMode = true; | 66 context.analysisOptions.strongMode = true; |
65 (context.analysisOptions as AnalysisOptionsImpl).strongModeHints = true; | 67 (context.analysisOptions as AnalysisOptionsImpl).strongModeHints = true; |
(...skipping 20 matching lines...) Expand all Loading... |
86 var librarySource = context.getLibrariesContaining(source).single; | 88 var librarySource = context.getLibrariesContaining(source).single; |
87 var resolved = context.resolveCompilationUnit2(source, librarySource); | 89 var resolved = context.resolveCompilationUnit2(source, librarySource); |
88 errors.addAll(context.getErrors(source).errors.where((e) => | 90 errors.addAll(context.getErrors(source).errors.where((e) => |
89 e.errorCode != HintCode.UNUSED_LOCAL_VARIABLE && | 91 e.errorCode != HintCode.UNUSED_LOCAL_VARIABLE && |
90 // TODO(jmesserly): these are usually intentional dynamic calls. | 92 // TODO(jmesserly): these are usually intentional dynamic calls. |
91 e.errorCode.name != 'UNDEFINED_METHOD')); | 93 e.errorCode.name != 'UNDEFINED_METHOD')); |
92 | 94 |
93 _expectErrors(resolved, errors); | 95 _expectErrors(resolved, errors); |
94 } | 96 } |
95 } | 97 } |
| 98 |
| 99 return initialLibrary; |
96 } | 100 } |
97 | 101 |
98 /// Adds a file using [addFile] and calls [check]. | 102 /// Adds a file using [addFile] and calls [check]. |
99 void checkFile(String content) { | 103 /// |
| 104 /// Also returns the resolved compilation unit. |
| 105 CompilationUnit checkFile(String content) { |
100 addFile(content); | 106 addFile(content); |
101 check(); | 107 return check(); |
102 } | 108 } |
103 | 109 |
104 SourceSpanWithContext _createSpanHelper( | 110 SourceSpanWithContext _createSpanHelper( |
105 LineInfo lineInfo, int start, Source source, String content, | 111 LineInfo lineInfo, int start, Source source, String content, |
106 {int end}) { | 112 {int end}) { |
107 var startLoc = _locationForOffset(lineInfo, source.uri, start); | 113 var startLoc = _locationForOffset(lineInfo, source.uri, start); |
108 var endLoc = _locationForOffset(lineInfo, source.uri, end ?? start); | 114 var endLoc = _locationForOffset(lineInfo, source.uri, end ?? start); |
109 | 115 |
110 var lineStart = startLoc.offset - startLoc.column; | 116 var lineStart = startLoc.offset - startLoc.column; |
111 // Find the end of the line. This is not exposed directly on LineInfo, but | 117 // Find the end of the line. This is not exposed directly on LineInfo, but |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 384 |
379 @override | 385 @override |
380 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 386 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
381 if (uri.scheme == 'package') { | 387 if (uri.scheme == 'package') { |
382 return (provider.getResource('/packages/' + uri.path) as File) | 388 return (provider.getResource('/packages/' + uri.path) as File) |
383 .createSource(uri); | 389 .createSource(uri); |
384 } | 390 } |
385 return super.resolveAbsolute(uri, actualUri); | 391 return super.resolveAbsolute(uri, actualUri); |
386 } | 392 } |
387 } | 393 } |
OLD | NEW |