##// END OF EJS Templates
tests: fix test-run-tests.py on OS X...
Simon Heimberg -
r20284:e1e6ddae default
parent child Browse files
Show More
@@ -1,84 +1,87 b''
1 """test line matching with some failing examples and some which warn
1 """test line matching with some failing examples and some which warn
2
2
3 run-test.t only checks positive matches and can not see warnings
3 run-test.t only checks positive matches and can not see warnings
4 (both by design)
4 (both by design)
5 """
5 """
6
6
7
7 import os, re
8 import doctest, os, re
8 # this is hack to make sure no escape characters are inserted into the output
9 if 'TERM' in os.environ:
10 del os.environ['TERM']
11 import doctest
9 run_tests = __import__('run-tests')
12 run_tests = __import__('run-tests')
10
13
11 def lm(expected, output):
14 def lm(expected, output):
12 r"""check if output matches expected
15 r"""check if output matches expected
13
16
14 does it generally work?
17 does it generally work?
15 >>> lm('H*e (glob)\n', 'Here\n')
18 >>> lm('H*e (glob)\n', 'Here\n')
16 True
19 True
17
20
18 fail on bad test data
21 fail on bad test data
19 >>> try: lm('a\n','a')
22 >>> try: lm('a\n','a')
20 ... except AssertionError, ex: print ex
23 ... except AssertionError, ex: print ex
21 missing newline
24 missing newline
22 >>> try: lm('single backslash\n', 'single \backslash\n')
25 >>> try: lm('single backslash\n', 'single \backslash\n')
23 ... except AssertionError, ex: print ex
26 ... except AssertionError, ex: print ex
24 single backslash or unknown char
27 single backslash or unknown char
25 """
28 """
26 assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
29 assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
27 assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \
30 assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \
28 'single backslash or unknown char'
31 'single backslash or unknown char'
29 match = run_tests.linematch(expected, output)
32 match = run_tests.linematch(expected, output)
30 if isinstance(match, str):
33 if isinstance(match, str):
31 return 'special: ' + match
34 return 'special: ' + match
32 else:
35 else:
33 return bool(match) # do not return match object
36 return bool(match) # do not return match object
34
37
35 def wintests():
38 def wintests():
36 r"""test matching like running on windows
39 r"""test matching like running on windows
37
40
38 enable windows matching on any os
41 enable windows matching on any os
39 >>> _osaltsep = os.altsep
42 >>> _osaltsep = os.altsep
40 >>> os.altsep = True
43 >>> os.altsep = True
41
44
42 valid match on windows
45 valid match on windows
43 >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n')
46 >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n')
44 True
47 True
45
48
46 direct matching, glob unnecessary
49 direct matching, glob unnecessary
47 >>> lm('g/b (glob)\n', 'g/b\n')
50 >>> lm('g/b (glob)\n', 'g/b\n')
48 'special: -glob'
51 'special: -glob'
49
52
50 missing glob
53 missing glob
51 >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
54 >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
52 'special: +glob'
55 'special: +glob'
53
56
54 restore os.altsep
57 restore os.altsep
55 >>> os.altsep = _osaltsep
58 >>> os.altsep = _osaltsep
56 """
59 """
57 os.altsep # for pyflakes, because it does not see os in the doctest
60 pass
58
61
59 def otherostests():
62 def otherostests():
60 r"""test matching like running on non-windows os
63 r"""test matching like running on non-windows os
61
64
62 disable windows matching on any os
65 disable windows matching on any os
63 >>> _osaltsep = os.altsep
66 >>> _osaltsep = os.altsep
64 >>> os.altsep = False
67 >>> os.altsep = False
65
68
66 backslash does not match slash
69 backslash does not match slash
67 >>> lm('h/a* (glob)\n', 'h\\ab\n')
70 >>> lm('h/a* (glob)\n', 'h\\ab\n')
68 False
71 False
69
72
70 direct matching glob can not be recognized
73 direct matching glob can not be recognized
71 >>> lm('h/b (glob)\n', 'h/b\n')
74 >>> lm('h/b (glob)\n', 'h/b\n')
72 True
75 True
73
76
74 missing glob can not not be recognized
77 missing glob can not not be recognized
75 >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n')
78 >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n')
76 False
79 False
77
80
78 restore os.altsep
81 restore os.altsep
79 >>> os.altsep = _osaltsep
82 >>> os.altsep = _osaltsep
80 """
83 """
81 pass
84 pass
82
85
83 if __name__ == '__main__':
86 if __name__ == '__main__':
84 doctest.testmod()
87 doctest.testmod()
General Comments 0
You need to be logged in to leave comments. Login now