| 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 inferTransitively: StrongModeOptions.inferTransitivelyDefault, | 80 inferTransitively: StrongModeOptions.inferTransitivelyDefault}) { |
| 81 nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}) { | |
| 82 test(name, () { | 81 test(name, () { |
| 83 expect(testFiles.containsKey('/main.dart'), isTrue, | 82 expect(testFiles.containsKey('/main.dart'), isTrue, |
| 84 reason: '`/main.dart` is missing in testFiles'); | 83 reason: '`/main.dart` is missing in testFiles'); |
| 85 | 84 |
| 86 var provider = createTestResourceProvider(testFiles); | 85 var provider = createTestResourceProvider(testFiles); |
| 87 var uriResolver = new TestUriResolver(provider); | 86 var uriResolver = new TestUriResolver(provider); |
| 88 // Enable task model strong mode | 87 // Enable task model strong mode |
| 89 AnalysisEngine.instance.useTaskModel = true; | 88 AnalysisEngine.instance.useTaskModel = true; |
| 90 var context = AnalysisEngine.instance.createAnalysisContext(); | 89 var context = AnalysisEngine.instance.createAnalysisContext(); |
| 91 context.analysisOptions.strongMode = true; | 90 context.analysisOptions.strongMode = true; |
| 92 context.sourceFactory = createSourceFactory( | 91 context.sourceFactory = createSourceFactory( |
| 93 new SourceResolverOptions( | 92 new SourceResolverOptions( |
| 94 customUrlMappings: customUrlMappings, | 93 customUrlMappings: customUrlMappings, |
| 95 useMockSdk: sdkDir == null, | 94 useMockSdk: sdkDir == null, |
| 96 dartSdkPath: sdkDir), | 95 dartSdkPath: sdkDir), |
| 97 fileResolvers: [uriResolver]); | 96 fileResolvers: [uriResolver]); |
| 98 | 97 |
| 99 var checker = new StrongChecker( | 98 var checker = new StrongChecker( |
| 100 context, | 99 context, |
| 101 new StrongModeOptions( | 100 new StrongModeOptions( |
| 102 relaxedCasts: relaxedCasts, | 101 relaxedCasts: relaxedCasts, |
| 103 inferDownwards: inferDownwards, | 102 inferDownwards: inferDownwards, |
| 104 inferTransitively: inferTransitively, | 103 inferTransitively: inferTransitively, |
| 105 nonnullableTypes: nonnullableTypes, | |
| 106 hints: true)); | 104 hints: true)); |
| 107 | 105 |
| 108 // Run the checker on /main.dart. | 106 // Run the checker on /main.dart. |
| 109 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); | 107 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); |
| 110 var initialLibrary = | 108 var initialLibrary = |
| 111 context.resolveCompilationUnit2(mainSource, mainSource); | 109 context.resolveCompilationUnit2(mainSource, mainSource); |
| 112 | 110 |
| 113 // Extract expectations from the comments in the test files, and | 111 // Extract expectations from the comments in the test files, and |
| 114 // check that all errors we emit are included in the expected map. | 112 // check that all errors we emit are included in the expected map. |
| 115 var allLibraries = reachableLibraries(initialLibrary.element.library); | 113 var allLibraries = reachableLibraries(initialLibrary.element.library); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 expect(tokens[1], "should", reason: 'invalid error descriptor'); | 276 expect(tokens[1], "should", reason: 'invalid error descriptor'); |
| 279 expect(tokens[2], "be", reason: 'invalid error descriptor'); | 277 expect(tokens[2], "be", reason: 'invalid error descriptor'); |
| 280 if (tokens[0] == "pass") return null; | 278 if (tokens[0] == "pass") return null; |
| 281 // TODO(leafp) For now, we just use whatever the current expectation is, | 279 // TODO(leafp) For now, we just use whatever the current expectation is, |
| 282 // eventually we could do more automated reporting here. | 280 // eventually we could do more automated reporting here. |
| 283 return _parse(tokens[0]); | 281 return _parse(tokens[0]); |
| 284 } | 282 } |
| 285 | 283 |
| 286 String toString() => '$level $typeName'; | 284 String toString() => '$level $typeName'; |
| 287 } | 285 } |
| OLD | NEW |