Skip to content

Commit 5a03ec3

Browse files
committed
Update tests
1 parent 878cfb2 commit 5a03ec3

File tree

1 file changed

+85
-5
lines changed

1 file changed

+85
-5
lines changed

Lib/test/test_generated_cases.py

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def run_cases_test(self, input: str, expected: str):
286286
instructions, labels_with_prelude_and_postlude = rest.split(tier1_generator.INSTRUCTION_END_MARKER)
287287
_, labels_with_postlude = labels_with_prelude_and_postlude.split(tier1_generator.LABEL_START_MARKER)
288288
labels, _ = labels_with_postlude.split(tier1_generator.LABEL_END_MARKER)
289-
actual = instructions + labels
289+
actual = instructions.strip() + "\n\n " + labels.strip()
290290
# if actual.strip() != expected.strip():
291291
# print("Actual:")
292292
# print(actual)
@@ -652,6 +652,9 @@ def test_cache_effect(self):
652652

653653
def test_suppress_dispatch(self):
654654
input = """
655+
label(somewhere) {
656+
}
657+
655658
inst(OP, (--)) {
656659
goto somewhere;
657660
}
@@ -663,6 +666,11 @@ def test_suppress_dispatch(self):
663666
INSTRUCTION_STATS(OP);
664667
goto somewhere;
665668
}
669+
670+
somewhere:
671+
{
672+
673+
}
666674
"""
667675
self.run_cases_test(input, output)
668676

@@ -1768,9 +1776,15 @@ def test_kill_in_wrong_order(self):
17681776

17691777
def test_complex_label(self):
17701778
input = """
1779+
label(other_label) {
1780+
}
1781+
1782+
label(other_label2) {
1783+
}
1784+
17711785
label(my_label) {
17721786
// Comment
1773-
do_thing()
1787+
do_thing();
17741788
if (complex) {
17751789
goto other_label;
17761790
}
@@ -1779,10 +1793,22 @@ def test_complex_label(self):
17791793
"""
17801794

17811795
output = """
1796+
other_label:
1797+
{
1798+
1799+
}
1800+
1801+
other_label2:
1802+
{
1803+
1804+
}
1805+
17821806
my_label:
17831807
{
17841808
// Comment
1785-
do_thing()
1809+
_PyFrame_SetStackPointer(frame, stack_pointer);
1810+
do_thing();
1811+
stack_pointer = _PyFrame_GetStackPointer(frame);
17861812
if (complex) {
17871813
goto other_label;
17881814
}
@@ -1791,6 +1817,60 @@ def test_complex_label(self):
17911817
"""
17921818
self.run_cases_test(input, output)
17931819

1820+
def test_spilled_label(self):
1821+
input = """
1822+
spilled label(one) {
1823+
RELOAD_STACK();
1824+
goto two;
1825+
}
1826+
1827+
label(two) {
1828+
SAVE_STACK();
1829+
goto one;
1830+
}
1831+
"""
1832+
1833+
output = """
1834+
one:
1835+
{
1836+
/* STACK SPILLED */
1837+
stack_pointer = _PyFrame_GetStackPointer(frame);
1838+
goto two;
1839+
}
1840+
1841+
two:
1842+
{
1843+
_PyFrame_SetStackPointer(frame, stack_pointer);
1844+
goto one;
1845+
}
1846+
"""
1847+
self.run_cases_test(input, output)
1848+
1849+
1850+
def test_incorrect_spills(self):
1851+
input1 = """
1852+
spilled label(one) {
1853+
goto two;
1854+
}
1855+
1856+
label(two) {
1857+
}
1858+
"""
1859+
1860+
input2 = """
1861+
spilled label(one) {
1862+
}
1863+
1864+
label(two) {
1865+
goto one;
1866+
}
1867+
"""
1868+
with self.assertRaisesRegex(SyntaxError, ".*reload.*"):
1869+
self.run_cases_test(input1, "")
1870+
with self.assertRaisesRegex(SyntaxError, ".*spill.*"):
1871+
self.run_cases_test(input2, "")
1872+
1873+
17941874
def test_multiple_labels(self):
17951875
input = """
17961876
label(my_label_1) {
@@ -1802,7 +1882,7 @@ def test_multiple_labels(self):
18021882
label(my_label_2) {
18031883
// Comment
18041884
do_thing2();
1805-
goto my_label_3;
1885+
goto my_label_1;
18061886
}
18071887
"""
18081888

@@ -1818,7 +1898,7 @@ def test_multiple_labels(self):
18181898
{
18191899
// Comment
18201900
do_thing2();
1821-
goto my_label_3;
1901+
goto my_label_1;
18221902
}
18231903
"""
18241904

0 commit comments

Comments
 (0)