OLD | NEW |
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 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 } | 1549 } |
1550 | 1550 |
1551 @override | 1551 @override |
1552 void setUp() { | 1552 void setUp() { |
1553 super.setUp(); | 1553 super.setUp(); |
1554 enableStrongMode(); | 1554 enableStrongMode(); |
1555 } | 1555 } |
1556 | 1556 |
1557 void test_library_cycle_incremental() { | 1557 void test_library_cycle_incremental() { |
1558 enableStrongMode(); | 1558 enableStrongMode(); |
1559 Source lib1Source = newSource( | 1559 Source a = newSource( |
1560 '/my_lib1.dart', | 1560 '/a.dart', |
1561 ''' | 1561 ''' |
1562 library my_lib1; | 1562 library a; |
1563 '''); | 1563 '''); |
1564 Source lib2Source = newSource( | 1564 Source b = newSource( |
1565 '/my_lib2.dart', | 1565 '/b.dart', |
1566 ''' | 1566 ''' |
1567 library my_lib2; | 1567 library b; |
1568 import 'my_lib1.dart'; | 1568 import 'a.dart'; |
1569 '''); | 1569 '''); |
1570 Source lib3Source = newSource( | 1570 Source c = newSource( |
1571 '/my_lib3.dart', | 1571 '/c.dart', |
1572 ''' | 1572 ''' |
1573 library my_lib3; | 1573 library c; |
1574 import 'my_lib2.dart'; | 1574 import 'b.dart'; |
1575 '''); | 1575 '''); |
1576 | 1576 |
1577 computeResult(lib1Source, LIBRARY_CYCLE); | 1577 _assertLibraryCycle(a, [a]); |
1578 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1578 _assertLibraryCycle(b, [b]); |
1579 computeResult(lib2Source, LIBRARY_CYCLE); | 1579 _assertLibraryCycle(c, [c]); |
1580 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | |
1581 computeResult(lib3Source, LIBRARY_CYCLE); | |
1582 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | |
1583 | 1580 |
1584 // create a cycle | 1581 // Create a cycle. |
1585 context.setContents( | 1582 context.setContents( |
1586 lib1Source, | 1583 a, |
1587 ''' | 1584 ''' |
1588 library my_lib1; | 1585 library a; |
1589 import 'my_lib3.dart'; | 1586 import 'c.dart'; |
1590 '''); | 1587 '''); |
1591 _expectInvalid(lib1Source); | 1588 _expectInvalid(a); |
1592 _expectInvalid(lib2Source); | 1589 _expectInvalid(b); |
1593 _expectInvalid(lib3Source); | 1590 _expectInvalid(c); |
1594 | 1591 |
1595 computeResult(lib1Source, LIBRARY_CYCLE); | 1592 _assertLibraryCycle(a, [a, b, c]); |
1596 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1593 _assertLibraryCycle(b, [a, b, c]); |
1597 computeResult(lib2Source, LIBRARY_CYCLE); | 1594 _assertLibraryCycle(c, [a, b, c]); |
1598 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | |
1599 computeResult(lib3Source, LIBRARY_CYCLE); | |
1600 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | |
1601 | 1595 |
1602 // break the cycle again | 1596 // Break the cycle again. |
1603 context.setContents( | 1597 context.setContents( |
1604 lib1Source, | 1598 a, |
1605 ''' | 1599 ''' |
1606 library my_lib1; | 1600 library a; |
1607 '''); | 1601 '''); |
1608 _expectInvalid(lib1Source); | 1602 _expectInvalid(a); |
1609 _expectInvalid(lib2Source); | 1603 _expectInvalid(b); |
1610 _expectInvalid(lib3Source); | 1604 _expectInvalid(c); |
1611 | 1605 |
1612 computeResult(lib1Source, LIBRARY_CYCLE); | 1606 _assertLibraryCycle(a, [a]); |
1613 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1607 _assertLibraryCycle(b, [b]); |
1614 computeResult(lib2Source, LIBRARY_CYCLE); | 1608 _assertLibraryCycle(c, [c]); |
1615 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | |
1616 computeResult(lib3Source, LIBRARY_CYCLE); | |
1617 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | |
1618 } | 1609 } |
1619 | 1610 |
1620 void test_library_cycle_incremental_partial() { | 1611 void test_library_cycle_incremental_partial() { |
1621 enableStrongMode(); | 1612 enableStrongMode(); |
1622 Source lib1Source = newSource( | 1613 Source a = newSource( |
1623 '/my_lib1.dart', | 1614 '/a.dart', |
1624 ''' | 1615 r''' |
1625 library my_lib1; | 1616 library a; |
1626 '''); | 1617 '''); |
1627 Source lib2Source = newSource( | 1618 Source b = newSource( |
1628 '/my_lib2.dart', | 1619 '/b.dart', |
1629 ''' | 1620 r''' |
1630 library my_lib2; | 1621 library b; |
1631 import 'my_lib1.dart'; | 1622 import 'a.dart'; |
1632 '''); | 1623 '''); |
1633 Source lib3Source = newSource( | 1624 Source c = newSource( |
1634 '/my_lib3.dart', | 1625 '/c.dart', |
1635 ''' | 1626 r''' |
1636 library my_lib3; | 1627 library c; |
1637 import 'my_lib2.dart'; | 1628 import 'b.dart'; |
1638 '''); | 1629 '''); |
1639 | 1630 |
1640 computeResult(lib1Source, LIBRARY_CYCLE); | 1631 _assertLibraryCycle(a, [a]); |
1641 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1632 _assertLibraryCycle(b, [b]); |
1642 computeResult(lib2Source, LIBRARY_CYCLE); | 1633 // 'c' is not reachable, so we have not yet computed its library cycles. |
1643 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | |
1644 // lib3 is not reachable, so we have not yet computed its library | |
1645 // cycles | |
1646 | 1634 |
1647 // complete the cycle, via lib3 | 1635 // Complete the cycle, via 'c'. |
1648 context.setContents( | 1636 context.setContents( |
1649 lib1Source, | 1637 a, |
1650 ''' | 1638 r''' |
1651 library my_lib1; | 1639 library a; |
1652 import 'my_lib3.dart'; | 1640 import 'c.dart'; |
1653 '''); | 1641 '''); |
1654 _expectInvalid(lib1Source); | 1642 _expectInvalid(a); |
1655 _expectInvalid(lib2Source); | 1643 _expectInvalid(b); |
1656 _expectInvalid(lib3Source); | 1644 _expectInvalid(c); |
1657 | 1645 |
1658 // Ensure that invalidation correctly invalidated everything reachable | 1646 // Ensure that everything reachable through 'c' was invalidated, |
1659 // through lib3 | 1647 // and recomputed to include all three sources. |
1660 computeResult(lib1Source, LIBRARY_CYCLE); | 1648 _assertLibraryCycle(a, [a, b, c]); |
1661 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1649 _assertLibraryCycle(b, [a, b, c]); |
1662 computeResult(lib2Source, LIBRARY_CYCLE); | 1650 _assertLibraryCycle(c, [a, b, c]); |
1663 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1651 } |
1664 computeResult(lib3Source, LIBRARY_CYCLE); | 1652 |
1665 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1653 void test_library_cycle_incremental_partial2() { |
| 1654 enableStrongMode(); |
| 1655 Source a = newSource( |
| 1656 '/a.dart', |
| 1657 r''' |
| 1658 library a; |
| 1659 import 'b.dart'; |
| 1660 '''); |
| 1661 Source b = newSource( |
| 1662 '/b.dart', |
| 1663 r''' |
| 1664 library b; |
| 1665 import 'a.dart'; |
| 1666 '''); |
| 1667 Source c = newSource( |
| 1668 '/c.dart', |
| 1669 r''' |
| 1670 library c; |
| 1671 import 'b.dart'; |
| 1672 '''); |
| 1673 |
| 1674 _assertLibraryCycle(a, [a, b]); |
| 1675 _assertLibraryCycle(b, [a, b]); |
| 1676 _assertLibraryCycle(c, [c]); |
| 1677 |
| 1678 // Include 'c' into the cycle. |
| 1679 context.setContents( |
| 1680 a, |
| 1681 r''' |
| 1682 library a; |
| 1683 import 'b.dart'; |
| 1684 import 'c.dart'; |
| 1685 '''); |
| 1686 _expectInvalid(a); |
| 1687 _expectInvalid(b); |
| 1688 _expectInvalid(c); |
| 1689 |
| 1690 // Start processing with 'b', so that when we resolve 'b' directives, |
| 1691 // and invalidate library cycles, the 'a' directives are not resolved yet, |
| 1692 // so we don't know that the cycle must include 'c'. |
| 1693 _assertLibraryCycle(b, [a, b, c]); |
| 1694 _assertLibraryCycle(a, [a, b, c]); |
| 1695 _assertLibraryCycle(c, [a, b, c]); |
1666 } | 1696 } |
1667 | 1697 |
1668 void test_library_cycle_linear() { | 1698 void test_library_cycle_linear() { |
1669 List<Source> sources = newSources({ | 1699 List<Source> sources = newSources({ |
1670 '/a.dart': ''' | 1700 '/a.dart': ''' |
1671 ''', | 1701 ''', |
1672 '/b.dart': ''' | 1702 '/b.dart': ''' |
1673 import 'a.dart'; | 1703 import 'a.dart'; |
1674 ''' | 1704 ''' |
1675 }); | 1705 }); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results0); | 1997 List<CompilationUnitElement> dep0 = getLibraryCycleDependencies(results0); |
1968 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results1); | 1998 List<CompilationUnitElement> dep1 = getLibraryCycleDependencies(results1); |
1969 List<CompilationUnitElement> dep4 = getLibraryCycleDependencies(results4); | 1999 List<CompilationUnitElement> dep4 = getLibraryCycleDependencies(results4); |
1970 List<CompilationUnitElement> dep5 = getLibraryCycleDependencies(results5); | 2000 List<CompilationUnitElement> dep5 = getLibraryCycleDependencies(results5); |
1971 expect(dep0, hasLength(1)); // dart:core | 2001 expect(dep0, hasLength(1)); // dart:core |
1972 expect(dep1, hasLength(1)); // dart:core | 2002 expect(dep1, hasLength(1)); // dart:core |
1973 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2003 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
1974 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2004 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
1975 } | 2005 } |
1976 | 2006 |
| 2007 void _assertLibraryCycle(Source source, List<Source> expected) { |
| 2008 computeResult(source, LIBRARY_CYCLE); |
| 2009 List<LibraryElement> cycle = outputs[LIBRARY_CYCLE] as List<LibraryElement>; |
| 2010 expect(cycle.map((e) => e.source), unorderedEquals(expected)); |
| 2011 } |
| 2012 |
1977 void _expectInvalid(Source librarySource) { | 2013 void _expectInvalid(Source librarySource) { |
1978 CacheEntry entry = context.getCacheEntry(librarySource); | 2014 CacheEntry entry = context.getCacheEntry(librarySource); |
1979 expect(entry.getState(LIBRARY_CYCLE), CacheState.INVALID); | 2015 expect(entry.getState(LIBRARY_CYCLE), CacheState.INVALID); |
1980 } | 2016 } |
1981 } | 2017 } |
1982 | 2018 |
1983 @reflectiveTest | 2019 @reflectiveTest |
1984 class ComputePropagableVariableDependenciesTaskTest | 2020 class ComputePropagableVariableDependenciesTaskTest |
1985 extends _AbstractDartTaskTest { | 2021 extends _AbstractDartTaskTest { |
1986 List<VariableElement> getPropagableVariableDependencies( | 2022 List<VariableElement> getPropagableVariableDependencies( |
(...skipping 3812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5799 /** | 5835 /** |
5800 * Fill [errorListener] with [result] errors in the current [task]. | 5836 * Fill [errorListener] with [result] errors in the current [task]. |
5801 */ | 5837 */ |
5802 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5838 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
5803 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 5839 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
5804 expect(errors, isNotNull, reason: result.name); | 5840 expect(errors, isNotNull, reason: result.name); |
5805 errorListener = new GatheringErrorListener(); | 5841 errorListener = new GatheringErrorListener(); |
5806 errorListener.addAll(errors); | 5842 errorListener.addAll(errors); |
5807 } | 5843 } |
5808 } | 5844 } |
OLD | NEW |