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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1842363004: More strong mode fixes for analyzer (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Backout options changes Created 4 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
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 analyzer.test.src.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 List<Source> sources = newSources(sourceMap); 974 List<Source> sources = newSources(sourceMap);
975 Source libSource = sources.first; 975 Source libSource = sources.first;
976 computeResult(libSource, LIBRARY_ELEMENT1, 976 computeResult(libSource, LIBRARY_ELEMENT1,
977 matcher: isBuildLibraryElementTask); 977 matcher: isBuildLibraryElementTask);
978 libraryUnit = context 978 libraryUnit = context
979 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) 979 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource))
980 .getValue(RESOLVED_UNIT1); 980 .getValue(RESOLVED_UNIT1);
981 libraryUnitElement = libraryUnit.element; 981 libraryUnitElement = libraryUnit.element;
982 librarySource = libraryUnitElement.source; 982 librarySource = libraryUnitElement.source;
983 libraryElement = outputs[LIBRARY_ELEMENT1]; 983 libraryElement = outputs[LIBRARY_ELEMENT1];
984 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; 984 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]
985 as List<CompilationUnit>;
985 } 986 }
986 } 987 }
987 988
988 @reflectiveTest 989 @reflectiveTest
989 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest { 990 class BuildPublicNamespaceTaskTest extends _AbstractDartTaskTest {
990 test_perform() { 991 test_perform() {
991 List<Source> sources = newSources({ 992 List<Source> sources = newSources({
992 '/lib.dart': ''' 993 '/lib.dart': '''
993 library lib; 994 library lib;
994 part 'part.dart'; 995 part 'part.dart';
(...skipping 10 matching lines...) Expand all
1005 matcher: isBuildPublicNamespaceTask); 1006 matcher: isBuildPublicNamespaceTask);
1006 // validate 1007 // validate
1007 LibraryElement library = outputs[LIBRARY_ELEMENT3]; 1008 LibraryElement library = outputs[LIBRARY_ELEMENT3];
1008 Namespace namespace = library.publicNamespace; 1009 Namespace namespace = library.publicNamespace;
1009 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); 1010 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd']));
1010 } 1011 }
1011 } 1012 }
1012 1013
1013 @reflectiveTest 1014 @reflectiveTest
1014 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { 1015 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest {
1016 List<Source> getExportSourceClosure(Map<ResultDescriptor, dynamic> outputs) {
1017 return outputs[EXPORT_SOURCE_CLOSURE] as List<Source>;
1018 }
1019
1015 test_perform_exportClosure() { 1020 test_perform_exportClosure() {
1016 Source sourceA = newSource( 1021 Source sourceA = newSource(
1017 '/a.dart', 1022 '/a.dart',
1018 ''' 1023 '''
1019 library lib_a; 1024 library lib_a;
1020 export 'b.dart'; 1025 export 'b.dart';
1021 '''); 1026 ''');
1022 Source sourceB = newSource( 1027 Source sourceB = newSource(
1023 '/b.dart', 1028 '/b.dart',
1024 ''' 1029 '''
1025 library lib_b; 1030 library lib_b;
1026 export 'c.dart'; 1031 export 'c.dart';
1027 '''); 1032 ''');
1028 Source sourceC = newSource( 1033 Source sourceC = newSource(
1029 '/c.dart', 1034 '/c.dart',
1030 ''' 1035 '''
1031 library lib_c; 1036 library lib_c;
1032 export 'a.dart'; 1037 export 'a.dart';
1033 '''); 1038 ''');
1034 Source sourceD = newSource( 1039 Source sourceD = newSource(
1035 '/d.dart', 1040 '/d.dart',
1036 ''' 1041 '''
1037 library lib_d; 1042 library lib_d;
1038 '''); 1043 ''');
1039 // a.dart 1044 // a.dart
1040 { 1045 {
1041 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, 1046 computeResult(sourceA, EXPORT_SOURCE_CLOSURE,
1042 matcher: isBuildSourceExportClosureTask); 1047 matcher: isBuildSourceExportClosureTask);
1043 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1048 List<Source> closure = getExportSourceClosure(outputs);
1044 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); 1049 expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
1045 } 1050 }
1046 // c.dart 1051 // c.dart
1047 { 1052 {
1048 computeResult(sourceC, EXPORT_SOURCE_CLOSURE, 1053 computeResult(sourceC, EXPORT_SOURCE_CLOSURE,
1049 matcher: isBuildSourceExportClosureTask); 1054 matcher: isBuildSourceExportClosureTask);
1050 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1055 List<Source> closure = getExportSourceClosure(outputs);
1051 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); 1056 expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
1052 } 1057 }
1053 // d.dart 1058 // d.dart
1054 { 1059 {
1055 computeResult(sourceD, EXPORT_SOURCE_CLOSURE, 1060 computeResult(sourceD, EXPORT_SOURCE_CLOSURE,
1056 matcher: isBuildSourceExportClosureTask); 1061 matcher: isBuildSourceExportClosureTask);
1057 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1062 List<Source> closure = getExportSourceClosure(outputs);
1058 expect(closure, unorderedEquals([sourceD])); 1063 expect(closure, unorderedEquals([sourceD]));
1059 } 1064 }
1060 } 1065 }
1061 } 1066 }
1062 1067
1063 @reflectiveTest 1068 @reflectiveTest
1064 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { 1069 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest {
1065 test_perform() { 1070 test_perform() {
1066 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER, 1071 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER,
1067 matcher: isBuildTypeProviderTask); 1072 matcher: isBuildTypeProviderTask);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 '''); 1510 ''');
1506 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1511 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1507 computeResult(target, RESOLVED_UNIT5); 1512 computeResult(target, RESOLVED_UNIT5);
1508 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 1513 CompilationUnit unit = outputs[RESOLVED_UNIT5];
1509 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; 1514 TopLevelVariableElement elementA = unit.element.topLevelVariables[0];
1510 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; 1515 TopLevelVariableElement elementB = unit.element.topLevelVariables[1];
1511 1516
1512 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, 1517 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES,
1513 matcher: isComputeInferableStaticVariableDependenciesTask); 1518 matcher: isComputeInferableStaticVariableDependenciesTask);
1514 expect(outputs, hasLength(1)); 1519 expect(outputs, hasLength(1));
1515 List<VariableElement> dependencies = 1520 List<VariableElement> dependencies = outputs[
1516 outputs[INFERABLE_STATIC_VARIABLE_DEPENDENCIES]; 1521 INFERABLE_STATIC_VARIABLE_DEPENDENCIES] as List<VariableElement>;
1517 expect(dependencies, unorderedEquals([elementB])); 1522 expect(dependencies, unorderedEquals([elementB]));
1518 } 1523 }
1519 } 1524 }
1520 1525
1521 @reflectiveTest 1526 @reflectiveTest
1522 class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest { 1527 class ComputeLibraryCycleTaskTest extends _AbstractDartTaskTest {
1528 List<LibraryElement> getLibraryCycle(Map<ResultDescriptor, dynamic> outputs) {
1529 return outputs[LIBRARY_CYCLE] as List<LibraryElement>;
1530 }
1531
1532 List<CompilationUnitElement> getLibraryCycleDependencies(
1533 Map<ResultDescriptor, dynamic> outputs) {
1534 return outputs[LIBRARY_CYCLE_DEPENDENCIES] as List<CompilationUnitElement>;
1535 }
1536
1537 List<CompilationUnitElement> getLibraryCycleUnits(
1538 Map<ResultDescriptor, dynamic> outputs) {
1539 return outputs[LIBRARY_CYCLE_UNITS] as List<CompilationUnitElement>;
1540 }
1541
1523 @override 1542 @override
1524 void setUp() { 1543 void setUp() {
1525 super.setUp(); 1544 super.setUp();
1526 enableStrongMode(); 1545 enableStrongMode();
1527 } 1546 }
1528 1547
1529 void test_library_cycle_incremental() { 1548 void test_library_cycle_incremental() {
1530 enableStrongMode(); 1549 enableStrongMode();
1531 Source lib1Source = newSource( 1550 Source lib1Source = newSource(
1532 '/my_lib1.dart', 1551 '/my_lib1.dart',
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 void test_library_cycle_linear() { 1651 void test_library_cycle_linear() {
1633 List<Source> sources = newSources({ 1652 List<Source> sources = newSources({
1634 '/a.dart': ''' 1653 '/a.dart': '''
1635 ''', 1654 ''',
1636 '/b.dart': ''' 1655 '/b.dart': '''
1637 import 'a.dart'; 1656 import 'a.dart';
1638 ''' 1657 '''
1639 }); 1658 });
1640 List<Map<ResultDescriptor, dynamic>> results = 1659 List<Map<ResultDescriptor, dynamic>> results =
1641 computeLibraryResultsMap(sources, LIBRARY_CYCLE); 1660 computeLibraryResultsMap(sources, LIBRARY_CYCLE);
1642 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; 1661 List<LibraryElement> component0 = getLibraryCycle(results[0]);
1643 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; 1662 List<LibraryElement> component1 = getLibraryCycle(results[1]);
1644 expect(component0, hasLength(1)); 1663 expect(component0, hasLength(1));
1645 expect(component1, hasLength(1)); 1664 expect(component1, hasLength(1));
1646 1665
1647 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; 1666 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results[0]);
1648 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; 1667 List<CompilationUnitElement> units1 = getLibraryCycleUnits(results[1]);
1649 expect(units0, hasLength(1)); 1668 expect(units0, hasLength(1));
1650 expect(units1, hasLength(1)); 1669 expect(units1, hasLength(1));
1651 1670
1652 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; 1671 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results[0]);
1653 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; 1672 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results[1]);
1654 expect(dep0, hasLength(1)); // dart:core 1673 expect(dep0, hasLength(1)); // dart:core
1655 expect(dep1, hasLength(2)); // dart:core, a.dart 1674 expect(dep1, hasLength(2)); // dart:core, a.dart
1656 } 1675 }
1657 1676
1658 void test_library_cycle_loop() { 1677 void test_library_cycle_loop() {
1659 List<Source> sources = newSources({ 1678 List<Source> sources = newSources({
1660 '/a.dart': ''' 1679 '/a.dart': '''
1661 import 'c.dart'; 1680 import 'c.dart';
1662 ''', 1681 ''',
1663 '/b.dart': ''' 1682 '/b.dart': '''
1664 import 'a.dart'; 1683 import 'a.dart';
1665 ''', 1684 ''',
1666 '/c.dart': ''' 1685 '/c.dart': '''
1667 import 'b.dart'; 1686 import 'b.dart';
1668 ''' 1687 '''
1669 }); 1688 });
1670 List<Map<ResultDescriptor, dynamic>> results = 1689 List<Map<ResultDescriptor, dynamic>> results =
1671 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); 1690 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
1672 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; 1691 List<LibraryElement> component0 = getLibraryCycle(results[0]);
1673 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; 1692 List<LibraryElement> component1 = getLibraryCycle(results[1]);
1674 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; 1693 List<LibraryElement> component2 = getLibraryCycle(results[2]);
1675 1694
1676 expect(component0, hasLength(3)); 1695 expect(component0, hasLength(3));
1677 expect(component1, hasLength(3)); 1696 expect(component1, hasLength(3));
1678 expect(component2, hasLength(3)); 1697 expect(component2, hasLength(3));
1679 1698
1680 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; 1699 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results[0]);
1681 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; 1700 List<CompilationUnitElement> units1 = getLibraryCycleUnits(results[1]);
1682 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; 1701 List<CompilationUnitElement> units2 = getLibraryCycleUnits(results[2]);
1683 expect(units0, hasLength(3)); 1702 expect(units0, hasLength(3));
1684 expect(units1, hasLength(3)); 1703 expect(units1, hasLength(3));
1685 expect(units2, hasLength(3)); 1704 expect(units2, hasLength(3));
1686 1705
1687 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; 1706 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results[0]);
1688 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; 1707 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results[1]);
1689 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; 1708 List<CompilationUnitElement> dep2 = getLibraryCycleDependencies(results[2]);
1690 expect(dep0, hasLength(1)); // dart:core 1709 expect(dep0, hasLength(1)); // dart:core
1691 expect(dep1, hasLength(1)); // dart:core 1710 expect(dep1, hasLength(1)); // dart:core
1692 expect(dep2, hasLength(1)); // dart:core 1711 expect(dep2, hasLength(1)); // dart:core
1693 } 1712 }
1694 1713
1695 void test_library_cycle_override_inference_incremental() { 1714 void test_library_cycle_override_inference_incremental() {
1696 enableStrongMode(); 1715 enableStrongMode();
1697 Source lib1Source = newSource( 1716 Source lib1Source = newSource(
1698 '/my_lib1.dart', 1717 '/my_lib1.dart',
1699 ''' 1718 '''
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 } 1768 }
1750 1769
1751 void test_library_cycle_self_loop() { 1770 void test_library_cycle_self_loop() {
1752 List<Source> sources = newSources({ 1771 List<Source> sources = newSources({
1753 '/a.dart': ''' 1772 '/a.dart': '''
1754 import 'a.dart'; 1773 import 'a.dart';
1755 ''' 1774 '''
1756 }); 1775 });
1757 List<Map<ResultDescriptor, dynamic>> results = 1776 List<Map<ResultDescriptor, dynamic>> results =
1758 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); 1777 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
1759 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; 1778 List<LibraryElement> component0 = getLibraryCycle(results[0]);
1760 expect(component0, hasLength(1)); 1779 expect(component0, hasLength(1));
1761 1780
1762 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; 1781 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results[0]);
1763 expect(units0, hasLength(1)); 1782 expect(units0, hasLength(1));
1764 1783
1765 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; 1784 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results[0]);
1766 expect(dep0, hasLength(1)); // dart:core 1785 expect(dep0, hasLength(1)); // dart:core
1767 } 1786 }
1768 1787
1769 void test_library_cycle_singleton() { 1788 void test_library_cycle_singleton() {
1770 Source source = newSource( 1789 Source source = newSource(
1771 '/test.dart', 1790 '/test.dart',
1772 ''' 1791 '''
1773 import 'dart:core'; 1792 import 'dart:core';
1774 '''); 1793 ''');
1775 computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE); 1794 computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE);
1776 List<LibraryElement> component = outputs[LIBRARY_CYCLE]; 1795 List<LibraryElement> component = getLibraryCycle(outputs);
1777 List<CompilationUnitElement> units = outputs[LIBRARY_CYCLE_UNITS]; 1796 List<CompilationUnitElement> units = getLibraryCycleUnits(outputs);
1778 List<CompilationUnitElement> deps = outputs[LIBRARY_CYCLE_DEPENDENCIES]; 1797 List<CompilationUnitElement> deps = getLibraryCycleDependencies(outputs);
1779 expect(component, hasLength(1)); 1798 expect(component, hasLength(1));
1780 expect(units, hasLength(1)); 1799 expect(units, hasLength(1));
1781 expect(deps, hasLength(1)); 1800 expect(deps, hasLength(1));
1782 } 1801 }
1783 1802
1784 void test_library_cycle_tree() { 1803 void test_library_cycle_tree() {
1785 List<Source> sources = newSources({ 1804 List<Source> sources = newSources({
1786 '/a.dart': ''' 1805 '/a.dart': '''
1787 ''', 1806 ''',
1788 '/b.dart': ''' 1807 '/b.dart': '''
1789 ''', 1808 ''',
1790 '/c.dart': ''' 1809 '/c.dart': '''
1791 import 'a.dart'; 1810 import 'a.dart';
1792 import 'b.dart'; 1811 import 'b.dart';
1793 ''' 1812 '''
1794 }); 1813 });
1795 List<Map<ResultDescriptor, dynamic>> results = 1814 List<Map<ResultDescriptor, dynamic>> results =
1796 computeLibraryResultsMap(sources, LIBRARY_CYCLE); 1815 computeLibraryResultsMap(sources, LIBRARY_CYCLE);
1797 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; 1816 List<LibraryElement> component0 = getLibraryCycle(results[0]);
1798 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; 1817 List<LibraryElement> component1 = getLibraryCycle(results[1]);
1799 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; 1818 List<LibraryElement> component2 = getLibraryCycle(results[2]);
1800 expect(component0, hasLength(1)); 1819 expect(component0, hasLength(1));
1801 expect(component1, hasLength(1)); 1820 expect(component1, hasLength(1));
1802 expect(component2, hasLength(1)); 1821 expect(component2, hasLength(1));
1803 1822
1804 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; 1823 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results[0]);
1805 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; 1824 List<CompilationUnitElement> units1 = getLibraryCycleUnits(results[1]);
1806 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; 1825 List<CompilationUnitElement> units2 = getLibraryCycleUnits(results[2]);
1807 expect(units0, hasLength(1)); 1826 expect(units0, hasLength(1));
1808 expect(units1, hasLength(1)); 1827 expect(units1, hasLength(1));
1809 expect(units2, hasLength(1)); 1828 expect(units2, hasLength(1));
1810 1829
1811 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; 1830 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results[0]);
1812 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; 1831 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results[1]);
1813 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; 1832 List<CompilationUnitElement> dep2 = getLibraryCycleDependencies(results[2]);
1814 expect(dep0, hasLength(1)); // dart:core 1833 expect(dep0, hasLength(1)); // dart:core
1815 expect(dep1, hasLength(1)); // dart:core, 1834 expect(dep1, hasLength(1)); // dart:core,
1816 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart 1835 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart
1817 } 1836 }
1818 1837
1819 void test_library_double_loop() { 1838 void test_library_double_loop() {
1820 List<Source> sources = newSources({ 1839 List<Source> sources = newSources({
1821 '/a.dart': ''' 1840 '/a.dart': '''
1822 import 'b.dart'; 1841 import 'b.dart';
1823 ''', 1842 ''',
1824 '/b.dart': ''' 1843 '/b.dart': '''
1825 import 'a.dart'; 1844 import 'a.dart';
1826 ''', 1845 ''',
1827 '/c.dart': ''' 1846 '/c.dart': '''
1828 import 'd.dart' as foo; 1847 import 'd.dart' as foo;
1829 import 'a.dart' as bar; 1848 import 'a.dart' as bar;
1830 export 'b.dart'; 1849 export 'b.dart';
1831 ''', 1850 ''',
1832 '/d.dart': ''' 1851 '/d.dart': '''
1833 import 'c.dart' as foo; 1852 import 'c.dart' as foo;
1834 import 'b.dart' as bar; 1853 import 'b.dart' as bar;
1835 export 'a.dart'; 1854 export 'a.dart';
1836 ''' 1855 '''
1837 }); 1856 });
1838 List<Map<ResultDescriptor, dynamic>> results = 1857 List<Map<ResultDescriptor, dynamic>> results =
1839 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList(); 1858 computeLibraryResultsMap(sources, LIBRARY_CYCLE).toList();
1840 List<LibraryElement> component0 = results[0][LIBRARY_CYCLE]; 1859 List<LibraryElement> component0 = getLibraryCycle(results[0]);
1841 List<LibraryElement> component1 = results[1][LIBRARY_CYCLE]; 1860 List<LibraryElement> component1 = getLibraryCycle(results[1]);
1842 List<LibraryElement> component2 = results[2][LIBRARY_CYCLE]; 1861 List<LibraryElement> component2 = getLibraryCycle(results[2]);
1843 List<LibraryElement> component3 = results[3][LIBRARY_CYCLE]; 1862 List<LibraryElement> component3 = getLibraryCycle(results[3]);
1844 1863
1845 expect(component0, hasLength(2)); 1864 expect(component0, hasLength(2));
1846 expect(component1, hasLength(2)); 1865 expect(component1, hasLength(2));
1847 expect(component2, hasLength(2)); 1866 expect(component2, hasLength(2));
1848 expect(component3, hasLength(2)); 1867 expect(component3, hasLength(2));
1849 1868
1850 List<CompilationUnitElement> units0 = results[0][LIBRARY_CYCLE_UNITS]; 1869 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results[0]);
1851 List<CompilationUnitElement> units1 = results[1][LIBRARY_CYCLE_UNITS]; 1870 List<CompilationUnitElement> units1 = getLibraryCycleUnits(results[1]);
1852 List<CompilationUnitElement> units2 = results[2][LIBRARY_CYCLE_UNITS]; 1871 List<CompilationUnitElement> units2 = getLibraryCycleUnits(results[2]);
1853 List<CompilationUnitElement> units3 = results[3][LIBRARY_CYCLE_UNITS]; 1872 List<CompilationUnitElement> units3 = getLibraryCycleUnits(results[3]);
1854 expect(units0, hasLength(2)); 1873 expect(units0, hasLength(2));
1855 expect(units1, hasLength(2)); 1874 expect(units1, hasLength(2));
1856 expect(units2, hasLength(2)); 1875 expect(units2, hasLength(2));
1857 expect(units3, hasLength(2)); 1876 expect(units3, hasLength(2));
1858 1877
1859 List<CompilationUnitElement> dep0 = results[0][LIBRARY_CYCLE_DEPENDENCIES]; 1878 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results[0]);
1860 List<CompilationUnitElement> dep1 = results[1][LIBRARY_CYCLE_DEPENDENCIES]; 1879 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results[1]);
1861 List<CompilationUnitElement> dep2 = results[2][LIBRARY_CYCLE_DEPENDENCIES]; 1880 List<CompilationUnitElement> dep2 = getLibraryCycleDependencies(results[2]);
1862 List<CompilationUnitElement> dep3 = results[3][LIBRARY_CYCLE_DEPENDENCIES]; 1881 List<CompilationUnitElement> dep3 = getLibraryCycleDependencies(results[3]);
1863 expect(dep0, hasLength(1)); // dart:core 1882 expect(dep0, hasLength(1)); // dart:core
1864 expect(dep1, hasLength(1)); // dart:core 1883 expect(dep1, hasLength(1)); // dart:core
1865 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart 1884 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart
1866 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart 1885 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart
1867 } 1886 }
1868 1887
1869 void test_library_double_loop_parts() { 1888 void test_library_double_loop_parts() {
1870 List<Source> sources = newSources({ 1889 List<Source> sources = newSources({
1871 '/a.dart': ''' 1890 '/a.dart': '''
1872 import 'b.dart'; 1891 import 'b.dart';
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 computeResult( 1934 computeResult(
1916 new LibrarySpecificUnit(sources[5], sources[5]), LIBRARY_CYCLE); 1935 new LibrarySpecificUnit(sources[5], sources[5]), LIBRARY_CYCLE);
1917 Map<ResultDescriptor, dynamic> results5 = outputs; 1936 Map<ResultDescriptor, dynamic> results5 = outputs;
1918 computeResult( 1937 computeResult(
1919 new LibrarySpecificUnit(sources[5], sources[6]), LIBRARY_CYCLE); 1938 new LibrarySpecificUnit(sources[5], sources[6]), LIBRARY_CYCLE);
1920 Map<ResultDescriptor, dynamic> results6 = outputs; 1939 Map<ResultDescriptor, dynamic> results6 = outputs;
1921 computeResult( 1940 computeResult(
1922 new LibrarySpecificUnit(sources[5], sources[7]), LIBRARY_CYCLE); 1941 new LibrarySpecificUnit(sources[5], sources[7]), LIBRARY_CYCLE);
1923 Map<ResultDescriptor, dynamic> results7 = outputs; 1942 Map<ResultDescriptor, dynamic> results7 = outputs;
1924 1943
1925 List<LibraryElement> component0 = results0[LIBRARY_CYCLE]; 1944 List<LibraryElement> component0 = getLibraryCycle(results0);
1926 List<LibraryElement> component1 = results1[LIBRARY_CYCLE]; 1945 List<LibraryElement> component1 = getLibraryCycle(results1);
1927 List<LibraryElement> component2 = results2[LIBRARY_CYCLE]; 1946 List<LibraryElement> component2 = getLibraryCycle(results2);
1928 List<LibraryElement> component3 = results3[LIBRARY_CYCLE]; 1947 List<LibraryElement> component3 = getLibraryCycle(results3);
1929 List<LibraryElement> component4 = results4[LIBRARY_CYCLE]; 1948 List<LibraryElement> component4 = getLibraryCycle(results4);
1930 List<LibraryElement> component5 = results5[LIBRARY_CYCLE]; 1949 List<LibraryElement> component5 = getLibraryCycle(results5);
1931 List<LibraryElement> component6 = results6[LIBRARY_CYCLE]; 1950 List<LibraryElement> component6 = getLibraryCycle(results6);
1932 List<LibraryElement> component7 = results7[LIBRARY_CYCLE]; 1951 List<LibraryElement> component7 = getLibraryCycle(results7);
1933 1952
1934 expect(component0, hasLength(2)); 1953 expect(component0, hasLength(2));
1935 expect(component1, hasLength(2)); 1954 expect(component1, hasLength(2));
1936 expect(component2, hasLength(2)); 1955 expect(component2, hasLength(2));
1937 expect(component3, hasLength(2)); 1956 expect(component3, hasLength(2));
1938 expect(component4, hasLength(2)); 1957 expect(component4, hasLength(2));
1939 expect(component5, hasLength(2)); 1958 expect(component5, hasLength(2));
1940 expect(component6, hasLength(2)); 1959 expect(component6, hasLength(2));
1941 expect(component7, hasLength(2)); 1960 expect(component7, hasLength(2));
1942 1961
1943 List<CompilationUnitElement> units0 = results0[LIBRARY_CYCLE_UNITS]; 1962 List<CompilationUnitElement> units0 = getLibraryCycleUnits(results0);
1944 List<CompilationUnitElement> units1 = results1[LIBRARY_CYCLE_UNITS]; 1963 List<CompilationUnitElement> units1 = getLibraryCycleUnits(results1);
1945 List<CompilationUnitElement> units2 = results2[LIBRARY_CYCLE_UNITS]; 1964 List<CompilationUnitElement> units2 = getLibraryCycleUnits(results2);
1946 List<CompilationUnitElement> units3 = results3[LIBRARY_CYCLE_UNITS]; 1965 List<CompilationUnitElement> units3 = getLibraryCycleUnits(results3);
1947 List<CompilationUnitElement> units4 = results4[LIBRARY_CYCLE_UNITS]; 1966 List<CompilationUnitElement> units4 = getLibraryCycleUnits(results4);
1948 List<CompilationUnitElement> units5 = results5[LIBRARY_CYCLE_UNITS]; 1967 List<CompilationUnitElement> units5 = getLibraryCycleUnits(results5);
1949 List<CompilationUnitElement> units6 = results6[LIBRARY_CYCLE_UNITS]; 1968 List<CompilationUnitElement> units6 = getLibraryCycleUnits(results6);
1950 List<CompilationUnitElement> units7 = results7[LIBRARY_CYCLE_UNITS]; 1969 List<CompilationUnitElement> units7 = getLibraryCycleUnits(results7);
1951 expect(units0, hasLength(4)); 1970 expect(units0, hasLength(4));
1952 expect(units1, hasLength(4)); 1971 expect(units1, hasLength(4));
1953 expect(units2, hasLength(4)); 1972 expect(units2, hasLength(4));
1954 expect(units3, hasLength(4)); 1973 expect(units3, hasLength(4));
1955 expect(units4, hasLength(4)); 1974 expect(units4, hasLength(4));
1956 expect(units5, hasLength(4)); 1975 expect(units5, hasLength(4));
1957 expect(units6, hasLength(4)); 1976 expect(units6, hasLength(4));
1958 expect(units7, hasLength(4)); 1977 expect(units7, hasLength(4));
1959 1978
1960 List<CompilationUnitElement> dep0 = results0[LIBRARY_CYCLE_DEPENDENCIES]; 1979 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results0);
1961 List<CompilationUnitElement> dep1 = results1[LIBRARY_CYCLE_DEPENDENCIES]; 1980 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results1);
1962 List<CompilationUnitElement> dep2 = results2[LIBRARY_CYCLE_DEPENDENCIES]; 1981 List<CompilationUnitElement> dep2 = getLibraryCycleDependencies(results2);
1963 List<CompilationUnitElement> dep3 = results3[LIBRARY_CYCLE_DEPENDENCIES]; 1982 List<CompilationUnitElement> dep3 = getLibraryCycleDependencies(results3);
1964 List<CompilationUnitElement> dep4 = results4[LIBRARY_CYCLE_DEPENDENCIES]; 1983 List<CompilationUnitElement> dep4 = getLibraryCycleDependencies(results4);
1965 List<CompilationUnitElement> dep5 = results5[LIBRARY_CYCLE_DEPENDENCIES]; 1984 List<CompilationUnitElement> dep5 = getLibraryCycleDependencies(results5);
1966 List<CompilationUnitElement> dep6 = results6[LIBRARY_CYCLE_DEPENDENCIES]; 1985 List<CompilationUnitElement> dep6 = getLibraryCycleDependencies(results6);
1967 List<CompilationUnitElement> dep7 = results7[LIBRARY_CYCLE_DEPENDENCIES]; 1986 List<CompilationUnitElement> dep7 = getLibraryCycleDependencies(results7);
1968 expect(dep0, hasLength(1)); // dart:core 1987 expect(dep0, hasLength(1)); // dart:core
1969 expect(dep1, hasLength(1)); // dart:core 1988 expect(dep1, hasLength(1)); // dart:core
1970 expect(dep2, hasLength(1)); // dart:core 1989 expect(dep2, hasLength(1)); // dart:core
1971 expect(dep3, hasLength(1)); // dart:core 1990 expect(dep3, hasLength(1)); // dart:core
1972 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart 1991 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
1973 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart 1992 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
1974 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart 1993 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
1975 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart 1994 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart
1976 } 1995 }
1977 } 1996 }
1978 1997
1979 @reflectiveTest 1998 @reflectiveTest
1980 class ComputePropagableVariableDependenciesTaskTest 1999 class ComputePropagableVariableDependenciesTaskTest
1981 extends _AbstractDartTaskTest { 2000 extends _AbstractDartTaskTest {
2001 List<VariableElement> getPropagableVariableDependencies(
2002 Map<ResultDescriptor, dynamic> outputs) {
2003 return outputs[PROPAGABLE_VARIABLE_DEPENDENCIES] as List<VariableElement>;
2004 }
2005
1982 test_perform_instanceField() { 2006 test_perform_instanceField() {
1983 AnalysisTarget source = newSource( 2007 AnalysisTarget source = newSource(
1984 '/test.dart', 2008 '/test.dart',
1985 ''' 2009 '''
1986 class A { 2010 class A {
1987 final a = a1 + a2 + a3 + a4 + B.b1 + B.b2 + B.b3 + B.b4; 2011 final a = a1 + a2 + a3 + a4 + B.b1 + B.b2 + B.b3 + B.b4;
1988 static const a1 = 1; 2012 static const a1 = 1;
1989 final a2 = 2; 2013 final a2 = 2;
1990 final a3; 2014 final a3;
1991 var a4 = 4; 2015 var a4 = 4;
1992 } 2016 }
1993 class B { 2017 class B {
1994 static const b1 = 1; 2018 static const b1 = 1;
1995 static final b2 = 2; 2019 static final b2 = 2;
1996 static final b3; 2020 static final b3;
1997 static var b4 = 4; 2021 static var b4 = 4;
1998 } 2022 }
1999 '''); 2023 ''');
2000 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2024 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2001 computeResult(target, RESOLVED_UNIT5); 2025 computeResult(target, RESOLVED_UNIT5);
2002 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2026 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2003 FieldElement elementA = AstFinder.getFieldInClassElement(unit, 'A', 'a'); 2027 FieldElement elementA = AstFinder.getFieldInClassElement(unit, 'A', 'a');
2004 // compute 2028 // compute
2005 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2029 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2006 matcher: isComputePropagableVariableDependenciesTask); 2030 matcher: isComputePropagableVariableDependenciesTask);
2007 // verify 2031 // verify
2008 expect(outputs, hasLength(1)); 2032 expect(outputs, hasLength(1));
2009 List<VariableElement> dependencies = 2033 List<VariableElement> dependencies =
2010 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; 2034 getPropagableVariableDependencies(outputs);
2011 expect( 2035 expect(
2012 dependencies, 2036 dependencies,
2013 unorderedEquals([ 2037 unorderedEquals([
2014 AstFinder.getFieldInClassElement(unit, 'A', 'a1'), 2038 AstFinder.getFieldInClassElement(unit, 'A', 'a1'),
2015 AstFinder.getFieldInClassElement(unit, 'A', 'a2'), 2039 AstFinder.getFieldInClassElement(unit, 'A', 'a2'),
2016 AstFinder.getFieldInClassElement(unit, 'B', 'b1'), 2040 AstFinder.getFieldInClassElement(unit, 'B', 'b1'),
2017 AstFinder.getFieldInClassElement(unit, 'B', 'b2') 2041 AstFinder.getFieldInClassElement(unit, 'B', 'b2')
2018 ])); 2042 ]));
2019 } 2043 }
2020 2044
(...skipping 11 matching lines...) Expand all
2032 computeResult(target, RESOLVED_UNIT5); 2056 computeResult(target, RESOLVED_UNIT5);
2033 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2057 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2034 TopLevelVariableElement elementA = 2058 TopLevelVariableElement elementA =
2035 AstFinder.getTopLevelVariableElement(unit, 'a'); 2059 AstFinder.getTopLevelVariableElement(unit, 'a');
2036 // compute 2060 // compute
2037 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2061 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2038 matcher: isComputePropagableVariableDependenciesTask); 2062 matcher: isComputePropagableVariableDependenciesTask);
2039 // verify 2063 // verify
2040 expect(outputs, hasLength(1)); 2064 expect(outputs, hasLength(1));
2041 List<VariableElement> dependencies = 2065 List<VariableElement> dependencies =
2042 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; 2066 getPropagableVariableDependencies(outputs);
2043 expect( 2067 expect(
2044 dependencies, 2068 dependencies,
2045 unorderedEquals([ 2069 unorderedEquals([
2046 AstFinder.getTopLevelVariableElement(unit, 'd1'), 2070 AstFinder.getTopLevelVariableElement(unit, 'd1'),
2047 AstFinder.getTopLevelVariableElement(unit, 'd2') 2071 AstFinder.getTopLevelVariableElement(unit, 'd2')
2048 ])); 2072 ]));
2049 } 2073 }
2050 2074
2051 test_perform_topLevel_ignoreLocal() { 2075 test_perform_topLevel_ignoreLocal() {
2052 AnalysisTarget source = newSource( 2076 AnalysisTarget source = newSource(
(...skipping 10 matching lines...) Expand all
2063 computeResult(target, RESOLVED_UNIT5); 2087 computeResult(target, RESOLVED_UNIT5);
2064 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2088 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2065 TopLevelVariableElement elementA = 2089 TopLevelVariableElement elementA =
2066 AstFinder.getTopLevelVariableElement(unit, 'a'); 2090 AstFinder.getTopLevelVariableElement(unit, 'a');
2067 // compute 2091 // compute
2068 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2092 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2069 matcher: isComputePropagableVariableDependenciesTask); 2093 matcher: isComputePropagableVariableDependenciesTask);
2070 // verify 2094 // verify
2071 expect(outputs, hasLength(1)); 2095 expect(outputs, hasLength(1));
2072 List<VariableElement> dependencies = 2096 List<VariableElement> dependencies =
2073 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; 2097 getPropagableVariableDependencies(outputs);
2074 expect(dependencies, 2098 expect(dependencies,
2075 unorderedEquals([AstFinder.getTopLevelVariableElement(unit, 'd')])); 2099 unorderedEquals([AstFinder.getTopLevelVariableElement(unit, 'd')]));
2076 } 2100 }
2077 2101
2078 test_perform_topLevel_withoutSpaceAfterType() { 2102 test_perform_topLevel_withoutSpaceAfterType() {
2079 AnalysisTarget source = newSource( 2103 AnalysisTarget source = newSource(
2080 '/test.dart', 2104 '/test.dart',
2081 ''' 2105 '''
2082 const List<int>a=[b, c]; 2106 const List<int>a=[b, c];
2083 const b = 1; 2107 const b = 1;
2084 const c = 2; 2108 const c = 2;
2085 '''); 2109 ''');
2086 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2110 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2087 computeResult(target, RESOLVED_UNIT5); 2111 computeResult(target, RESOLVED_UNIT5);
2088 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2112 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2089 TopLevelVariableElement elementA = 2113 TopLevelVariableElement elementA =
2090 AstFinder.getTopLevelVariableElement(unit, 'a'); 2114 AstFinder.getTopLevelVariableElement(unit, 'a');
2091 // compute 2115 // compute
2092 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2116 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2093 matcher: isComputePropagableVariableDependenciesTask); 2117 matcher: isComputePropagableVariableDependenciesTask);
2094 // verify 2118 // verify
2095 expect(outputs, hasLength(1)); 2119 expect(outputs, hasLength(1));
2096 List<VariableElement> dependencies = 2120 List<VariableElement> dependencies =
2097 outputs[PROPAGABLE_VARIABLE_DEPENDENCIES]; 2121 getPropagableVariableDependencies(outputs);
2098 expect( 2122 expect(
2099 dependencies, 2123 dependencies,
2100 unorderedEquals([ 2124 unorderedEquals([
2101 AstFinder.getTopLevelVariableElement(unit, 'b'), 2125 AstFinder.getTopLevelVariableElement(unit, 'b'),
2102 AstFinder.getTopLevelVariableElement(unit, 'c') 2126 AstFinder.getTopLevelVariableElement(unit, 'c')
2103 ])); 2127 ]));
2104 } 2128 }
2105 } 2129 }
2106 2130
2107 @reflectiveTest 2131 @reflectiveTest
2108 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { 2132 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
2133 List<Source> getContainingLibraries(Map<ResultDescriptor, dynamic> outputs) {
2134 return outputs[CONTAINING_LIBRARIES] as List<Source>;
2135 }
2136
2109 test_perform_definingCompilationUnit() { 2137 test_perform_definingCompilationUnit() {
2110 AnalysisTarget library = newSource('/test.dart', 'library test;'); 2138 AnalysisTarget library = newSource('/test.dart', 'library test;');
2111 computeResult(library, INCLUDED_PARTS); 2139 computeResult(library, INCLUDED_PARTS);
2112 computeResult(library, CONTAINING_LIBRARIES, 2140 computeResult(library, CONTAINING_LIBRARIES,
2113 matcher: isContainingLibrariesTask); 2141 matcher: isContainingLibrariesTask);
2114 expect(outputs, hasLength(1)); 2142 expect(outputs, hasLength(1));
2115 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 2143 List<Source> containingLibraries = getContainingLibraries(outputs);
2116 expect(containingLibraries, unorderedEquals([library])); 2144 expect(containingLibraries, unorderedEquals([library]));
2117 } 2145 }
2118 2146
2119 test_perform_partInMultipleLibraries() { 2147 test_perform_partInMultipleLibraries() {
2120 AnalysisTarget library1 = 2148 AnalysisTarget library1 =
2121 newSource('/lib1.dart', 'library test; part "part.dart";'); 2149 newSource('/lib1.dart', 'library test; part "part.dart";');
2122 AnalysisTarget library2 = 2150 AnalysisTarget library2 =
2123 newSource('/lib2.dart', 'library test; part "part.dart";'); 2151 newSource('/lib2.dart', 'library test; part "part.dart";');
2124 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 2152 AnalysisTarget part = newSource('/part.dart', 'part of test;');
2125 computeResult(library1, INCLUDED_PARTS); 2153 computeResult(library1, INCLUDED_PARTS);
2126 computeResult(library2, INCLUDED_PARTS); 2154 computeResult(library2, INCLUDED_PARTS);
2127 computeResult(part, SOURCE_KIND); 2155 computeResult(part, SOURCE_KIND);
2128 computeResult(part, CONTAINING_LIBRARIES, 2156 computeResult(part, CONTAINING_LIBRARIES,
2129 matcher: isContainingLibrariesTask); 2157 matcher: isContainingLibrariesTask);
2130 expect(outputs, hasLength(1)); 2158 expect(outputs, hasLength(1));
2131 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 2159 List<Source> containingLibraries = getContainingLibraries(outputs);
2132 expect(containingLibraries, unorderedEquals([library1, library2])); 2160 expect(containingLibraries, unorderedEquals([library1, library2]));
2133 } 2161 }
2134 2162
2135 test_perform_partInSingleLibrary() { 2163 test_perform_partInSingleLibrary() {
2136 AnalysisTarget library = 2164 AnalysisTarget library =
2137 newSource('/lib.dart', 'library test; part "part.dart";'); 2165 newSource('/lib.dart', 'library test; part "part.dart";');
2138 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 2166 AnalysisTarget part = newSource('/part.dart', 'part of test;');
2139 computeResult(library, INCLUDED_PARTS); 2167 computeResult(library, INCLUDED_PARTS);
2140 computeResult(part, SOURCE_KIND); 2168 computeResult(part, SOURCE_KIND);
2141 computeResult(part, CONTAINING_LIBRARIES, 2169 computeResult(part, CONTAINING_LIBRARIES,
2142 matcher: isContainingLibrariesTask); 2170 matcher: isContainingLibrariesTask);
2143 expect(outputs, hasLength(1)); 2171 expect(outputs, hasLength(1));
2144 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 2172 List<Source> containingLibraries = getContainingLibraries(outputs);
2145 expect(containingLibraries, unorderedEquals([library])); 2173 expect(containingLibraries, unorderedEquals([library]));
2146 } 2174 }
2147 } 2175 }
2148 2176
2149 @reflectiveTest 2177 @reflectiveTest
2150 class DartErrorsTaskTest extends _AbstractDartTaskTest { 2178 class DartErrorsTaskTest extends _AbstractDartTaskTest {
2179 List<AnalysisError> getDartErrors(Map<ResultDescriptor, dynamic> outputs) {
2180 return outputs[DART_ERRORS] as List<AnalysisError>;
2181 }
2182
2151 test_perform_definingCompilationUnit() { 2183 test_perform_definingCompilationUnit() {
2152 AnalysisTarget library = 2184 AnalysisTarget library =
2153 newSource('/test.dart', 'library test; import "dart:math";'); 2185 newSource('/test.dart', 'library test; import "dart:math";');
2154 computeResult(library, INCLUDED_PARTS); 2186 computeResult(library, INCLUDED_PARTS);
2155 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask); 2187 computeResult(library, DART_ERRORS, matcher: isDartErrorsTask);
2156 expect(outputs, hasLength(1)); 2188 expect(outputs, hasLength(1));
2157 List<AnalysisError> errors = outputs[DART_ERRORS]; 2189 List<AnalysisError> errors = getDartErrors(outputs);
2158 expect(errors, hasLength(1)); 2190 expect(errors, hasLength(1));
2159 } 2191 }
2160 2192
2161 test_perform_partInSingleLibrary() { 2193 test_perform_partInSingleLibrary() {
2162 AnalysisTarget library = newSource( 2194 AnalysisTarget library = newSource(
2163 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); 2195 '/lib.dart', 'library test; import "dart:math"; part "part.dart";');
2164 AnalysisTarget part = 2196 AnalysisTarget part =
2165 newSource('/part.dart', 'part of test; class A extends A {}'); 2197 newSource('/part.dart', 'part of test; class A extends A {}');
2166 computeResult(library, INCLUDED_PARTS); 2198 computeResult(library, INCLUDED_PARTS);
2167 computeResult(library, DART_ERRORS); 2199 computeResult(library, DART_ERRORS);
2168 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask); 2200 computeResult(part, DART_ERRORS, matcher: isDartErrorsTask);
2169 expect(outputs, hasLength(1)); 2201 expect(outputs, hasLength(1));
2170 List<AnalysisError> errors = outputs[DART_ERRORS]; 2202 List<AnalysisError> errors = getDartErrors(outputs);
2171 // This should contain only the errors in the part file, not the ones in the 2203 // This should contain only the errors in the part file, not the ones in the
2172 // library. 2204 // library.
2173 expect(errors, hasLength(1)); 2205 expect(errors, hasLength(1));
2174 } 2206 }
2175 } 2207 }
2176 2208
2177 @reflectiveTest 2209 @reflectiveTest
2178 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { 2210 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
2179 test_created_resolved_unit() { 2211 test_created_resolved_unit() {
2180 Source source = newSource( 2212 Source source = newSource(
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
3124 bool ready = outputs[LIBRARY_ERRORS_READY]; 3156 bool ready = outputs[LIBRARY_ERRORS_READY];
3125 expect(ready, isTrue); 3157 expect(ready, isTrue);
3126 expect(context.getErrors(library).errors, hasLength(1)); 3158 expect(context.getErrors(library).errors, hasLength(1));
3127 expect(context.getErrors(part1).errors, hasLength(1)); 3159 expect(context.getErrors(part1).errors, hasLength(1));
3128 expect(context.getErrors(part2).errors, hasLength(1)); 3160 expect(context.getErrors(part2).errors, hasLength(1));
3129 } 3161 }
3130 } 3162 }
3131 3163
3132 @reflectiveTest 3164 @reflectiveTest
3133 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest { 3165 class LibraryUnitErrorsTaskTest extends _AbstractDartTaskTest {
3166 List<AnalysisError> getLibraryUnitErrors(
3167 Map<ResultDescriptor, dynamic> outputs) {
3168 return outputs[LIBRARY_UNIT_ERRORS] as List<AnalysisError>;
3169 }
3170
3134 test_perform_definingCompilationUnit() { 3171 test_perform_definingCompilationUnit() {
3135 AnalysisTarget library = 3172 AnalysisTarget library =
3136 newSource('/test.dart', 'library test; import "dart:math";'); 3173 newSource('/test.dart', 'library test; import "dart:math";');
3137 computeResult( 3174 computeResult(
3138 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS, 3175 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS,
3139 matcher: isLibraryUnitErrorsTask); 3176 matcher: isLibraryUnitErrorsTask);
3140 expect(outputs, hasLength(1)); 3177 expect(outputs, hasLength(1));
3141 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; 3178 List<AnalysisError> errors = getLibraryUnitErrors(outputs);
3142 expect(errors, hasLength(1)); 3179 expect(errors, hasLength(1));
3143 } 3180 }
3144 3181
3145 test_perform_partInSingleLibrary() { 3182 test_perform_partInSingleLibrary() {
3146 AnalysisTarget library = 3183 AnalysisTarget library =
3147 newSource('/lib.dart', 'library test; part "part.dart";'); 3184 newSource('/lib.dart', 'library test; part "part.dart";');
3148 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 3185 AnalysisTarget part = newSource('/part.dart', 'part of test;');
3149 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS, 3186 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS,
3150 matcher: isLibraryUnitErrorsTask); 3187 matcher: isLibraryUnitErrorsTask);
3151 expect(outputs, hasLength(1)); 3188 expect(outputs, hasLength(1));
3152 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; 3189 List<AnalysisError> errors = getLibraryUnitErrors(outputs);
3153 expect(errors, hasLength(0)); 3190 expect(errors, hasLength(0));
3154 } 3191 }
3155 } 3192 }
3156 3193
3157 @reflectiveTest 3194 @reflectiveTest
3158 class ParseDartTaskTest extends _AbstractDartTaskTest { 3195 class ParseDartTaskTest extends _AbstractDartTaskTest {
3159 Source source; 3196 Source source;
3160 3197
3161 test_perform() { 3198 test_perform() {
3162 _performParseTask(r''' 3199 _performParseTask(r'''
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 3352
3316 void _performParseTask(String content) { 3353 void _performParseTask(String content) {
3317 if (content == null) { 3354 if (content == null) {
3318 source = resourceProvider.getFile('/test.dart').createSource(); 3355 source = resourceProvider.getFile('/test.dart').createSource();
3319 } else { 3356 } else {
3320 source = newSource('/test.dart', content); 3357 source = newSource('/test.dart', content);
3321 } 3358 }
3322 computeResult(source, PARSED_UNIT, matcher: isParseDartTask); 3359 computeResult(source, PARSED_UNIT, matcher: isParseDartTask);
3323 } 3360 }
3324 3361
3325 static void _assertHasCore(List<Source> sources, int lenght) { 3362 static void _assertHasCore(dynamic sourceList, int lenght) {
3363 List<Source> sources = sourceList as List<Source>;
3326 expect(sources, hasLength(lenght)); 3364 expect(sources, hasLength(lenght));
3327 expect(sources, contains(predicate((Source s) { 3365 expect(sources, contains(predicate((Source s) {
3328 return s.fullName.endsWith('core.dart'); 3366 return s.fullName.endsWith('core.dart');
3329 }))); 3367 })));
3330 } 3368 }
3331 } 3369 }
3332 3370
3333 @reflectiveTest 3371 @reflectiveTest
3334 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { 3372 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest {
3335 test_perform_propagable() { 3373 test_perform_propagable() {
(...skipping 13 matching lines...) Expand all
3349 const fi1 = 1; 3387 const fi1 = 1;
3350 final fi2 = 2; 3388 final fi2 = 2;
3351 var fi3 = 3; 3389 var fi3 = 3;
3352 final fi4; 3390 final fi4;
3353 } 3391 }
3354 '''); 3392 ''');
3355 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3393 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3356 computeResult(target, PROPAGABLE_VARIABLES_IN_UNIT, 3394 computeResult(target, PROPAGABLE_VARIABLES_IN_UNIT,
3357 matcher: isPartiallyResolveUnitReferencesTask); 3395 matcher: isPartiallyResolveUnitReferencesTask);
3358 // PROPAGABLE_VARIABLES_IN_UNIT 3396 // PROPAGABLE_VARIABLES_IN_UNIT
3359 List<VariableElement> variables = outputs[PROPAGABLE_VARIABLES_IN_UNIT]; 3397 List<VariableElement> variables =
3398 outputs[PROPAGABLE_VARIABLES_IN_UNIT] as List<VariableElement>;
3360 expect(variables.map((v) => v.displayName), 3399 expect(variables.map((v) => v.displayName),
3361 unorderedEquals(['t1', 't2', 'fs1', 'fs2', 'fi1', 'fi2'])); 3400 unorderedEquals(['t1', 't2', 'fs1', 'fs2', 'fi1', 'fi2']));
3362 } 3401 }
3363 3402
3364 test_perform_strong_importExport() { 3403 test_perform_strong_importExport() {
3365 newSource( 3404 newSource(
3366 '/a.dart', 3405 '/a.dart',
3367 ''' 3406 '''
3368 library a; 3407 library a;
3369 class A<T> { 3408 class A<T> {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 var g = 0; 3455 var g = 0;
3417 } 3456 }
3418 '''); 3457 ''');
3419 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3458 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3420 computeResult(target, RESOLVED_UNIT5, 3459 computeResult(target, RESOLVED_UNIT5,
3421 matcher: isPartiallyResolveUnitReferencesTask); 3460 matcher: isPartiallyResolveUnitReferencesTask);
3422 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3461 CompilationUnit unit = outputs[RESOLVED_UNIT5];
3423 // INFERABLE_STATIC_VARIABLES_IN_UNIT 3462 // INFERABLE_STATIC_VARIABLES_IN_UNIT
3424 { 3463 {
3425 List<VariableElement> variables = 3464 List<VariableElement> variables =
3426 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT]; 3465 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] as List<VariableElement>;
3427 expect(variables, hasLength(4)); 3466 expect(variables, hasLength(4));
3428 expect(variables.map((v) => v.displayName), 3467 expect(variables.map((v) => v.displayName),
3429 unorderedEquals(['a', 'b', 'd', 'f'])); 3468 unorderedEquals(['a', 'b', 'd', 'f']));
3430 } 3469 }
3431 // Test the state of the AST 3470 // Test the state of the AST
3432 TopLevelVariableDeclaration a = unit.declarations[0]; 3471 TopLevelVariableDeclaration a = unit.declarations[0];
3433 VariableDeclaration variableA = a.variables.variables[0]; 3472 VariableDeclaration variableA = a.variables.variables[0];
3434 SimpleIdentifier initializer = variableA.initializer; 3473 SimpleIdentifier initializer = variableA.initializer;
3435 expect(initializer.staticElement, isNotNull); 3474 expect(initializer.staticElement, isNotNull);
3436 } 3475 }
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
5096 5135
5097 void setUp() { 5136 void setUp() {
5098 super.setUp(); 5137 super.setUp();
5099 emptySource = newSource('/test.dart'); 5138 emptySource = newSource('/test.dart');
5100 } 5139 }
5101 5140
5102 /** 5141 /**
5103 * Fill [errorListener] with [result] errors in the current [task]. 5142 * Fill [errorListener] with [result] errors in the current [task].
5104 */ 5143 */
5105 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 5144 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
5106 List<AnalysisError> errors = task.outputs[result]; 5145 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
5107 expect(errors, isNotNull, reason: result.name); 5146 expect(errors, isNotNull, reason: result.name);
5108 errorListener = new GatheringErrorListener(); 5147 errorListener = new GatheringErrorListener();
5109 errorListener.addAll(errors); 5148 errorListener.addAll(errors);
5110 } 5149 }
5111 } 5150 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/constant/value_test.dart ('k') | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698