comparison tests/run-tests.py @ 50252:a6b8b1ab9116

branching: merge stable into default The clippy god had to be appeased on some aspect.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 02 Mar 2023 19:02:52 +0100
parents afa9d73780e1 6515d9a6592d
children ada9a0245fd7
comparison
equal deleted inserted replaced
50251:2fbc109fd58a 50252:a6b8b1ab9116
1829 # Expected shell script output. 1829 # Expected shell script output.
1830 expected = {} 1830 expected = {}
1831 1831
1832 pos = prepos = -1 1832 pos = prepos = -1
1833 1833
1834 # True or False when in a true or false conditional section 1834 # The current stack of conditionnal section.
1835 skipping = None 1835 # Each relevant conditionnal section can have the following value:
1836 # - True: we should run this block
1837 # - False: we should skip this block
1838 # - None: The parent block is skipped,
1839 # (no branch of this one will ever run)
1840 condition_stack = []
1841
1842 def run_line():
1843 """return True if the current line should be run"""
1844 if not condition_stack:
1845 return True
1846 return bool(condition_stack[-1])
1847
1848 def push_conditional_block(should_run):
1849 """Push a new conditional context, with its initial state
1850
1851 i.e. entry a #if block"""
1852 if not run_line():
1853 condition_stack.append(None)
1854 else:
1855 condition_stack.append(should_run)
1856
1857 def flip_conditional():
1858 """reverse the current condition state
1859
1860 i.e. enter a #else
1861 """
1862 assert condition_stack
1863 if condition_stack[-1] is not None:
1864 condition_stack[-1] = not condition_stack[-1]
1865
1866 def pop_conditional():
1867 """exit the current skipping context
1868
1869 i.e. reach the #endif"""
1870 assert condition_stack
1871 condition_stack.pop()
1836 1872
1837 # We keep track of whether or not we're in a Python block so we 1873 # We keep track of whether or not we're in a Python block so we
1838 # can generate the surrounding doctest magic. 1874 # can generate the surrounding doctest magic.
1839 inpython = False 1875 inpython = False
1840 1876
1886 lsplit = l.split() 1922 lsplit = l.split()
1887 if len(lsplit) < 2 or lsplit[0] != b'#require': 1923 if len(lsplit) < 2 or lsplit[0] != b'#require':
1888 after.setdefault(pos, []).append( 1924 after.setdefault(pos, []).append(
1889 b' !!! invalid #require\n' 1925 b' !!! invalid #require\n'
1890 ) 1926 )
1891 if not skipping: 1927 if run_line():
1892 haveresult, message = self._hghave(lsplit[1:]) 1928 haveresult, message = self._hghave(lsplit[1:])
1893 if not haveresult: 1929 if not haveresult:
1894 script = [b'echo "%s"\nexit 80\n' % message] 1930 script = [b'echo "%s"\nexit 80\n' % message]
1895 break 1931 break
1896 after.setdefault(pos, []).append(l) 1932 after.setdefault(pos, []).append(l)
1897 elif l.startswith(b'#if'): 1933 elif l.startswith(b'#if'):
1898 lsplit = l.split() 1934 lsplit = l.split()
1899 if len(lsplit) < 2 or lsplit[0] != b'#if': 1935 if len(lsplit) < 2 or lsplit[0] != b'#if':
1900 after.setdefault(pos, []).append(b' !!! invalid #if\n') 1936 after.setdefault(pos, []).append(b' !!! invalid #if\n')
1901 if skipping is not None: 1937 push_conditional_block(self._iftest(lsplit[1:]))
1902 after.setdefault(pos, []).append(b' !!! nested #if\n')
1903 skipping = not self._iftest(lsplit[1:])
1904 after.setdefault(pos, []).append(l) 1938 after.setdefault(pos, []).append(l)
1905 elif l.startswith(b'#else'): 1939 elif l.startswith(b'#else'):
1906 if skipping is None: 1940 if not condition_stack:
1907 after.setdefault(pos, []).append(b' !!! missing #if\n') 1941 after.setdefault(pos, []).append(b' !!! missing #if\n')
1908 skipping = not skipping 1942 flip_conditional()
1909 after.setdefault(pos, []).append(l) 1943 after.setdefault(pos, []).append(l)
1910 elif l.startswith(b'#endif'): 1944 elif l.startswith(b'#endif'):
1911 if skipping is None: 1945 if not condition_stack:
1912 after.setdefault(pos, []).append(b' !!! missing #if\n') 1946 after.setdefault(pos, []).append(b' !!! missing #if\n')
1913 skipping = None 1947 pop_conditional()
1914 after.setdefault(pos, []).append(l) 1948 after.setdefault(pos, []).append(l)
1915 elif skipping: 1949 elif not run_line():
1916 after.setdefault(pos, []).append(l) 1950 after.setdefault(pos, []).append(l)
1917 elif l.startswith(b' >>> '): # python inlines 1951 elif l.startswith(b' >>> '): # python inlines
1918 after.setdefault(pos, []).append(l) 1952 after.setdefault(pos, []).append(l)
1919 prepos = pos 1953 prepos = pos
1920 pos = n 1954 pos = n
1955 # Non-command/result. Queue up for merged output. 1989 # Non-command/result. Queue up for merged output.
1956 after.setdefault(pos, []).append(l) 1990 after.setdefault(pos, []).append(l)
1957 1991
1958 if inpython: 1992 if inpython:
1959 script.append(b'EOF\n') 1993 script.append(b'EOF\n')
1960 if skipping is not None: 1994 if condition_stack:
1961 after.setdefault(pos, []).append(b' !!! missing #endif\n') 1995 after.setdefault(pos, []).append(b' !!! missing #endif\n')
1962 addsalt(n + 1, False) 1996 addsalt(n + 1, False)
1963 # Need to end any current per-command trace 1997 # Need to end any current per-command trace
1964 if activetrace: 1998 if activetrace:
1965 toggletrace() 1999 toggletrace()