tests/test-run-tests.py
changeset 43076 2372284d9457
parent 41759 aaad36b88298
child 47573 75b623801f6a
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
     6 from __future__ import absolute_import, print_function
     6 from __future__ import absolute_import, print_function
     7 
     7 
     8 import doctest
     8 import doctest
     9 import os
     9 import os
    10 import re
    10 import re
       
    11 
    11 # this is hack to make sure no escape characters are inserted into the output
    12 # this is hack to make sure no escape characters are inserted into the output
    12 if 'TERM' in os.environ:
    13 if 'TERM' in os.environ:
    13     del os.environ['TERM']
    14     del os.environ['TERM']
    14 run_tests = __import__('run-tests')
    15 run_tests = __import__('run-tests')
       
    16 
    15 
    17 
    16 def prn(ex):
    18 def prn(ex):
    17     m = ex.args[0]
    19     m = ex.args[0]
    18     if isinstance(m, str):
    20     if isinstance(m, str):
    19         print(m)
    21         print(m)
    20     else:
    22     else:
    21         print(m.decode('utf-8'))
    23         print(m.decode('utf-8'))
       
    24 
    22 
    25 
    23 def lm(expected, output):
    26 def lm(expected, output):
    24     r"""check if output matches expected
    27     r"""check if output matches expected
    25 
    28 
    26     does it generally work?
    29     does it generally work?
    33         missing newline
    36         missing newline
    34         >>> try: lm(b'single backslash\n', b'single \backslash\n')
    37         >>> try: lm(b'single backslash\n', b'single \backslash\n')
    35         ... except AssertionError as ex: prn(ex)
    38         ... except AssertionError as ex: prn(ex)
    36         single backslash or unknown char
    39         single backslash or unknown char
    37     """
    40     """
    38     assert (expected.endswith(b'\n')
    41     assert expected.endswith(b'\n') and output.endswith(
    39             and output.endswith(b'\n')), 'missing newline'
    42         b'\n'
    40     assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), (
    43     ), 'missing newline'
    41            b'single backslash or unknown char')
    44     assert not re.search(
       
    45         br'[^ \w\\/\r\n()*?]', expected + output
       
    46     ), b'single backslash or unknown char'
    42     test = run_tests.TTest(b'test-run-test.t', b'.', b'.')
    47     test = run_tests.TTest(b'test-run-test.t', b'.', b'.')
    43     match, exact = test.linematch(expected, output)
    48     match, exact = test.linematch(expected, output)
    44     if isinstance(match, str):
    49     if isinstance(match, str):
    45         return 'special: ' + match
    50         return 'special: ' + match
    46     elif isinstance(match, bytes):
    51     elif isinstance(match, bytes):
    47         return 'special: ' + match.decode('utf-8')
    52         return 'special: ' + match.decode('utf-8')
    48     else:
    53     else:
    49         return bool(match) # do not return match object
    54         return bool(match)  # do not return match object
       
    55 
    50 
    56 
    51 def wintests():
    57 def wintests():
    52     r"""test matching like running on windows
    58     r"""test matching like running on windows
    53 
    59 
    54     enable windows matching on any os
    60     enable windows matching on any os
    75         >>> os.altsep = _osaltsep
    81         >>> os.altsep = _osaltsep
    76         >>> os.name = _osname
    82         >>> os.name = _osname
    77     """
    83     """
    78     pass
    84     pass
    79 
    85 
       
    86 
    80 def otherostests():
    87 def otherostests():
    81     r"""test matching like running on non-windows os
    88     r"""test matching like running on non-windows os
    82 
    89 
    83     disable windows matching on any os
    90     disable windows matching on any os
    84         >>> _osaltsep = os.altsep
    91         >>> _osaltsep = os.altsep
   102         >>> os.altsep = _osaltsep
   109         >>> os.altsep = _osaltsep
   103         >>> os.name = _osname
   110         >>> os.name = _osname
   104     """
   111     """
   105     pass
   112     pass
   106 
   113 
       
   114 
   107 if __name__ == '__main__':
   115 if __name__ == '__main__':
   108     doctest.testmod()
   116     doctest.testmod()