| 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 library dev_compiler.src.testing; | 5 library dev_compiler.src.testing; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:logging/logging.dart'; | 11 import 'package:logging/logging.dart'; |
| 12 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
| 13 import 'package:source_span/source_span.dart'; | 13 import 'package:source_span/source_span.dart'; |
| 14 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 15 | 15 |
| 16 import 'package:dev_compiler/src/checker/dart_sdk.dart' | 16 import 'package:dev_compiler/src/checker/dart_sdk.dart' |
| 17 show mockSdkSources, dartSdkDirectory; | 17 show mockSdkSources, dartSdkDirectory; |
| 18 import 'package:dev_compiler/src/checker/resolver.dart' show TypeResolver; | 18 import 'package:dev_compiler/src/checker/resolver.dart' show TypeResolver; |
| 19 import 'package:dev_compiler/src/utils.dart'; | 19 import 'package:dev_compiler/src/utils.dart'; |
| 20 import 'package:dev_compiler/src/info.dart'; | 20 import 'package:dev_compiler/src/info.dart'; |
| 21 import 'package:dev_compiler/src/options.dart'; | 21 import 'package:dev_compiler/src/options.dart'; |
| 22 import 'package:dev_compiler/src/report.dart'; | 22 import 'package:dev_compiler/src/report.dart'; |
| 23 import 'package:dev_compiler/config.dart'; | 23 import 'package:dev_compiler/config.dart'; |
| 24 import 'package:dev_compiler/devc.dart' show Compiler; | 24 import 'package:dev_compiler/devc.dart' show Compiler; |
| 25 | 25 |
| 26 import 'dependency_graph.dart' show runtimeFilesForServerMode; |
| 27 |
| 26 /// Run the checker on a program with files contents as indicated in | 28 /// Run the checker on a program with files contents as indicated in |
| 27 /// [testFiles]. | 29 /// [testFiles]. |
| 28 /// | 30 /// |
| 29 /// This function makes several assumptions to make it easier to describe error | 31 /// This function makes several assumptions to make it easier to describe error |
| 30 /// expectations: | 32 /// expectations: |
| 31 /// | 33 /// |
| 32 /// * a file named `/main.dart` exists in [testFiles]. | 34 /// * a file named `/main.dart` exists in [testFiles]. |
| 33 /// * all expected failures are listed in the source code using comments | 35 /// * all expected failures are listed in the source code using comments |
| 34 /// immediately in front of the AST node that should contain the error. | 36 /// immediately in front of the AST node that should contain the error. |
| 35 /// * errors are formatted as a token `level:Type`, where `level` is the | 37 /// * errors are formatted as a token `level:Type`, where `level` is the |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 var testUriResolver = new TestUriResolver(testFiles); | 62 var testUriResolver = new TestUriResolver(testFiles); |
| 61 var options = new CompilerOptions( | 63 var options = new CompilerOptions( |
| 62 allowConstCasts: allowConstCasts, | 64 allowConstCasts: allowConstCasts, |
| 63 covariantGenerics: covariantGenerics, | 65 covariantGenerics: covariantGenerics, |
| 64 relaxedCasts: relaxedCasts, | 66 relaxedCasts: relaxedCasts, |
| 65 inferFromOverrides: inferFromOverrides, | 67 inferFromOverrides: inferFromOverrides, |
| 66 inferTransitively: inferTransitively, | 68 inferTransitively: inferTransitively, |
| 67 nonnullableTypes: nonnullableTypes, | 69 nonnullableTypes: nonnullableTypes, |
| 68 useMockSdk: sdkDir == null, | 70 useMockSdk: sdkDir == null, |
| 69 dartSdkPath: sdkDir, | 71 dartSdkPath: sdkDir, |
| 72 runtimeDir: '/dev_compiler_runtime/', |
| 70 entryPointFile: '/main.dart'); | 73 entryPointFile: '/main.dart'); |
| 71 var resolver = sdkDir == null | 74 var resolver = sdkDir == null |
| 72 ? new TypeResolver.fromMock(mockSdkSources, options, | 75 ? new TypeResolver.fromMock(mockSdkSources, options, |
| 73 otherResolvers: [testUriResolver]) | 76 otherResolvers: [testUriResolver]) |
| 74 : new TypeResolver.fromDir(sdkDir, options, | 77 : new TypeResolver.fromDir(sdkDir, options, |
| 75 otherResolvers: [testUriResolver]); | 78 otherResolvers: [testUriResolver]); |
| 76 | 79 |
| 77 // Run the checker on /main.dart. | 80 // Run the checker on /main.dart. |
| 78 var mainFile = new Uri.file('/main.dart'); | 81 var mainFile = new Uri.file('/main.dart'); |
| 79 var checkExpectations = reporter == null; | 82 var checkExpectations = reporter == null; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 /// behavior from analyzer), or to use null (possible when overriding the | 274 /// behavior from analyzer), or to use null (possible when overriding the |
| 272 /// package-url-resolvers.) | 275 /// package-url-resolvers.) |
| 273 final bool representNonExistingFiles; | 276 final bool representNonExistingFiles; |
| 274 | 277 |
| 275 TestUriResolver(Map<String, String> allFiles, | 278 TestUriResolver(Map<String, String> allFiles, |
| 276 {this.representNonExistingFiles: true}) { | 279 {this.representNonExistingFiles: true}) { |
| 277 allFiles.forEach((key, value) { | 280 allFiles.forEach((key, value) { |
| 278 var uri = key.startsWith('package:') ? Uri.parse(key) : new Uri.file(key); | 281 var uri = key.startsWith('package:') ? Uri.parse(key) : new Uri.file(key); |
| 279 files[uri] = new TestSource(uri, value); | 282 files[uri] = new TestSource(uri, value); |
| 280 }); | 283 }); |
| 284 |
| 285 runtimeFilesForServerMode.forEach((filepath) { |
| 286 var uri = Uri.parse('/dev_compiler_runtime/$filepath'); |
| 287 files[uri] = new TestSource(uri, '/* test contents of $filepath */'); |
| 288 }); |
| 281 } | 289 } |
| 282 | 290 |
| 283 Source resolveAbsolute(Uri uri) { | 291 Source resolveAbsolute(Uri uri) { |
| 284 if (uri.scheme != 'file' && uri.scheme != 'package') return null; | 292 if (uri.scheme != 'file' && uri.scheme != 'package') return null; |
| 285 if (!representNonExistingFiles) return files[uri]; | 293 if (!representNonExistingFiles) return files[uri]; |
| 286 return files.putIfAbsent(uri, () => new TestSource(uri, null)); | 294 return files.putIfAbsent(uri, () => new TestSource(uri, null)); |
| 287 } | 295 } |
| 288 } | 296 } |
| 289 | 297 |
| 290 class TestContents implements TimestampedData<String> { | 298 class TestContents implements TimestampedData<String> { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 335 |
| 328 SourceSpan spanFor(AstNode node) { | 336 SourceSpan spanFor(AstNode node) { |
| 329 final begin = node is AnnotatedNode | 337 final begin = node is AnnotatedNode |
| 330 ? node.firstTokenAfterCommentAndMetadata.offset | 338 ? node.firstTokenAfterCommentAndMetadata.offset |
| 331 : node.offset; | 339 : node.offset; |
| 332 return _file.span(begin, node.end); | 340 return _file.span(begin, node.end); |
| 333 } | 341 } |
| 334 | 342 |
| 335 String toString() => '[$runtimeType: $uri]'; | 343 String toString() => '[$runtimeType: $uri]'; |
| 336 } | 344 } |
| OLD | NEW |