OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 trydart.incremental_compilation_update_test; | 5 library trydart.incremental_compilation_update_test; |
6 | 6 |
7 import 'dart:html' hide | 7 import 'dart:html' hide |
8 Element; | 8 Element; |
9 | 9 |
10 import 'dart:async' show | 10 import 'dart:async' show |
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 } | 1392 } |
1393 | 1393 |
1394 main() { | 1394 main() { |
1395 print(const C('v2').value); | 1395 print(const C('v2').value); |
1396 } | 1396 } |
1397 """, | 1397 """, |
1398 const <String>['v2']), | 1398 const <String>['v2']), |
1399 ], | 1399 ], |
1400 | 1400 |
1401 // Test that an instance field can be added to a compound declaration. | 1401 // Test that an instance field can be added to a compound declaration. |
1402 // TODO(ahe): Test doesn't pass. | |
1403 const <ProgramResult>[ | 1402 const <ProgramResult>[ |
1404 const ProgramResult( | 1403 const ProgramResult( |
1405 r""" | 1404 r""" |
1406 class C { | 1405 class C { |
1407 int x; | 1406 int x; |
1408 } | 1407 } |
1409 | 1408 |
1410 var instance; | 1409 var instance; |
1411 | 1410 |
1412 main() { | 1411 main() { |
(...skipping 10 matching lines...) Expand all Loading... |
1423 print('[instance.x] threw'); | 1422 print('[instance.x] threw'); |
1424 } | 1423 } |
1425 try { | 1424 try { |
1426 print(instance.y); | 1425 print(instance.y); |
1427 } catch (e) { | 1426 } catch (e) { |
1428 print('[instance.y] threw'); | 1427 print('[instance.y] threw'); |
1429 } | 1428 } |
1430 } | 1429 } |
1431 """, | 1430 """, |
1432 const <String>['[instance] is null', 'v1', '[instance.y] threw']), | 1431 const <String>['[instance] is null', 'v1', '[instance.y] threw']), |
1433 /* | 1432 |
1434 const ProgramResult( | 1433 const ProgramResult( |
1435 r""" | 1434 r""" |
1436 class C { | 1435 class C { |
1437 int x, y; | 1436 int x, y; |
1438 } | 1437 } |
1439 | 1438 |
1440 var instance; | 1439 var instance; |
1441 | 1440 |
1442 main() { | 1441 main() { |
1443 if (instance == null) { | 1442 if (instance == null) { |
1444 print('[instance] is null'); | 1443 print('[instance] is null'); |
1445 instance = new C(); | 1444 instance = new C(); |
1446 instance.x = 'v1'; | 1445 instance.x = 'v1'; |
1447 } else { | 1446 } else { |
1448 instance.y = 'v2'; | 1447 instance.y = 'v2'; |
1449 } | 1448 } |
1450 try { | 1449 try { |
1451 print(instance.x); | 1450 print(instance.x); |
1452 } catch (e) { | 1451 } catch (e) { |
1453 print('[instance.x] threw'); | 1452 print('[instance.x] threw'); |
1454 } | 1453 } |
1455 try { | 1454 try { |
1456 print(instance.y); | 1455 print(instance.y); |
1457 } catch (e) { | 1456 } catch (e) { |
1458 print('[instance.y] threw'); | 1457 print('[instance.y] threw'); |
1459 } | 1458 } |
1460 } | 1459 } |
1461 """, | 1460 """, |
1462 const <String>['v1', 'v2']), | 1461 const <String>['v1', 'v2'], |
1463 */ | 1462 // TODO(ahe): Shouldn't throw. |
| 1463 compileUpdatesShouldThrow: true), |
| 1464 |
1464 ], | 1465 ], |
1465 | 1466 |
1466 // Test that an instance field can be removed from a compound declaration. | 1467 // Test that an instance field can be removed from a compound declaration. |
1467 // TODO(ahe): Test doesn't pass. | |
1468 const <ProgramResult>[ | 1468 const <ProgramResult>[ |
1469 const ProgramResult( | 1469 const ProgramResult( |
1470 r""" | 1470 r""" |
1471 class C { | 1471 class C { |
1472 int x, y; | 1472 int x, y; |
1473 } | 1473 } |
1474 | 1474 |
1475 var instance; | 1475 var instance; |
1476 | 1476 |
1477 main() { | 1477 main() { |
1478 if (instance == null) { | 1478 if (instance == null) { |
1479 print('[instance] is null'); | 1479 print('[instance] is null'); |
1480 instance = new C(); | 1480 instance = new C(); |
1481 instance.x = 'v1'; | 1481 instance.x = 'v1'; |
1482 instance.y = 'v2'; | 1482 instance.y = 'v2'; |
1483 } | 1483 } |
1484 try { | 1484 try { |
1485 print(instance.x); | 1485 print(instance.x); |
1486 } catch (e) { | 1486 } catch (e) { |
1487 print('[instance.x] threw'); | 1487 print('[instance.x] threw'); |
1488 } | 1488 } |
1489 try { | 1489 try { |
1490 print(instance.y); | 1490 print(instance.y); |
1491 } catch (e) { | 1491 } catch (e) { |
1492 print('[instance.y] threw'); | 1492 print('[instance.y] threw'); |
1493 } | 1493 } |
1494 } | 1494 } |
1495 """, | 1495 """, |
1496 const <String>['[instance] is null', 'v1', 'v2']), | 1496 const <String>['[instance] is null', 'v1', 'v2']), |
1497 /* | 1497 |
1498 const ProgramResult( | 1498 const ProgramResult( |
1499 r""" | 1499 r""" |
1500 class C { | 1500 class C { |
1501 int x; | 1501 int x; |
1502 } | 1502 } |
1503 | 1503 |
1504 var instance; | 1504 var instance; |
1505 | 1505 |
1506 main() { | 1506 main() { |
1507 if (instance == null) { | 1507 if (instance == null) { |
1508 print('[instance] is null'); | 1508 print('[instance] is null'); |
1509 instance = new C(); | 1509 instance = new C(); |
1510 instance.x = 'v1'; | 1510 instance.x = 'v1'; |
1511 instance.y = 'v2'; | 1511 instance.y = 'v2'; |
1512 } | 1512 } |
1513 try { | 1513 try { |
1514 print(instance.x); | 1514 print(instance.x); |
1515 } catch (e) { | 1515 } catch (e) { |
1516 print('[instance.x] threw'); | 1516 print('[instance.x] threw'); |
1517 } | 1517 } |
1518 try { | 1518 try { |
1519 print(instance.y); | 1519 print(instance.y); |
1520 } catch (e) { | 1520 } catch (e) { |
1521 print('[instance.y] threw'); | 1521 print('[instance.y] threw'); |
1522 } | 1522 } |
1523 } | 1523 } |
1524 """, | 1524 """, |
1525 const <String>['v1', '[instance.y] threw']), | 1525 const <String>['v1', '[instance.y] threw'], |
1526 */ | 1526 // TODO(ahe): Shouldn't throw. |
| 1527 compileUpdatesShouldThrow: true), |
1527 ], | 1528 ], |
1528 | 1529 |
1529 // Test that a static field can be made an instance field. | 1530 // Test that a static field can be made an instance field. |
1530 // TODO(ahe): Test doesn't pass. | 1531 // TODO(ahe): Test doesn't pass. |
1531 const <ProgramResult>[ | 1532 const <ProgramResult>[ |
1532 const ProgramResult( | 1533 const ProgramResult( |
1533 r""" | 1534 r""" |
1534 class C { | 1535 class C { |
1535 static int x; | 1536 static int x; |
1536 } | 1537 } |
(...skipping 14 matching lines...) Expand all Loading... |
1551 print('[C.x] threw'); | 1552 print('[C.x] threw'); |
1552 } | 1553 } |
1553 try { | 1554 try { |
1554 print(instance.x); | 1555 print(instance.x); |
1555 } catch (e) { | 1556 } catch (e) { |
1556 print('[instance.x] threw'); | 1557 print('[instance.x] threw'); |
1557 } | 1558 } |
1558 } | 1559 } |
1559 """, | 1560 """, |
1560 const <String>['[instance] is null', 'v1', '[instance.x] threw']), | 1561 const <String>['[instance] is null', 'v1', '[instance.x] threw']), |
1561 /* | 1562 |
1562 const ProgramResult( | 1563 const ProgramResult( |
1563 r""" | 1564 r""" |
1564 class C { | 1565 class C { |
1565 int x; | 1566 int x; |
1566 } | 1567 } |
1567 | 1568 |
1568 var instance; | 1569 var instance; |
1569 | 1570 |
1570 main() { | 1571 main() { |
1571 if (instance == null) { | 1572 if (instance == null) { |
1572 print('[instance] is null'); | 1573 print('[instance] is null'); |
1573 instance = new C(); | 1574 instance = new C(); |
1574 C.x = 'v1'; | 1575 C.x = 'v1'; |
1575 } else { | 1576 } else { |
1576 instance.x = 'v2'; | 1577 instance.x = 'v2'; |
1577 } | 1578 } |
1578 try { | 1579 try { |
1579 print(C.x); | 1580 print(C.x); |
1580 } catch (e) { | 1581 } catch (e) { |
1581 print('[C.x] threw'); | 1582 print('[C.x] threw'); |
1582 } | 1583 } |
1583 try { | 1584 try { |
1584 print(instance.x); | 1585 print(instance.x); |
1585 } catch (e) { | 1586 } catch (e) { |
1586 print('[instance.x] threw'); | 1587 print('[instance.x] threw'); |
1587 } | 1588 } |
1588 } | 1589 } |
1589 """, | 1590 """, |
1590 const <String>['[C.x] threw', 'v2']), | 1591 const <String>['[C.x] threw', 'v2'], |
1591 */ | 1592 // TODO(ahe): Shouldn't throw. |
| 1593 compileUpdatesShouldThrow: true), |
1592 ], | 1594 ], |
1593 | 1595 |
1594 // Test that instance field can be made static. | 1596 // Test that instance field can be made static. |
1595 // TODO(ahe): Test doesn't pass. | |
1596 const <ProgramResult>[ | 1597 const <ProgramResult>[ |
1597 const ProgramResult( | 1598 const ProgramResult( |
1598 r""" | 1599 r""" |
1599 class C { | 1600 class C { |
1600 int x; | 1601 int x; |
1601 } | 1602 } |
1602 | 1603 |
1603 var instance; | 1604 var instance; |
1604 | 1605 |
1605 main() { | 1606 main() { |
(...skipping 10 matching lines...) Expand all Loading... |
1616 print('[C.x] threw'); | 1617 print('[C.x] threw'); |
1617 } | 1618 } |
1618 try { | 1619 try { |
1619 print(instance.x); | 1620 print(instance.x); |
1620 } catch (e) { | 1621 } catch (e) { |
1621 print('[instance.x] threw'); | 1622 print('[instance.x] threw'); |
1622 } | 1623 } |
1623 } | 1624 } |
1624 """, | 1625 """, |
1625 const <String>['[instance] is null', '[C.x] threw', 'v1']), | 1626 const <String>['[instance] is null', '[C.x] threw', 'v1']), |
1626 /* | 1627 |
1627 const ProgramResult( | 1628 const ProgramResult( |
1628 r""" | 1629 r""" |
1629 class C { | 1630 class C { |
1630 static int x; | 1631 static int x; |
1631 } | 1632 } |
1632 | 1633 |
1633 var instance; | 1634 var instance; |
1634 | 1635 |
1635 main() { | 1636 main() { |
1636 if (instance == null) { | 1637 if (instance == null) { |
1637 print('[instance] is null'); | 1638 print('[instance] is null'); |
1638 instance = new C(); | 1639 instance = new C(); |
1639 instance.x = 'v1'; | 1640 instance.x = 'v1'; |
1640 } else { | 1641 } else { |
1641 C.x = 'v2'; | 1642 C.x = 'v2'; |
1642 } | 1643 } |
1643 try { | 1644 try { |
1644 print(C.x); | 1645 print(C.x); |
1645 } catch (e) { | 1646 } catch (e) { |
1646 print('[C.x] threw'); | 1647 print('[C.x] threw'); |
1647 } | 1648 } |
1648 try { | 1649 try { |
1649 print(instance.x); | 1650 print(instance.x); |
1650 } catch (e) { | 1651 } catch (e) { |
1651 print('[instance.x] threw'); | 1652 print('[instance.x] threw'); |
1652 } | 1653 } |
1653 } | 1654 } |
1654 """, | 1655 """, |
1655 const <String>['v2', '[instance.x] threw']), | 1656 const <String>['v2', '[instance.x] threw'], |
1656 */ | 1657 // TODO(ahe): Shouldn't throw. |
| 1658 compileUpdatesShouldThrow: true), |
1657 ], | 1659 ], |
1658 | 1660 |
1659 // Test compound constants. | 1661 // Test compound constants. |
1660 const <ProgramResult>[ | 1662 const <ProgramResult>[ |
1661 const ProgramResult( | 1663 const ProgramResult( |
1662 r""" | 1664 r""" |
1663 class A { | 1665 class A { |
1664 final value; | 1666 final value; |
1665 const A(this.value); | 1667 const A(this.value); |
1666 | 1668 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1760 | 1762 |
1761 summary = new SpanElement(); | 1763 summary = new SpanElement(); |
1762 document.body.append(new HeadingElement.h1() | 1764 document.body.append(new HeadingElement.h1() |
1763 ..appendText("Incremental compiler tests") | 1765 ..appendText("Incremental compiler tests") |
1764 ..append(summary)); | 1766 ..append(summary)); |
1765 | 1767 |
1766 String query = window.location.search; | 1768 String query = window.location.search; |
1767 int skip = 0; | 1769 int skip = 0; |
1768 if (query != null && query.length > 1) { | 1770 if (query != null && query.length > 1) { |
1769 query = query.substring(1); | 1771 query = query.substring(1); |
1770 String skipParam = Uri.splitQueryString(window.location.search)['skip']; | 1772 String skipParameter = Uri.splitQueryString(window.location.search)['skip']; |
1771 if (skipParam != null) { | 1773 if (skipParameter != null) { |
1772 skip = int.parse(skipParam); | 1774 skip = int.parse(skipParameter); |
1773 } | 1775 } |
| 1776 String verboseParameter = |
| 1777 Uri.splitQueryString(window.location.search)['verbose']; |
| 1778 verboseStatus = verboseParameter != null; |
1774 } | 1779 } |
1775 testCount += skip; | 1780 testCount += skip; |
1776 | 1781 |
1777 return asyncTest(() => Future.forEach(tests.skip(skip), compileAndRun) | 1782 return asyncTest(() => Future.forEach(tests.skip(skip), compileAndRun) |
1778 .then(updateSummary)); | 1783 .then(updateSummary)); |
1779 } | 1784 } |
1780 | 1785 |
1781 SpanElement summary; | 1786 SpanElement summary; |
1782 | 1787 |
1783 int testCount = 1; | 1788 int testCount = 1; |
1784 | 1789 |
| 1790 bool verboseStatus = false; |
| 1791 |
1785 void updateSummary(_) { | 1792 void updateSummary(_) { |
1786 summary.text = " (${testCount - 1}/${tests.length})"; | 1793 summary.text = " (${testCount - 1}/${tests.length})"; |
1787 } | 1794 } |
1788 | 1795 |
1789 Future compileAndRun(List<ProgramResult> programs) { | 1796 Future compileAndRun(List<ProgramResult> programs) { |
1790 updateSummary(null); | 1797 updateSummary(null); |
1791 var status = new DivElement(); | 1798 var status = new DivElement(); |
1792 document.body.append(status); | 1799 document.body.append(status); |
1793 | 1800 |
1794 IFrameElement iframe = | 1801 IFrameElement iframe = |
(...skipping 27 matching lines...) Expand all Loading... |
1822 | 1829 |
1823 status.append(new HeadingElement.h2()..appendText("Update:")); | 1830 status.append(new HeadingElement.h2()..appendText("Update:")); |
1824 status.append(numberedLines(program.code)); | 1831 status.append(numberedLines(program.code)); |
1825 | 1832 |
1826 WebInputProvider inputProvider = | 1833 WebInputProvider inputProvider = |
1827 test.incrementalCompiler.inputProvider; | 1834 test.incrementalCompiler.inputProvider; |
1828 Uri uri = test.scriptUri.resolve('?v${version++}'); | 1835 Uri uri = test.scriptUri.resolve('?v${version++}'); |
1829 inputProvider.cachedSources[uri] = new Future.value(program.code); | 1836 inputProvider.cachedSources[uri] = new Future.value(program.code); |
1830 Future future = test.incrementalCompiler.compileUpdates( | 1837 Future future = test.incrementalCompiler.compileUpdates( |
1831 {test.scriptUri: uri}, logVerbose: logger, logTime: logger); | 1838 {test.scriptUri: uri}, logVerbose: logger, logTime: logger); |
| 1839 future = future.catchError((error, trace) { |
| 1840 String statusMessage; |
| 1841 Future result; |
| 1842 if (program.compileUpdatesShouldThrow) { |
| 1843 statusMessage = "Expected error in compileUpdates."; |
| 1844 result = null; |
| 1845 } else { |
| 1846 statusMessage = "Unexpected error in compileUpdates."; |
| 1847 result = new Future.error(error, trace); |
| 1848 } |
| 1849 status.append(new HeadingElement.h3()..appendText(statusMessage)); |
| 1850 return result; |
| 1851 }); |
1832 return future.then((String update) { | 1852 return future.then((String update) { |
| 1853 if (program.compileUpdatesShouldThrow) { |
| 1854 Expect.isNull(update); |
| 1855 return null; |
| 1856 } |
1833 print({'update': update}); | 1857 print({'update': update}); |
1834 iframe.contentWindow.postMessage(['apply-update', update], '*'); | 1858 iframe.contentWindow.postMessage(['apply-update', update], '*'); |
1835 | 1859 |
1836 return listener.expect( | 1860 return listener.expect( |
1837 program.messagesWith('iframe-dart-updated-main-done')) | 1861 program.messagesWith('iframe-dart-updated-main-done')) |
1838 .then((_) { | 1862 .then((_) { |
1839 return new SerializeScopeTestCase( | 1863 return new SerializeScopeTestCase( |
1840 program.code, test.incrementalCompiler.mainApp, | 1864 program.code, test.incrementalCompiler.mainApp, |
1841 test.incrementalCompiler.compiler).run(); | 1865 test.incrementalCompiler.compiler).run(); |
1842 }); | 1866 }); |
1843 }); | 1867 }); |
1844 }); | 1868 }); |
1845 }); | 1869 }); |
1846 }); | 1870 }); |
1847 }).then((_) { | 1871 }).then((_) { |
1848 status.style.color = 'limegreen'; | 1872 status.style.color = 'limegreen'; |
1849 | 1873 |
1850 // Remove the iframe and status to work around a bug in test.dart | 1874 // Remove the iframe and status to work around a bug in test.dart |
1851 // (https://code.google.com/p/dart/issues/detail?id=21691). | 1875 // (https://code.google.com/p/dart/issues/detail?id=21691). |
1852 status.remove(); | 1876 if (!verboseStatus) status.remove(); |
1853 iframe.remove(); | 1877 iframe.remove(); |
1854 }); | 1878 }); |
1855 } | 1879 } |
1856 | 1880 |
1857 class SerializeScopeTestCase extends CompilerTestCase { | 1881 class SerializeScopeTestCase extends CompilerTestCase { |
1858 final String scopeInfo; | 1882 final String scopeInfo; |
1859 | 1883 |
1860 SerializeScopeTestCase( | 1884 SerializeScopeTestCase( |
1861 String source, | 1885 String source, |
1862 LibraryElement library, | 1886 LibraryElement library, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 ..classes.add("line"); | 1938 ..classes.add("line"); |
1915 result.append(line); | 1939 result.append(line); |
1916 } | 1940 } |
1917 | 1941 |
1918 return result; | 1942 return result; |
1919 } | 1943 } |
1920 | 1944 |
1921 | 1945 |
1922 StyleElement lineNumberStyle() { | 1946 StyleElement lineNumberStyle() { |
1923 StyleElement style = new StyleElement()..appendText(''' | 1947 StyleElement style = new StyleElement()..appendText(''' |
1924 h2 { | 1948 h2, h3 { |
1925 color: black; | 1949 color: black; |
1926 } | 1950 } |
1927 | 1951 |
1928 .output { | 1952 .output { |
1929 padding: 0px; | 1953 padding: 0px; |
1930 counter-reset: line-number; | 1954 counter-reset: line-number; |
1931 padding-bottom: 1em; | 1955 padding-bottom: 1em; |
1932 } | 1956 } |
1933 | 1957 |
1934 .line { | 1958 .line { |
1935 white-space: pre-wrap; | 1959 white-space: pre-wrap; |
1936 padding-left: 3.5em; | 1960 padding-left: 3.5em; |
1937 margin-top: 0; | 1961 margin-top: 0; |
1938 margin-bottom: 0; | 1962 margin-bottom: 0; |
1939 } | 1963 } |
1940 | 1964 |
1941 .line::before { | 1965 .line::before { |
1942 counter-increment: line-number; | 1966 counter-increment: line-number; |
1943 content: counter(line-number) " "; | 1967 content: counter(line-number) " "; |
1944 position: absolute; | 1968 position: absolute; |
1945 left: 0px; | 1969 left: 0px; |
1946 width: 3em; | 1970 width: 3em; |
1947 text-align: right; | 1971 text-align: right; |
1948 background-color: lightgoldenrodyellow; | 1972 background-color: lightgoldenrodyellow; |
1949 } | 1973 } |
1950 '''); | 1974 '''); |
1951 style.type = 'text/css'; | 1975 style.type = 'text/css'; |
1952 return style; | 1976 return style; |
1953 } | 1977 } |
OLD | NEW |