Show More
@@ -3,6 +3,7 b'' | |||
|
3 | 3 | run-test.t only checks positive matches and can not see warnings |
|
4 | 4 | (both by design) |
|
5 | 5 | """ |
|
6 | from __future__ import print_function | |
|
6 | 7 | |
|
7 | 8 | import os, re |
|
8 | 9 | # this is hack to make sure no escape characters are inserted into the output |
@@ -11,27 +12,37 b" if 'TERM' in os.environ:" | |||
|
11 | 12 | import doctest |
|
12 | 13 | run_tests = __import__('run-tests') |
|
13 | 14 | |
|
15 | def prn(ex): | |
|
16 | m = ex.args[0] | |
|
17 | if isinstance(m, str): | |
|
18 | print(m) | |
|
19 | else: | |
|
20 | print(m.decode('utf-8')) | |
|
21 | ||
|
14 | 22 | def lm(expected, output): |
|
15 | 23 | r"""check if output matches expected |
|
16 | 24 | |
|
17 | 25 | does it generally work? |
|
18 | >>> lm('H*e (glob)\n', 'Here\n') | |
|
26 | >>> lm(b'H*e (glob)\n', b'Here\n') | |
|
19 | 27 | True |
|
20 | 28 | |
|
21 | 29 | fail on bad test data |
|
22 | >>> try: lm('a\n','a') | |
|
23 |
... except AssertionError |
|
|
30 | >>> try: lm(b'a\n',b'a') | |
|
31 | ... except AssertionError as ex: print(ex) | |
|
24 | 32 | missing newline |
|
25 | >>> try: lm('single backslash\n', 'single \backslash\n') | |
|
26 |
... except AssertionError |
|
|
33 | >>> try: lm(b'single backslash\n', b'single \backslash\n') | |
|
34 | ... except AssertionError as ex: prn(ex) | |
|
27 | 35 | single backslash or unknown char |
|
28 | 36 | """ |
|
29 | assert expected.endswith('\n') and output.endswith('\n'), 'missing newline' | |
|
30 | assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \ | |
|
31 | 'single backslash or unknown char' | |
|
37 | assert (expected.endswith(b'\n') | |
|
38 | and output.endswith(b'\n')), 'missing newline' | |
|
39 | assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \ | |
|
40 | b'single backslash or unknown char' | |
|
32 | 41 | match = run_tests.TTest.linematch(expected, output) |
|
33 | 42 | if isinstance(match, str): |
|
34 | 43 | return 'special: ' + match |
|
44 | elif isinstance(match, bytes): | |
|
45 | return 'special: ' + match.decode('utf-8') | |
|
35 | 46 | else: |
|
36 | 47 | return bool(match) # do not return match object |
|
37 | 48 | |
@@ -43,15 +54,15 b' def wintests():' | |||
|
43 | 54 | >>> os.altsep = True |
|
44 | 55 | |
|
45 | 56 | valid match on windows |
|
46 | >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n') | |
|
57 | >>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n') | |
|
47 | 58 | True |
|
48 | 59 | |
|
49 | 60 | direct matching, glob unnecessary |
|
50 | >>> lm('g/b (glob)\n', 'g/b\n') | |
|
61 | >>> lm(b'g/b (glob)\n', b'g/b\n') | |
|
51 | 62 | 'special: -glob' |
|
52 | 63 | |
|
53 | 64 | missing glob |
|
54 | >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n') | |
|
65 | >>> lm(b'/g/c/d/fg\n', b'\\g\\c\\d/fg\n') | |
|
55 | 66 | 'special: +glob' |
|
56 | 67 | |
|
57 | 68 | restore os.altsep |
@@ -67,15 +78,15 b' def otherostests():' | |||
|
67 | 78 | >>> os.altsep = False |
|
68 | 79 | |
|
69 | 80 | backslash does not match slash |
|
70 | >>> lm('h/a* (glob)\n', 'h\\ab\n') | |
|
81 | >>> lm(b'h/a* (glob)\n', b'h\\ab\n') | |
|
71 | 82 | False |
|
72 | 83 | |
|
73 | 84 | direct matching glob can not be recognized |
|
74 | >>> lm('h/b (glob)\n', 'h/b\n') | |
|
85 | >>> lm(b'h/b (glob)\n', b'h/b\n') | |
|
75 | 86 | True |
|
76 | 87 | |
|
77 | 88 | missing glob can not not be recognized |
|
78 | >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n') | |
|
89 | >>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n') | |
|
79 | 90 | False |
|
80 | 91 | |
|
81 | 92 | restore os.altsep |
General Comments 0
You need to be logged in to leave comments.
Login now