Show More
@@ -1834,8 +1834,44 b' class TTest(Test):' | |||||
1834 |
|
1834 | |||
1835 | pos = prepos = -1 |
|
1835 | pos = prepos = -1 | |
1836 |
|
1836 | |||
1837 |
# T |
|
1837 | # The current stack of conditionnal section. | |
1838 | skipping = None |
|
1838 | # Each relevant conditionnal section can have the following value: | |
|
1839 | # - True: we should run this block | |||
|
1840 | # - False: we should skip this block | |||
|
1841 | # - None: The parent block is skipped, | |||
|
1842 | # (no branch of this one will ever run) | |||
|
1843 | condition_stack = [] | |||
|
1844 | ||||
|
1845 | def run_line(): | |||
|
1846 | """return True if the current line should be run""" | |||
|
1847 | if not condition_stack: | |||
|
1848 | return True | |||
|
1849 | return bool(condition_stack[-1]) | |||
|
1850 | ||||
|
1851 | def push_conditional_block(should_run): | |||
|
1852 | """Push a new conditional context, with its initial state | |||
|
1853 | ||||
|
1854 | i.e. entry a #if block""" | |||
|
1855 | if not run_line(): | |||
|
1856 | condition_stack.append(None) | |||
|
1857 | else: | |||
|
1858 | condition_stack.append(should_run) | |||
|
1859 | ||||
|
1860 | def flip_conditional(): | |||
|
1861 | """reverse the current condition state | |||
|
1862 | ||||
|
1863 | i.e. enter a #else | |||
|
1864 | """ | |||
|
1865 | assert condition_stack | |||
|
1866 | if condition_stack[-1] is not None: | |||
|
1867 | condition_stack[-1] = not condition_stack[-1] | |||
|
1868 | ||||
|
1869 | def pop_conditional(): | |||
|
1870 | """exit the current skipping context | |||
|
1871 | ||||
|
1872 | i.e. reach the #endif""" | |||
|
1873 | assert condition_stack | |||
|
1874 | condition_stack.pop() | |||
1839 |
|
1875 | |||
1840 | # We keep track of whether or not we're in a Python block so we |
|
1876 | # We keep track of whether or not we're in a Python block so we | |
1841 | # can generate the surrounding doctest magic. |
|
1877 | # can generate the surrounding doctest magic. | |
@@ -1891,7 +1927,7 b' class TTest(Test):' | |||||
1891 | after.setdefault(pos, []).append( |
|
1927 | after.setdefault(pos, []).append( | |
1892 | b' !!! invalid #require\n' |
|
1928 | b' !!! invalid #require\n' | |
1893 | ) |
|
1929 | ) | |
1894 |
if |
|
1930 | if run_line(): | |
1895 | haveresult, message = self._hghave(lsplit[1:]) |
|
1931 | haveresult, message = self._hghave(lsplit[1:]) | |
1896 | if not haveresult: |
|
1932 | if not haveresult: | |
1897 | script = [b'echo "%s"\nexit 80\n' % message] |
|
1933 | script = [b'echo "%s"\nexit 80\n' % message] | |
@@ -1901,21 +1937,19 b' class TTest(Test):' | |||||
1901 | lsplit = l.split() |
|
1937 | lsplit = l.split() | |
1902 | if len(lsplit) < 2 or lsplit[0] != b'#if': |
|
1938 | if len(lsplit) < 2 or lsplit[0] != b'#if': | |
1903 | after.setdefault(pos, []).append(b' !!! invalid #if\n') |
|
1939 | after.setdefault(pos, []).append(b' !!! invalid #if\n') | |
1904 | if skipping is not None: |
|
1940 | push_conditional_block(self._iftest(lsplit[1:])) | |
1905 | after.setdefault(pos, []).append(b' !!! nested #if\n') |
|
|||
1906 | skipping = not self._iftest(lsplit[1:]) |
|
|||
1907 | after.setdefault(pos, []).append(l) |
|
1941 | after.setdefault(pos, []).append(l) | |
1908 | elif l.startswith(b'#else'): |
|
1942 | elif l.startswith(b'#else'): | |
1909 |
if |
|
1943 | if not condition_stack: | |
1910 | after.setdefault(pos, []).append(b' !!! missing #if\n') |
|
1944 | after.setdefault(pos, []).append(b' !!! missing #if\n') | |
1911 | skipping = not skipping |
|
1945 | flip_conditional() | |
1912 | after.setdefault(pos, []).append(l) |
|
1946 | after.setdefault(pos, []).append(l) | |
1913 | elif l.startswith(b'#endif'): |
|
1947 | elif l.startswith(b'#endif'): | |
1914 |
if |
|
1948 | if not condition_stack: | |
1915 | after.setdefault(pos, []).append(b' !!! missing #if\n') |
|
1949 | after.setdefault(pos, []).append(b' !!! missing #if\n') | |
1916 |
|
|
1950 | pop_conditional() | |
1917 | after.setdefault(pos, []).append(l) |
|
1951 | after.setdefault(pos, []).append(l) | |
1918 |
elif |
|
1952 | elif not run_line(): | |
1919 | after.setdefault(pos, []).append(l) |
|
1953 | after.setdefault(pos, []).append(l) | |
1920 | elif l.startswith(b' >>> '): # python inlines |
|
1954 | elif l.startswith(b' >>> '): # python inlines | |
1921 | after.setdefault(pos, []).append(l) |
|
1955 | after.setdefault(pos, []).append(l) | |
@@ -1960,7 +1994,7 b' class TTest(Test):' | |||||
1960 |
|
1994 | |||
1961 | if inpython: |
|
1995 | if inpython: | |
1962 | script.append(b'EOF\n') |
|
1996 | script.append(b'EOF\n') | |
1963 | if skipping is not None: |
|
1997 | if condition_stack: | |
1964 | after.setdefault(pos, []).append(b' !!! missing #endif\n') |
|
1998 | after.setdefault(pos, []).append(b' !!! missing #endif\n') | |
1965 | addsalt(n + 1, False) |
|
1999 | addsalt(n + 1, False) | |
1966 | # Need to end any current per-command trace |
|
2000 | # Need to end any current per-command trace |
General Comments 0
You need to be logged in to leave comments.
Login now