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 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 '''); | 1566 '''); |
1567 Source lib3Source = newSource( | 1567 Source lib3Source = newSource( |
1568 '/my_lib3.dart', | 1568 '/my_lib3.dart', |
1569 ''' | 1569 ''' |
1570 library my_lib3; | 1570 library my_lib3; |
1571 import 'my_lib2.dart'; | 1571 import 'my_lib2.dart'; |
1572 '''); | 1572 '''); |
1573 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); | 1573 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); |
1574 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); | 1574 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); |
1575 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); | 1575 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); |
| 1576 |
1576 computeResult(lib1Target, LIBRARY_CYCLE); | 1577 computeResult(lib1Target, LIBRARY_CYCLE); |
1577 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1578 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1578 computeResult(lib2Target, LIBRARY_CYCLE); | 1579 computeResult(lib2Target, LIBRARY_CYCLE); |
1579 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1580 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1580 computeResult(lib3Target, LIBRARY_CYCLE); | 1581 computeResult(lib3Target, LIBRARY_CYCLE); |
1581 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1582 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1582 | 1583 |
1583 // complete the cycle | 1584 // create a cycle |
1584 context.setContents( | 1585 context.setContents( |
1585 lib1Source, | 1586 lib1Source, |
1586 ''' | 1587 ''' |
1587 library my_lib1; | 1588 library my_lib1; |
1588 import 'my_lib3.dart'; | 1589 import 'my_lib3.dart'; |
1589 '''); | 1590 '''); |
| 1591 _expectInvalid(lib1Target); |
| 1592 _expectInvalid(lib2Target); |
| 1593 _expectInvalid(lib3Target); |
| 1594 |
1590 computeResult(lib1Target, LIBRARY_CYCLE); | 1595 computeResult(lib1Target, LIBRARY_CYCLE); |
1591 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1596 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1592 computeResult(lib2Target, LIBRARY_CYCLE); | 1597 computeResult(lib2Target, LIBRARY_CYCLE); |
1593 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1598 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1594 computeResult(lib3Target, LIBRARY_CYCLE); | 1599 computeResult(lib3Target, LIBRARY_CYCLE); |
1595 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1600 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1596 | 1601 |
1597 // break the cycle again | 1602 // break the cycle again |
1598 context.setContents( | 1603 context.setContents( |
1599 lib1Source, | 1604 lib1Source, |
1600 ''' | 1605 ''' |
1601 library my_lib1; | 1606 library my_lib1; |
1602 '''); | 1607 '''); |
| 1608 _expectInvalid(lib1Target); |
| 1609 _expectInvalid(lib2Target); |
| 1610 _expectInvalid(lib3Target); |
| 1611 |
1603 computeResult(lib1Target, LIBRARY_CYCLE); | 1612 computeResult(lib1Target, LIBRARY_CYCLE); |
1604 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1613 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1605 computeResult(lib2Target, LIBRARY_CYCLE); | 1614 computeResult(lib2Target, LIBRARY_CYCLE); |
1606 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1615 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1607 computeResult(lib3Target, LIBRARY_CYCLE); | 1616 computeResult(lib3Target, LIBRARY_CYCLE); |
1608 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1617 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1609 } | 1618 } |
1610 | 1619 |
1611 void test_library_cycle_incremental_partial() { | 1620 void test_library_cycle_incremental_partial() { |
1612 enableStrongMode(); | 1621 enableStrongMode(); |
(...skipping 10 matching lines...) Expand all Loading... |
1623 '''); | 1632 '''); |
1624 Source lib3Source = newSource( | 1633 Source lib3Source = newSource( |
1625 '/my_lib3.dart', | 1634 '/my_lib3.dart', |
1626 ''' | 1635 ''' |
1627 library my_lib3; | 1636 library my_lib3; |
1628 import 'my_lib2.dart'; | 1637 import 'my_lib2.dart'; |
1629 '''); | 1638 '''); |
1630 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); | 1639 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); |
1631 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); | 1640 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); |
1632 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); | 1641 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); |
| 1642 |
1633 computeResult(lib1Target, LIBRARY_CYCLE); | 1643 computeResult(lib1Target, LIBRARY_CYCLE); |
1634 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1644 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1635 computeResult(lib2Target, LIBRARY_CYCLE); | 1645 computeResult(lib2Target, LIBRARY_CYCLE); |
1636 expect(outputs[LIBRARY_CYCLE], hasLength(1)); | 1646 expect(outputs[LIBRARY_CYCLE], hasLength(1)); |
1637 // lib3 is not reachable, so we have not yet computed its library | 1647 // lib3 is not reachable, so we have not yet computed its library |
1638 // cycles | 1648 // cycles |
1639 | 1649 |
1640 // complete the cycle, via lib3 | 1650 // complete the cycle, via lib3 |
1641 context.setContents( | 1651 context.setContents( |
1642 lib1Source, | 1652 lib1Source, |
1643 ''' | 1653 ''' |
1644 library my_lib1; | 1654 library my_lib1; |
1645 import 'my_lib3.dart'; | 1655 import 'my_lib3.dart'; |
1646 '''); | 1656 '''); |
| 1657 _expectInvalid(lib1Target); |
| 1658 _expectInvalid(lib2Target); |
| 1659 _expectInvalid(lib3Target); |
| 1660 |
1647 // Ensure that invalidation correctly invalidated everything reachable | 1661 // Ensure that invalidation correctly invalidated everything reachable |
1648 // through lib3 | 1662 // through lib3 |
1649 computeResult(lib1Target, LIBRARY_CYCLE); | 1663 computeResult(lib1Target, LIBRARY_CYCLE); |
1650 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1664 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1651 computeResult(lib2Target, LIBRARY_CYCLE); | 1665 computeResult(lib2Target, LIBRARY_CYCLE); |
1652 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1666 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1653 computeResult(lib3Target, LIBRARY_CYCLE); | 1667 computeResult(lib3Target, LIBRARY_CYCLE); |
1654 expect(outputs[LIBRARY_CYCLE], hasLength(3)); | 1668 expect(outputs[LIBRARY_CYCLE], hasLength(3)); |
1655 } | 1669 } |
1656 | 1670 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 expect(b.getMethod('foo').returnType.toString(), 'int'); | 1770 expect(b.getMethod('foo').returnType.toString(), 'int'); |
1757 | 1771 |
1758 // add a dummy edit. | 1772 // add a dummy edit. |
1759 context.setContents( | 1773 context.setContents( |
1760 lib1Source, | 1774 lib1Source, |
1761 ''' | 1775 ''' |
1762 library my_lib1; | 1776 library my_lib1; |
1763 import 'my_lib3.dart'; | 1777 import 'my_lib3.dart'; |
1764 var foo = 123; | 1778 var foo = 123; |
1765 '''); | 1779 '''); |
| 1780 _expectInvalid(lib1Target); |
| 1781 _expectInvalid(lib2Target); |
| 1782 _expectInvalid(lib3Target); |
1766 | 1783 |
1767 computeResult(lib1Target, RESOLVED_UNIT); | 1784 computeResult(lib1Target, RESOLVED_UNIT); |
1768 computeResult(lib2Target, RESOLVED_UNIT); | 1785 computeResult(lib2Target, RESOLVED_UNIT); |
1769 computeResult(lib3Target, RESOLVED_UNIT); | 1786 computeResult(lib3Target, RESOLVED_UNIT); |
1770 unit = outputs[RESOLVED_UNIT]; | 1787 unit = outputs[RESOLVED_UNIT]; |
1771 b = unit.declarations[1].element; | 1788 b = unit.declarations[1].element; |
1772 expect(b.getMethod('foo').returnType.toString(), 'int', | 1789 expect(b.getMethod('foo').returnType.toString(), 'int', |
1773 reason: 'edit should not affect member inference'); | 1790 reason: 'edit should not affect member inference'); |
1774 } | 1791 } |
1775 | 1792 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 List<CompilationUnitElement> dep7 = getLibraryCycleDependencies(results7); | 2009 List<CompilationUnitElement> dep7 = getLibraryCycleDependencies(results7); |
1993 expect(dep0, hasLength(1)); // dart:core | 2010 expect(dep0, hasLength(1)); // dart:core |
1994 expect(dep1, hasLength(1)); // dart:core | 2011 expect(dep1, hasLength(1)); // dart:core |
1995 expect(dep2, hasLength(1)); // dart:core | 2012 expect(dep2, hasLength(1)); // dart:core |
1996 expect(dep3, hasLength(1)); // dart:core | 2013 expect(dep3, hasLength(1)); // dart:core |
1997 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2014 expect(dep4, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
1998 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2015 expect(dep5, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
1999 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2016 expect(dep6, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
2000 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart | 2017 expect(dep7, hasLength(5)); // dart:core, a.dart, aa.dart, ab.dart, b.dart |
2001 } | 2018 } |
| 2019 |
| 2020 void _expectInvalid(LibrarySpecificUnit target) { |
| 2021 CacheEntry entry = context.getCacheEntry(target); |
| 2022 expect(entry.getState(LIBRARY_CYCLE), CacheState.INVALID); |
| 2023 } |
2002 } | 2024 } |
2003 | 2025 |
2004 @reflectiveTest | 2026 @reflectiveTest |
2005 class ComputePropagableVariableDependenciesTaskTest | 2027 class ComputePropagableVariableDependenciesTaskTest |
2006 extends _AbstractDartTaskTest { | 2028 extends _AbstractDartTaskTest { |
2007 List<VariableElement> getPropagableVariableDependencies( | 2029 List<VariableElement> getPropagableVariableDependencies( |
2008 Map<ResultDescriptor, dynamic> outputs) { | 2030 Map<ResultDescriptor, dynamic> outputs) { |
2009 return outputs[PROPAGABLE_VARIABLE_DEPENDENCIES] as List<VariableElement>; | 2031 return outputs[PROPAGABLE_VARIABLE_DEPENDENCIES] as List<VariableElement>; |
2010 } | 2032 } |
2011 | 2033 |
(...skipping 3342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5354 /** | 5376 /** |
5355 * Fill [errorListener] with [result] errors in the current [task]. | 5377 * Fill [errorListener] with [result] errors in the current [task]. |
5356 */ | 5378 */ |
5357 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5379 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
5358 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 5380 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
5359 expect(errors, isNotNull, reason: result.name); | 5381 expect(errors, isNotNull, reason: result.name); |
5360 errorListener = new GatheringErrorListener(); | 5382 errorListener = new GatheringErrorListener(); |
5361 errorListener.addAll(errors); | 5383 errorListener.addAll(errors); |
5362 } | 5384 } |
5363 } | 5385 } |
OLD | NEW |