| 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 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 /// dynamic x = /*warning:Box*/3; | 70 /// dynamic x = /*warning:Box*/3; |
| 71 /// } | 71 /// } |
| 72 /// ''' | 72 /// ''' |
| 73 /// }); | 73 /// }); |
| 74 /// | 74 /// |
| 75 void testChecker(String name, Map<String, String> testFiles, | 75 void testChecker(String name, Map<String, String> testFiles, |
| 76 {String sdkDir, | 76 {String sdkDir, |
| 77 customUrlMappings: const {}, | 77 customUrlMappings: const {}, |
| 78 relaxedCasts: true, | 78 relaxedCasts: true, |
| 79 inferDownwards: StrongModeOptions.inferDownwardsDefault, | 79 inferDownwards: StrongModeOptions.inferDownwardsDefault, |
| 80 inferFromOverrides: StrongModeOptions.inferFromOverridesDefault, | |
| 81 inferTransitively: StrongModeOptions.inferTransitivelyDefault, | 80 inferTransitively: StrongModeOptions.inferTransitivelyDefault, |
| 82 nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}) { | 81 nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}) { |
| 83 test(name, () { | 82 test(name, () { |
| 84 expect(testFiles.containsKey('/main.dart'), isTrue, | 83 expect(testFiles.containsKey('/main.dart'), isTrue, |
| 85 reason: '`/main.dart` is missing in testFiles'); | 84 reason: '`/main.dart` is missing in testFiles'); |
| 86 | 85 |
| 87 var provider = createTestResourceProvider(testFiles); | 86 var provider = createTestResourceProvider(testFiles); |
| 88 var uriResolver = new TestUriResolver(provider); | 87 var uriResolver = new TestUriResolver(provider); |
| 89 // Enable task model strong mode | 88 // Enable task model strong mode |
| 90 AnalysisEngine.instance.useTaskModel = true; | 89 AnalysisEngine.instance.useTaskModel = true; |
| 91 var context = AnalysisEngine.instance.createAnalysisContext(); | 90 var context = AnalysisEngine.instance.createAnalysisContext(); |
| 92 context.analysisOptions.strongMode = true; | 91 context.analysisOptions.strongMode = true; |
| 93 context.sourceFactory = createSourceFactory( | 92 context.sourceFactory = createSourceFactory( |
| 94 new SourceResolverOptions( | 93 new SourceResolverOptions( |
| 95 customUrlMappings: customUrlMappings, | 94 customUrlMappings: customUrlMappings, |
| 96 useMockSdk: sdkDir == null, | 95 useMockSdk: sdkDir == null, |
| 97 dartSdkPath: sdkDir), | 96 dartSdkPath: sdkDir), |
| 98 fileResolvers: [uriResolver]); | 97 fileResolvers: [uriResolver]); |
| 99 | 98 |
| 100 var checker = new StrongChecker( | 99 var checker = new StrongChecker( |
| 101 context, | 100 context, |
| 102 new StrongModeOptions( | 101 new StrongModeOptions( |
| 103 relaxedCasts: relaxedCasts, | 102 relaxedCasts: relaxedCasts, |
| 104 inferDownwards: inferDownwards, | 103 inferDownwards: inferDownwards, |
| 105 inferFromOverrides: inferFromOverrides, | |
| 106 inferTransitively: inferTransitively, | 104 inferTransitively: inferTransitively, |
| 107 nonnullableTypes: nonnullableTypes, | 105 nonnullableTypes: nonnullableTypes, |
| 108 hints: true)); | 106 hints: true)); |
| 109 | 107 |
| 110 // Run the checker on /main.dart. | 108 // Run the checker on /main.dart. |
| 111 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 109 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); |
| 112 var initialLibrary = | 110 var initialLibrary = |
| 113 context.resolveCompilationUnit2(mainSource, mainSource); | 111 context.resolveCompilationUnit2(mainSource, mainSource); |
| 114 | 112 |
| 115 // Extract expectations from the comments in the test files, and | 113 // Extract expectations from the comments in the test files, and |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 expect(tokens[1], "should", reason: 'invalid error descriptor'); | 278 expect(tokens[1], "should", reason: 'invalid error descriptor'); |
| 281 expect(tokens[2], "be", reason: 'invalid error descriptor'); | 279 expect(tokens[2], "be", reason: 'invalid error descriptor'); |
| 282 if (tokens[0] == "pass") return null; | 280 if (tokens[0] == "pass") return null; |
| 283 // TODO(leafp) For now, we just use whatever the current expectation is, | 281 // TODO(leafp) For now, we just use whatever the current expectation is, |
| 284 // eventually we could do more automated reporting here. | 282 // eventually we could do more automated reporting here. |
| 285 return _parse(tokens[0]); | 283 return _parse(tokens[0]); |
| 286 } | 284 } |
| 287 | 285 |
| 288 String toString() => '$level $typeName'; | 286 String toString() => '$level $typeName'; |
| 289 } | 287 } |
| OLD | NEW |