##// END OF EJS Templates
run-tests: print more information on unnecessary glob matching...
run-tests: print more information on unnecessary glob matching Extend the message with the test name and the approximate line number. (The line number is the one of the command producing the output.) Finding the line to fix is easier now. old message: ...... Info, unnecessary glob: at a/b/c (glob) .. new message: ...... Info, unnecessary glob in test-example.t (after line 9): at a/b/c (glob) .. The test result is still pass as before.

File last commit:

r20274:7a259dfe default
r20274:7a259dfe default
Show More
test-run-tests.py
84 lines | 2.2 KiB | text/x-python | PythonLexer
/ tests / test-run-tests.py
Simon Heimberg
tests: new test for line matching functions in run-tests...
r20271 """test line matching with some failing examples and some which warn
run-test.t only checks positive matches and can not see warnings
(both by design)
"""
import doctest, os, re
run_tests = __import__('run-tests')
def lm(expected, output):
r"""check if output matches expected
does it generally work?
>>> lm('H*e (glob)\n', 'Here\n')
True
fail on bad test data
>>> try: lm('a\n','a')
... except AssertionError, ex: print ex
missing newline
>>> try: lm('single backslash\n', 'single \backslash\n')
... except AssertionError, ex: print ex
single backslash or unknown char
"""
assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \
'single backslash or unknown char'
match = run_tests.linematch(expected, output)
Simon Heimberg
run-tests: suggest to append glob when only path sep does not match...
r20273 if isinstance(match, str):
return 'special: ' + match
else:
return bool(match) # do not return match object
Simon Heimberg
tests: new test for line matching functions in run-tests...
r20271
def wintests():
r"""test matching like running on windows
enable windows matching on any os
>>> _osaltsep = os.altsep
>>> os.altsep = True
valid match on windows
>>> lm('g/a*/d (glob)\n', 'g\\abc/d\n')
True
direct matching, glob unnecessary
>>> lm('g/b (glob)\n', 'g/b\n')
Simon Heimberg
run-tests: print more information on unnecessary glob matching...
r20274 'special: -glob'
Simon Heimberg
tests: new test for line matching functions in run-tests...
r20271
missing glob
>>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
Simon Heimberg
run-tests: suggest to append glob when only path sep does not match...
r20273 'special: +glob'
Simon Heimberg
tests: new test for line matching functions in run-tests...
r20271
restore os.altsep
>>> os.altsep = _osaltsep
"""
os.altsep # for pyflakes, because it does not see os in the doctest
def otherostests():
r"""test matching like running on non-windows os
disable windows matching on any os
>>> _osaltsep = os.altsep
>>> os.altsep = False
backslash does not match slash
>>> lm('h/a* (glob)\n', 'h\\ab\n')
False
direct matching glob can not be recognized
>>> lm('h/b (glob)\n', 'h/b\n')
True
missing glob can not not be recognized
>>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n')
False
restore os.altsep
>>> os.altsep = _osaltsep
"""
pass
if __name__ == '__main__':
doctest.testmod()