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

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

Issue 2656233004: Use AnalysisDriver.getErrors() to get cached errors for already analyzed files. (Closed)
Patch Set: Created 3 years, 10 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
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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 687
688 driver.priorityFiles = [templatePath]; 688 driver.priorityFiles = [templatePath];
689 driver.changeFile(templatePath); 689 driver.changeFile(templatePath);
690 await driver.waitForIdle(); 690 await driver.waitForIdle();
691 expect(allExceptions, isEmpty); 691 expect(allExceptions, isEmpty);
692 expect(allResults, isEmpty); 692 expect(allResults, isEmpty);
693 693
694 expect(driver.knownFiles, isNot(contains(templatePath))); 694 expect(driver.knownFiles, isNot(contains(templatePath)));
695 } 695 }
696 696
697 test_getErrors() async {
698 String content = 'int f() => 42 + bar();';
699 addTestFile(content, priority: true);
700
701 ErrorsResult result = await driver.getErrors(testFile);
702 expect(result.path, testFile);
703 expect(result.uri.toString(), 'package:test/test.dart');
704 expect(result.contentHash, _md5(content));
705 expect(result.errors, hasLength(1));
706 }
707
697 test_getFilesReferencingName() async { 708 test_getFilesReferencingName() async {
698 var a = _p('/test/bin/a.dart'); 709 var a = _p('/test/bin/a.dart');
699 var b = _p('/test/bin/b.dart'); 710 var b = _p('/test/bin/b.dart');
700 var c = _p('/test/bin/c.dart'); 711 var c = _p('/test/bin/c.dart');
701 var d = _p('/test/bin/d.dart'); 712 var d = _p('/test/bin/d.dart');
702 var e = _p('/test/bin/e.dart'); 713 var e = _p('/test/bin/e.dart');
703 714
704 provider.newFile(a, 'class A {}'); 715 provider.newFile(a, 'class A {}');
705 provider.newFile(b, "import 'a.dart'; A a;"); 716 provider.newFile(b, "import 'a.dart'; A a;");
706 provider.newFile(c, "import 'a.dart'; var a = new A();"); 717 provider.newFile(c, "import 'a.dart'; var a = new A();");
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 await driver.getResult(p); 1369 await driver.getResult(p);
1359 1370
1360 // Update the file. 1371 // Update the file.
1361 provider.newFile(p, 'class A2 {}'); 1372 provider.newFile(p, 'class A2 {}');
1362 1373
1363 ParseResult parseResult = await driver.parseFile(p); 1374 ParseResult parseResult = await driver.parseFile(p);
1364 var clazz = parseResult.unit.declarations[0] as ClassDeclaration; 1375 var clazz = parseResult.unit.declarations[0] as ClassDeclaration;
1365 expect(clazz.name.name, 'A2'); 1376 expect(clazz.name.name, 'A2');
1366 } 1377 }
1367 1378
1379 test_part_getErrors_afterLibrary() async {
1380 var a = _p('/test/lib/a.dart');
1381 var b = _p('/test/lib/b.dart');
1382 var c = _p('/test/lib/c.dart');
1383 provider.newFile(
1384 a,
1385 r'''
1386 library a;
1387 import 'b.dart';
1388 part 'c.dart';
1389 class A {}
1390 var c = new C();
1391 ''');
1392 provider.newFile(b, 'class B {}');
1393 provider.newFile(
1394 c,
1395 r'''
1396 part of a;
1397 class C {}
1398 var a = new A();
1399 var b = new B();
1400 ''');
1401
1402 driver.addFile(a);
1403 driver.addFile(b);
1404 driver.addFile(c);
1405
1406 // Process a.dart so that we know that it's a library for c.dart later.
1407 {
1408 ErrorsResult result = await driver.getErrors(a);
1409 expect(result.errors, isEmpty);
1410 }
1411
1412 // c.dart does not have errors in the context of a.dart
1413 {
1414 ErrorsResult result = await driver.getErrors(c);
1415 expect(result.errors, isEmpty);
1416 }
1417 }
1418
1419 test_part_getErrors_beforeLibrary() async {
1420 var a = _p('/test/lib/a.dart');
1421 var b = _p('/test/lib/b.dart');
1422 var c = _p('/test/lib/c.dart');
1423 provider.newFile(
1424 a,
1425 r'''
1426 library a;
1427 import 'b.dart';
1428 part 'c.dart';
1429 class A {}
1430 var c = new C();
1431 ''');
1432 provider.newFile(b, 'class B {}');
1433 provider.newFile(
1434 c,
1435 r'''
1436 part of a;
1437 class C {}
1438 var a = new A();
1439 var b = new B();
1440 ''');
1441
1442 driver.addFile(a);
1443 driver.addFile(b);
1444 driver.addFile(c);
1445
1446 // c.dart is resolve in the context of a.dart, so have no errors
1447 {
1448 ErrorsResult result = await driver.getErrors(c);
1449 expect(result.errors, isEmpty);
1450 }
1451 }
1452
1368 test_part_getResult_afterLibrary() async { 1453 test_part_getResult_afterLibrary() async {
1369 var a = _p('/test/lib/a.dart'); 1454 var a = _p('/test/lib/a.dart');
1370 var b = _p('/test/lib/b.dart'); 1455 var b = _p('/test/lib/b.dart');
1371 var c = _p('/test/lib/c.dart'); 1456 var c = _p('/test/lib/c.dart');
1372 provider.newFile( 1457 provider.newFile(
1373 a, 1458 a,
1374 r''' 1459 r'''
1375 library a; 1460 library a;
1376 import 'b.dart'; 1461 import 'b.dart';
1377 part 'c.dart'; 1462 part 'c.dart';
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 * Return the [provider] specific path for the given Posix [path]. 1977 * Return the [provider] specific path for the given Posix [path].
1893 */ 1978 */
1894 String _p(String path) => provider.convertPath(path); 1979 String _p(String path) => provider.convertPath(path);
1895 1980
1896 static String _md5(String content) { 1981 static String _md5(String content) {
1897 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 1982 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
1898 } 1983 }
1899 } 1984 }
1900 1985
1901 class _SourceMock extends TypedMock implements Source {} 1986 class _SourceMock extends TypedMock implements Source {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer_cli/lib/src/analyzer_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698