Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: test/testing.dart

Issue 1273343002: fix testChecker to include test inside (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/checker/inferred_type_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 /// conversion, you can describe the test as follows: 65 /// conversion, you can describe the test as follows:
66 /// 66 ///
67 /// testChecker({ 67 /// testChecker({
68 /// '/main.dart': ''' 68 /// '/main.dart': '''
69 /// testMethod() { 69 /// testMethod() {
70 /// dynamic x = /*warning:Box*/3; 70 /// dynamic x = /*warning:Box*/3;
71 /// } 71 /// }
72 /// ''' 72 /// '''
73 /// }); 73 /// });
74 /// 74 ///
75 void testChecker(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, 80 inferFromOverrides: StrongModeOptions.inferFromOverridesDefault,
81 inferTransitively: StrongModeOptions.inferTransitivelyDefault, 81 inferTransitively: StrongModeOptions.inferTransitivelyDefault,
82 nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}) { 82 nonnullableTypes: StrongModeOptions.NONNULLABLE_TYPES}) {
83 expect(testFiles.containsKey('/main.dart'), isTrue, 83 test(name, () {
84 reason: '`/main.dart` is missing in testFiles'); 84 expect(testFiles.containsKey('/main.dart'), isTrue,
85 reason: '`/main.dart` is missing in testFiles');
85 86
86 var provider = createTestResourceProvider(testFiles); 87 var provider = createTestResourceProvider(testFiles);
87 var uriResolver = new TestUriResolver(provider); 88 var uriResolver = new TestUriResolver(provider);
88 var context = AnalysisEngine.instance.createAnalysisContext(); 89 var context = AnalysisEngine.instance.createAnalysisContext();
89 context.sourceFactory = createSourceFactory( 90 context.sourceFactory = createSourceFactory(
90 new SourceResolverOptions( 91 new SourceResolverOptions(
91 customUrlMappings: customUrlMappings, 92 customUrlMappings: customUrlMappings,
92 useMockSdk: sdkDir == null, 93 useMockSdk: sdkDir == null,
93 dartSdkPath: sdkDir), 94 dartSdkPath: sdkDir),
94 fileResolvers: [uriResolver]); 95 fileResolvers: [uriResolver]);
95 96
96 var checker = new StrongChecker( 97 var checker = new StrongChecker(
97 context, 98 context,
98 new StrongModeOptions( 99 new StrongModeOptions(
99 relaxedCasts: relaxedCasts, 100 relaxedCasts: relaxedCasts,
100 inferDownwards: inferDownwards, 101 inferDownwards: inferDownwards,
101 inferFromOverrides: inferFromOverrides, 102 inferFromOverrides: inferFromOverrides,
102 inferTransitively: inferTransitively, 103 inferTransitively: inferTransitively,
103 nonnullableTypes: nonnullableTypes, 104 nonnullableTypes: nonnullableTypes,
104 hints: true)); 105 hints: true));
105 106
106 // Run the checker on /main.dart. 107 // Run the checker on /main.dart.
107 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart')); 108 var mainSource = uriResolver.resolveAbsolute(new Uri.file('/main.dart'));
108 var initialLibrary = context.resolveCompilationUnit2(mainSource, mainSource); 109 var initialLibrary =
110 context.resolveCompilationUnit2(mainSource, mainSource);
109 111
110 // Extract expectations from the comments in the test files, and 112 // Extract expectations from the comments in the test files, and
111 // check that all errors we emit are included in the expected map. 113 // check that all errors we emit are included in the expected map.
112 var allLibraries = reachableLibraries(initialLibrary.element.library); 114 var allLibraries = reachableLibraries(initialLibrary.element.library);
113 for (var lib in allLibraries) { 115 for (var lib in allLibraries) {
114 for (var unit in lib.units) { 116 for (var unit in lib.units) {
115 if (unit.source.uri.scheme == 'dart') continue; 117 if (unit.source.uri.scheme == 'dart') continue;
116 118
117 var errorInfo = checker.computeErrors(unit.source); 119 var errorInfo = checker.computeErrors(unit.source);
118 new _ExpectedErrorVisitor(errorInfo.errors).validate(unit.unit); 120 new _ExpectedErrorVisitor(errorInfo.errors).validate(unit.unit);
121 }
119 } 122 }
120 } 123 });
121 } 124 }
122 125
123 /// Creates a [MemoryResourceProvider] with test data 126 /// Creates a [MemoryResourceProvider] with test data
124 MemoryResourceProvider createTestResourceProvider( 127 MemoryResourceProvider createTestResourceProvider(
125 Map<String, String> testFiles) { 128 Map<String, String> testFiles) {
126 var provider = new MemoryResourceProvider(); 129 var provider = new MemoryResourceProvider();
127 runtimeFilesForServerMode.forEach((filepath) { 130 runtimeFilesForServerMode.forEach((filepath) {
128 testFiles['/dev_compiler_runtime/$filepath'] = 131 testFiles['/dev_compiler_runtime/$filepath'] =
129 '/* test contents of $filepath */'; 132 '/* test contents of $filepath */';
130 }); 133 });
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 expect(tokens[1], "should", reason: 'invalid error descriptor'); 277 expect(tokens[1], "should", reason: 'invalid error descriptor');
275 expect(tokens[2], "be", reason: 'invalid error descriptor'); 278 expect(tokens[2], "be", reason: 'invalid error descriptor');
276 if (tokens[0] == "pass") return null; 279 if (tokens[0] == "pass") return null;
277 // TODO(leafp) For now, we just use whatever the current expectation is, 280 // TODO(leafp) For now, we just use whatever the current expectation is,
278 // eventually we could do more automated reporting here. 281 // eventually we could do more automated reporting here.
279 return _parse(tokens[0]); 282 return _parse(tokens[0]);
280 } 283 }
281 284
282 String toString() => '$level $typeName'; 285 String toString() => '$level $typeName';
283 } 286 }
OLDNEW
« no previous file with comments | « test/checker/inferred_type_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698