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/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
(...skipping 29 matching lines...) Expand all Loading... |
40 /// | 40 /// |
41 /// testChecker({ | 41 /// testChecker({ |
42 /// '/main.dart': ''' | 42 /// '/main.dart': ''' |
43 /// testMethod() { | 43 /// testMethod() { |
44 /// dynamic x = /*warning:Box*/3; | 44 /// dynamic x = /*warning:Box*/3; |
45 /// } | 45 /// } |
46 /// ''' | 46 /// ''' |
47 /// }); | 47 /// }); |
48 /// | 48 /// |
49 CheckerResults testChecker(Map<String, String> testFiles, | 49 CheckerResults testChecker(Map<String, String> testFiles, |
50 {bool allowConstCasts: true, String sdkDir, | 50 {bool allowConstCasts: true, String sdkDir, customUrlMappings: const {}, |
51 CheckerReporter createReporter(AnalysisContext context), | 51 CheckerReporter createReporter(AnalysisContext context), |
52 covariantGenerics: true, relaxedCasts: true, | 52 covariantGenerics: true, relaxedCasts: true, |
53 inferDownwards: RulesOptions.inferDownwardsDefault, | 53 inferDownwards: RulesOptions.inferDownwardsDefault, |
54 inferFromOverrides: ResolverOptions.inferFromOverridesDefault, | 54 inferFromOverrides: ResolverOptions.inferFromOverridesDefault, |
55 inferTransitively: ResolverOptions.inferTransitivelyDefault, | 55 inferTransitively: ResolverOptions.inferTransitivelyDefault, |
56 nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, | 56 nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, |
57 wrapClosures: RulesOptions.wrapClosuresDefault}) { | 57 wrapClosures: RulesOptions.wrapClosuresDefault}) { |
58 expect(testFiles.containsKey('/main.dart'), isTrue, | 58 expect(testFiles.containsKey('/main.dart'), isTrue, |
59 reason: '`/main.dart` is missing in testFiles'); | 59 reason: '`/main.dart` is missing in testFiles'); |
60 | 60 |
61 var provider = createTestResourceProvider(testFiles); | 61 var provider = createTestResourceProvider(testFiles); |
62 var uriResolver = new TestUriResolver(provider); | 62 var uriResolver = new TestUriResolver(provider); |
63 | 63 |
64 var options = new CompilerOptions( | 64 var options = new CompilerOptions( |
65 allowConstCasts: allowConstCasts, | 65 allowConstCasts: allowConstCasts, |
66 covariantGenerics: covariantGenerics, | 66 covariantGenerics: covariantGenerics, |
67 relaxedCasts: relaxedCasts, | 67 relaxedCasts: relaxedCasts, |
68 inferDownwards: inferDownwards, | 68 inferDownwards: inferDownwards, |
69 inferFromOverrides: inferFromOverrides, | 69 inferFromOverrides: inferFromOverrides, |
70 inferTransitively: inferTransitively, | 70 inferTransitively: inferTransitively, |
71 nonnullableTypes: nonnullableTypes, | 71 nonnullableTypes: nonnullableTypes, |
72 wrapClosures: wrapClosures, | 72 wrapClosures: wrapClosures, |
73 useMockSdk: sdkDir == null, | 73 useMockSdk: sdkDir == null, |
74 dartSdkPath: sdkDir, | 74 dartSdkPath: sdkDir, |
75 runtimeDir: '/dev_compiler_runtime/', | 75 runtimeDir: '/dev_compiler_runtime/', |
76 entryPointFile: '/main.dart'); | 76 entryPointFile: '/main.dart', |
| 77 customUrlMappings: customUrlMappings); |
77 | 78 |
78 var context = createAnalysisContext(options, fileResolvers: [uriResolver]); | 79 var context = createAnalysisContext(options, fileResolvers: [uriResolver]); |
79 | 80 |
80 // Run the checker on /main.dart. | 81 // Run the checker on /main.dart. |
81 var mainFile = new Uri.file('/main.dart'); | 82 var mainFile = new Uri.file('/main.dart'); |
82 TestReporter testReporter; | 83 TestReporter testReporter; |
83 CheckerReporter reporter; | 84 CheckerReporter reporter; |
84 if (createReporter == null) { | 85 if (createReporter == null) { |
85 reporter = testReporter = new TestReporter(context); | 86 reporter = testReporter = new TestReporter(context); |
86 } else { | 87 } else { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 expect(tokens[1], "should", reason: 'invalid error descriptor'); | 301 expect(tokens[1], "should", reason: 'invalid error descriptor'); |
301 expect(tokens[2], "be", reason: 'invalid error descriptor'); | 302 expect(tokens[2], "be", reason: 'invalid error descriptor'); |
302 if (tokens[0] == "pass") return null; | 303 if (tokens[0] == "pass") return null; |
303 // TODO(leafp) For now, we just use whatever the current expectation is, | 304 // TODO(leafp) For now, we just use whatever the current expectation is, |
304 // eventually we could do more automated reporting here. | 305 // eventually we could do more automated reporting here. |
305 return _parse(tokens[0]); | 306 return _parse(tokens[0]); |
306 } | 307 } |
307 | 308 |
308 String toString() => '$level $type'; | 309 String toString() => '$level $type'; |
309 } | 310 } |
OLD | NEW |