##// END OF EJS Templates
run-tests: make it possible to nest conditionals...
marmoute -
r51107:6515d9a6 stable
parent child Browse files
Show More
@@ -1834,8 +1834,44 b' class TTest(Test):'
1834 1834
1835 1835 pos = prepos = -1
1836 1836
1837 # True or False when in a true or false conditional section
1838 skipping = None
1837 # The current stack of conditionnal section.
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 1876 # We keep track of whether or not we're in a Python block so we
1841 1877 # can generate the surrounding doctest magic.
@@ -1891,7 +1927,7 b' class TTest(Test):'
1891 1927 after.setdefault(pos, []).append(
1892 1928 b' !!! invalid #require\n'
1893 1929 )
1894 if not skipping:
1930 if run_line():
1895 1931 haveresult, message = self._hghave(lsplit[1:])
1896 1932 if not haveresult:
1897 1933 script = [b'echo "%s"\nexit 80\n' % message]
@@ -1901,21 +1937,19 b' class TTest(Test):'
1901 1937 lsplit = l.split()
1902 1938 if len(lsplit) < 2 or lsplit[0] != b'#if':
1903 1939 after.setdefault(pos, []).append(b' !!! invalid #if\n')
1904 if skipping is not None:
1905 after.setdefault(pos, []).append(b' !!! nested #if\n')
1906 skipping = not self._iftest(lsplit[1:])
1940 push_conditional_block(self._iftest(lsplit[1:]))
1907 1941 after.setdefault(pos, []).append(l)
1908 1942 elif l.startswith(b'#else'):
1909 if skipping is None:
1943 if not condition_stack:
1910 1944 after.setdefault(pos, []).append(b' !!! missing #if\n')
1911 skipping = not skipping
1945 flip_conditional()
1912 1946 after.setdefault(pos, []).append(l)
1913 1947 elif l.startswith(b'#endif'):
1914 if skipping is None:
1948 if not condition_stack:
1915 1949 after.setdefault(pos, []).append(b' !!! missing #if\n')
1916 skipping = None
1950 pop_conditional()
1917 1951 after.setdefault(pos, []).append(l)
1918 elif skipping:
1952 elif not run_line():
1919 1953 after.setdefault(pos, []).append(l)
1920 1954 elif l.startswith(b' >>> '): # python inlines
1921 1955 after.setdefault(pos, []).append(l)
@@ -1960,7 +1994,7 b' class TTest(Test):'
1960 1994
1961 1995 if inpython:
1962 1996 script.append(b'EOF\n')
1963 if skipping is not None:
1997 if condition_stack:
1964 1998 after.setdefault(pos, []).append(b' !!! missing #endif\n')
1965 1999 addsalt(n + 1, False)
1966 2000 # Need to end any current per-command trace
General Comments 0
You need to be logged in to leave comments. Login now