annotate tests/test-run-tests.py @ 24353:3f6bf9f29e7b

bookmarks: prevent divergent bookmark from being updated unexpectedly Before this patch, "@99" suffixed bookmark may be updated unexpectedly by the bookmark value on the remote side at "hg pull", if all of "@1" to "@99" suffixed bookmarks exist in the local repository, because variable "n" still refers "@99" suffixed bookmark after the loop to examine "@num" suffixes, even though it already exists in the local repository. This patch prevents divergent bookmark from being updated unexpectedly, and shows warning message in such situation. This patch uses original python script "seq.py" instead of "seq" command to create sequence numbers in the test, because "seq" command may not be available: it isn't defined in recent POSIX specification (POSIX.1-2001 2013 Edition or XPG7)
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 17 Mar 2015 18:20:24 +0900
parents 56610da39b48
children 625dd917f04f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
1 """test line matching with some failing examples and some which warn
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
2
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
3 run-test.t only checks positive matches and can not see warnings
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
4 (both by design)
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
5 """
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
6
20284
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
7 import os, re
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
8 # this is hack to make sure no escape characters are inserted into the output
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
9 if 'TERM' in os.environ:
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
10 del os.environ['TERM']
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
11 import doctest
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
12 run_tests = __import__('run-tests')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
13
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
14 def lm(expected, output):
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
15 r"""check if output matches expected
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
16
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
17 does it generally work?
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
18 >>> lm('H*e (glob)\n', 'Here\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
19 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
20
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
21 fail on bad test data
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
22 >>> try: lm('a\n','a')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
23 ... except AssertionError, ex: print ex
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
24 missing newline
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
25 >>> try: lm('single backslash\n', 'single \backslash\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
26 ... except AssertionError, ex: print ex
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
27 single backslash or unknown char
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
28 """
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
29 assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
30 assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
31 'single backslash or unknown char'
21315
56610da39b48 run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents: 20284
diff changeset
32 match = run_tests.TTest.linematch(expected, output)
20273
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
33 if isinstance(match, str):
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
34 return 'special: ' + match
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
35 else:
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
36 return bool(match) # do not return match object
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
37
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
38 def wintests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
39 r"""test matching like running on windows
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
40
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
41 enable windows matching on any os
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
42 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
43 >>> os.altsep = True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
44
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
45 valid match on windows
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
46 >>> lm('g/a*/d (glob)\n', 'g\\abc/d\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
47 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
48
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
49 direct matching, glob unnecessary
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
50 >>> lm('g/b (glob)\n', 'g/b\n')
20274
7a259dfe24f7 run-tests: print more information on unnecessary glob matching
Simon Heimberg <simohe@besonet.ch>
parents: 20273
diff changeset
51 'special: -glob'
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
52
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
53 missing glob
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
54 >>> lm('/g/c/d/fg\n', '\\g\\c\\d/fg\n')
20273
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
55 'special: +glob'
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
56
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
57 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
58 >>> os.altsep = _osaltsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
59 """
20284
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
60 pass
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
61
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
62 def otherostests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
63 r"""test matching like running on non-windows os
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
64
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
65 disable windows matching on any os
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
66 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
67 >>> os.altsep = False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
68
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
69 backslash does not match slash
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
70 >>> lm('h/a* (glob)\n', 'h\\ab\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
71 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
72
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
73 direct matching glob can not be recognized
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
74 >>> lm('h/b (glob)\n', 'h/b\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
75 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
76
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
77 missing glob can not not be recognized
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
78 >>> lm('/h/c/df/g/\n', '\\h/c\\df/g\\\n')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
79 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
80
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
81 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
82 >>> os.altsep = _osaltsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
83 """
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
84 pass
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
85
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
86 if __name__ == '__main__':
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
87 doctest.testmod()