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

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

Issue 2566003002: When a file is removed from the driver, reschedule full analysis. (Closed)
Patch Set: Created 4 years 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_state.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 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 expect(driver.hasFilesToAnalyze, isFalse); 960 expect(driver.hasFilesToAnalyze, isFalse);
961 961
962 // Request of referenced names is not analysis of a file. 962 // Request of referenced names is not analysis of a file.
963 driver.getFilesReferencingName('X'); 963 driver.getFilesReferencingName('X');
964 expect(driver.hasFilesToAnalyze, isFalse); 964 expect(driver.hasFilesToAnalyze, isFalse);
965 } 965 }
966 966
967 test_knownFiles() async { 967 test_knownFiles() async {
968 var a = _p('/test/lib/a.dart'); 968 var a = _p('/test/lib/a.dart');
969 var b = _p('/test/lib/b.dart'); 969 var b = _p('/test/lib/b.dart');
970 var c = _p('/test/lib/c.dart');
970 971
971 provider.newFile( 972 provider.newFile(
972 a, 973 a,
973 r''' 974 r'''
974 import 'b.dart'; 975 import 'b.dart';
975 '''); 976 ''');
977 provider.newFile(b, '');
978 provider.newFile(c, '');
976 979
977 driver.addFile(a); 980 driver.addFile(a);
981 driver.addFile(c);
978 await _waitForIdle(); 982 await _waitForIdle();
979 983
980 expect(driver.knownFiles, contains(a)); 984 expect(driver.knownFiles, unorderedEquals([a, b, c]));
981 expect(driver.knownFiles, contains(b));
982 985
986 // Remove a.dart and analyze.
987 // Both a.dart and b.dart are not known now.
983 driver.removeFile(a); 988 driver.removeFile(a);
984 989 await _waitForIdle();
985 // a.dart was removed, but we don't clean up the file state state yet. 990 expect(driver.knownFiles, unorderedEquals([c]));
986 expect(driver.knownFiles, contains(a));
987 expect(driver.knownFiles, contains(b));
988 } 991 }
989 992
990 test_knownFiles_beforeAnalysis() async { 993 test_knownFiles_beforeAnalysis() async {
991 var a = _p('/test/lib/a.dart'); 994 var a = _p('/test/lib/a.dart');
992 var b = _p('/test/lib/b.dart'); 995 var b = _p('/test/lib/b.dart');
993 996
994 provider.newFile(a, ''); 997 provider.newFile(a, '');
995 998
996 // 'a.dart' is added, but not processed yet. 999 // 'a.dart' is added, but not processed yet.
997 // So, the set of known files is empty yet. 1000 // So, the set of known files is empty yet.
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 // Remove the file and send the change notification. 1333 // Remove the file and send the change notification.
1331 // The change notification does nothing, because the file is explicitly 1334 // The change notification does nothing, because the file is explicitly
1332 // or implicitly analyzed. 1335 // or implicitly analyzed.
1333 driver.removeFile(testFile); 1336 driver.removeFile(testFile);
1334 driver.changeFile(testFile); 1337 driver.changeFile(testFile);
1335 1338
1336 await _waitForIdle(); 1339 await _waitForIdle();
1337 expect(allResults, isEmpty); 1340 expect(allResults, isEmpty);
1338 } 1341 }
1339 1342
1343 test_removeFile_invalidate_importers() async {
1344 var a = _p('/test/lib/a.dart');
1345 var b = _p('/test/lib/b.dart');
1346
1347 provider.newFile(a, 'class A {}');
1348 provider.newFile(b, "import 'a.dart'; var a = new A();");
1349
1350 driver.addFile(a);
1351 driver.addFile(b);
1352 await _waitForIdle();
1353
1354 // b.dart s clean.
1355 expect(allResults.singleWhere((r) => r.path == b).errors, isEmpty);
1356 allResults.clear();
1357
1358 // Remove a.dart, now b.dart should be reanalyzed and has an error.
1359 provider.deleteFile(a);
1360 driver.removeFile(a);
1361 await _waitForIdle();
1362 expect(allResults.singleWhere((r) => r.path == b).errors, hasLength(2));
1363 allResults.clear();
1364 }
1365
1340 test_results_priority() async { 1366 test_results_priority() async {
1341 String content = 'int f() => 42;'; 1367 String content = 'int f() => 42;';
1342 addTestFile(content, priority: true); 1368 addTestFile(content, priority: true);
1343 1369
1344 await _waitForIdle(); 1370 await _waitForIdle();
1345 1371
1346 expect(allResults, hasLength(1)); 1372 expect(allResults, hasLength(1));
1347 AnalysisResult result = allResults.single; 1373 AnalysisResult result = allResults.single;
1348 expect(result.path, testFile); 1374 expect(result.path, testFile);
1349 expect(result.uri.toString(), 'package:test/test.dart'); 1375 expect(result.uri.toString(), 'package:test/test.dart');
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 String _p(String path) => provider.convertPath(path); 1527 String _p(String path) => provider.convertPath(path);
1502 1528
1503 Future<Null> _waitForIdle() async { 1529 Future<Null> _waitForIdle() async {
1504 await idleStatusMonitor.signal; 1530 await idleStatusMonitor.signal;
1505 } 1531 }
1506 1532
1507 static String _md5(String content) { 1533 static String _md5(String content) {
1508 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 1534 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
1509 } 1535 }
1510 } 1536 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/file_state.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698