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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/driver_test.dart

Issue 2808173002: Prioritize analysis of files that import the changed file, or have an error or warning. (Closed)
Patch Set: Use separate buckets for each file category. Created 3 years, 8 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 | « pkg/analyzer/lib/src/dart/analysis/file_tracker.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.test.driver; 5 library analyzer.test.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return driver; 90 return driver;
91 } 91 }
92 92
93 void setUp() { 93 void setUp() {
94 sdk = new MockSdk(resourceProvider: provider); 94 sdk = new MockSdk(resourceProvider: provider);
95 logger = new PerformanceLog(logBuffer); 95 logger = new PerformanceLog(logBuffer);
96 scheduler = new AnalysisDriverScheduler(logger); 96 scheduler = new AnalysisDriverScheduler(logger);
97 scheduler.start(); 97 scheduler.start();
98 } 98 }
99 99
100 test_priorities_allChangedFirst() async {
101 AnalysisDriver driver1 = newDriver();
102 AnalysisDriver driver2 = newDriver();
103
104 String a = _p('/a.dart');
105 String b = _p('/b.dart');
106 String c = _p('/c.dart');
107 String d = _p('/d.dart');
108 provider.newFile(a, 'class A {}');
109 provider.newFile(b, "import 'a.dart';");
110 provider.newFile(c, 'class C {}');
111 provider.newFile(d, "import 'c.dart';");
112 driver1.addFile(a);
113 driver1.addFile(b);
114 driver2.addFile(c);
115 driver2.addFile(d);
116
117 await scheduler.waitForIdle();
118 allResults.clear();
119
120 provider.updateFile(a, 'class A2 {}');
121 provider.updateFile(c, 'class C2 {}');
122 driver1.changeFile(a);
123 driver1.changeFile(c);
124 driver2.changeFile(a);
125 driver2.changeFile(c);
126
127 await scheduler.waitForIdle();
128 expect(allResults, hasLength(greaterThanOrEqualTo(2)));
129 expect(allResults[0].path, a);
130 expect(allResults[1].path, c);
131 }
132
133 test_priorities_firstChanged_thenImporting() async {
134 AnalysisDriver driver1 = newDriver();
135 AnalysisDriver driver2 = newDriver();
136
137 String a = _p('/a.dart');
138 String b = _p('/b.dart');
139 String c = _p('/c.dart');
140 provider.newFile(a, "import 'c.dart';");
141 provider.newFile(b, 'class B {}');
142 provider.newFile(c, "import 'b.dart';");
143 driver1.addFile(a);
144 driver1.addFile(b);
145 driver2.addFile(c);
146
147 await scheduler.waitForIdle();
148 allResults.clear();
149
150 provider.updateFile(b, 'class B2 {}');
151 driver1.changeFile(b);
152 driver2.changeFile(b);
153
154 await scheduler.waitForIdle();
155 expect(allResults, hasLength(greaterThanOrEqualTo(2)));
156 expect(allResults[0].path, b);
157 expect(allResults[1].path, c);
158 }
159
160 test_priorities_firstChanged_thenWithErrors() async {
161 AnalysisDriver driver1 = newDriver();
162 AnalysisDriver driver2 = newDriver();
163
164 String a = _p('/a.dart');
165 String b = _p('/b.dart');
166 String c = _p('/c.dart');
167 String d = _p('/d.dart');
168 provider.newFile(a, 'class A {}');
169 provider.newFile(b, "export 'a.dart';");
170 provider.newFile(c, "import 'b.dart';");
171 provider.newFile(d, "import 'b.dart'; class D extends X {}");
172 driver1.addFile(a);
173 driver1.addFile(b);
174 driver2.addFile(c);
175 driver2.addFile(d);
176
177 await scheduler.waitForIdle();
178 allResults.clear();
179
180 provider.updateFile(a, 'class A2 {}');
181 driver1.changeFile(a);
182 driver2.changeFile(a);
183
184 await scheduler.waitForIdle();
185 expect(allResults, hasLength(greaterThanOrEqualTo(2)));
186 expect(allResults[0].path, a);
187 expect(allResults[1].path, d);
188 }
189
100 test_priorities_getResult_beforePriority() async { 190 test_priorities_getResult_beforePriority() async {
101 AnalysisDriver driver1 = newDriver(); 191 AnalysisDriver driver1 = newDriver();
102 AnalysisDriver driver2 = newDriver(); 192 AnalysisDriver driver2 = newDriver();
103 193
104 String a = _p('/a.dart'); 194 String a = _p('/a.dart');
105 String b = _p('/b.dart'); 195 String b = _p('/b.dart');
106 String c = _p('/c.dart'); 196 String c = _p('/c.dart');
107 provider.newFile(a, 'class A {}'); 197 provider.newFile(a, 'class A {}');
108 provider.newFile(b, 'class B {}'); 198 provider.newFile(b, 'class B {}');
109 provider.newFile(c, 'class C {}'); 199 provider.newFile(c, 'class C {}');
(...skipping 2062 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 allResults.clear(); 2262 allResults.clear();
2173 2263
2174 // Remove a.dart, now b.dart should be reanalyzed and has an error. 2264 // Remove a.dart, now b.dart should be reanalyzed and has an error.
2175 provider.deleteFile(a); 2265 provider.deleteFile(a);
2176 driver.removeFile(a); 2266 driver.removeFile(a);
2177 await scheduler.waitForIdle(); 2267 await scheduler.waitForIdle();
2178 expect(allResults.singleWhere((r) => r.path == b).errors, hasLength(2)); 2268 expect(allResults.singleWhere((r) => r.path == b).errors, hasLength(2));
2179 allResults.clear(); 2269 allResults.clear();
2180 } 2270 }
2181 2271
2272 test_results_order() async {
2273 var a = _p('/test/lib/a.dart');
2274 var b = _p('/test/lib/b.dart');
2275 var c = _p('/test/lib/c.dart');
2276 var d = _p('/test/lib/d.dart');
2277 var e = _p('/test/lib/e.dart');
2278 var f = _p('/test/lib/f.dart');
2279 provider.newFile(
2280 a,
2281 r'''
2282 import 'd.dart';
2283 ''');
2284 provider.newFile(b, '');
2285 provider.newFile(
2286 c,
2287 r'''
2288 import 'd.dart';
2289 ''');
2290 provider.newFile(
2291 d,
2292 r'''
2293 import 'b.dart';
2294 ''');
2295 provider.newFile(
2296 e,
2297 r'''
2298 export 'b.dart';
2299 ''');
2300 provider.newFile(
2301 f,
2302 r'''
2303 import 'e.dart';
2304 class F extends X {}
2305 ''');
2306
2307 driver.addFile(a);
2308 driver.addFile(b);
2309 driver.addFile(c);
2310 driver.addFile(d);
2311 driver.addFile(e);
2312 driver.addFile(f);
2313 await scheduler.waitForIdle();
2314
2315 // The file f.dart has an error or warning.
2316 // So, its analysis will have higher priority.
2317 expect(driver.fsState.getFileForPath(f).hasErrorOrWarning, isTrue);
2318
2319 allResults.clear();
2320
2321 // Update a.dart with changing its API signature.
2322 provider.updateFile(b, 'class A {}');
2323 driver.changeFile(b);
2324 await scheduler.waitForIdle();
2325
2326 List<String> analyzedPaths = allResults.map((r) => r.path).toList();
2327
2328 // The changed file must be the first.
2329 expect(analyzedPaths[0], b);
2330
2331 // Then the file that imports the changed file.
2332 expect(analyzedPaths[1], d);
2333
2334 // Then the file that has an error (even if it is unrelated).
2335 expect(analyzedPaths[2], f);
2336 }
2337
2338 test_results_order_allChangedFirst_thenImports() async {
2339 var a = _p('/test/lib/a.dart');
2340 var b = _p('/test/lib/b.dart');
2341 var c = _p('/test/lib/c.dart');
2342 var d = _p('/test/lib/d.dart');
2343 var e = _p('/test/lib/e.dart');
2344 provider.newFile(a, 'class A {}');
2345 provider.newFile(b, 'class B {}');
2346 provider.newFile(c, '');
2347 provider.newFile(d, "import 'a.dart';");
2348 provider.newFile(e, "import 'b.dart';");
2349
2350 driver.addFile(a);
2351 driver.addFile(b);
2352 driver.addFile(c);
2353 driver.addFile(d);
2354 driver.addFile(e);
2355 await scheduler.waitForIdle();
2356
2357 allResults.clear();
2358
2359 // Change b.dart and then a.dart files.
2360 // So, a.dart and b.dart should be analyzed first.
2361 // Then d.dart and e.dart because they import a.dart and b.dart files.
2362 provider.updateFile(a, 'class A2 {}');
2363 provider.updateFile(b, 'class B2 {}');
2364 driver.changeFile(b);
2365 driver.changeFile(a);
2366 await scheduler.waitForIdle();
2367
2368 List<String> analyzedPaths = allResults.map((r) => r.path).toList();
2369
2370 // The changed files must be the first.
2371 expect(analyzedPaths[0], a);
2372 expect(analyzedPaths[1], b);
2373
2374 // Then the file that imports the changed file.
2375 expect(analyzedPaths[2], d);
2376 expect(analyzedPaths[3], e);
2377 }
2378
2182 test_results_priority() async { 2379 test_results_priority() async {
2183 String content = 'int f() => 42;'; 2380 String content = 'int f() => 42;';
2184 addTestFile(content, priority: true); 2381 addTestFile(content, priority: true);
2185 2382
2186 await scheduler.waitForIdle(); 2383 await scheduler.waitForIdle();
2187 2384
2188 expect(allResults, hasLength(1)); 2385 expect(allResults, hasLength(1));
2189 AnalysisResult result = allResults.single; 2386 AnalysisResult result = allResults.single;
2190 expect(result.path, testFile); 2387 expect(result.path, testFile);
2191 expect(result.uri.toString(), 'package:test/test.dart'); 2388 expect(result.uri.toString(), 'package:test/test.dart');
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 * Return the [provider] specific path for the given Posix [path]. 2597 * Return the [provider] specific path for the given Posix [path].
2401 */ 2598 */
2402 String _p(String path) => provider.convertPath(path); 2599 String _p(String path) => provider.convertPath(path);
2403 2600
2404 static String _md5(String content) { 2601 static String _md5(String content) {
2405 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 2602 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
2406 } 2603 }
2407 } 2604 }
2408 2605
2409 class _SourceMock extends TypedMock implements Source {} 2606 class _SourceMock extends TypedMock implements Source {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/file_tracker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698