annotate tests/test-run-tests.py @ 26750:9f9ec4abe700

cmdutil: make in-memory changes visible to external editor (issue4378) Before this patch, external editor process for the commit log can't view some in-memory changes (especially, of dirstate), because they aren't written out until the end of transaction (or wlock). This causes unexpected output of Mercurial commands spawned from that editor process. To make in-memory changes visible to external editor process, this patch does: - write (or schedule to write) in-memory dirstate changes, and - set HG_PENDING environment variable, if: - a transaction is running, and - there are in-memory changes to be visible "hg diff" spawned from external editor process for "hg qrefresh" shows: - "changes newly imported into the topmost" before 49148d7868df(*) - "all changes recorded in the topmost by refreshing" after this patch (*) 49148d7868df changed steps invoking editor process Even though backward compatibility may be broken, the latter behavior looks reasonable, because "hg diff" spawned from the editor process consistently shows "what changes new revision records" regardless of invocation context. In fact, issue4378 itself should be resolved by 800e090e9c64, which made 'repo.transaction()' write in-memory dirstate changes out explicitly before starting transaction. It also made "hg qrefresh" imply 'dirstate.write()' before external editor invocation in call chain below. - mq.queue.refresh - strip.strip - repair.strip - localrepository.transaction - dirstate.write - localrepository.commit - invoke external editor Though, this patch has '(issue4378)' in own summary line to indicate that issues like issue4378 should be fixed by this. BTW, this patch adds '-m' option to a 'hg ci --amend' execution in 'test-commit-amend.t', to avoid invoking external editor process. In this case, "unsure" states may be changed to "clean" according to timestamp or so on. These changes should be written into pending file, if external editor invocation is required, Then, writing dirstate changes out breaks stability of test, because it shows "transaction abort!/rollback completed" occasionally. Aborting after editor process invocation while commands below may cause similar instability of tests, too (AFAIK, there is no more such one, at this revision) - commit --amend - without --message/--logfile - import - without --message/--logfile, - without --no-commit, - without --bypass, - one of below, and - patch has no description text, or - with --edit - aborting at the 1st patch, which adds or removes file(s) - if it only changes existing files, status is checked only for changed files by 'scmutil.matchfiles()', and transition from "unsure" to "normal" in dirstate doesn't occur (= dirstate isn't changed, and written out) - aborting at the 2nd or later patch implies other pending changes (e.g. changelog), and always causes showing "transaction abort!/rollback completed"
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 17 Oct 2015 01:15:34 +0900
parents 625dd917f04f
children f798ffe7cb08
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 """
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
6 from __future__ import print_function
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
7
20284
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
8 import os, re
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
9 # 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
10 if 'TERM' in os.environ:
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
11 del os.environ['TERM']
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
12 import doctest
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
13 run_tests = __import__('run-tests')
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
14
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
15 def prn(ex):
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
16 m = ex.args[0]
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
17 if isinstance(m, str):
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
18 print(m)
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
19 else:
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
20 print(m.decode('utf-8'))
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
21
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
22 def lm(expected, output):
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
23 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
24
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
25 does it generally work?
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
26 >>> lm(b'H*e (glob)\n', b'Here\n')
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
27 True
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 fail on bad test data
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
30 >>> try: lm(b'a\n',b'a')
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
31 ... except AssertionError as ex: print(ex)
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
32 missing newline
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
33 >>> try: lm(b'single backslash\n', b'single \backslash\n')
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
34 ... except AssertionError as ex: prn(ex)
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
35 single backslash or unknown char
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
36 """
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
37 assert (expected.endswith(b'\n')
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
38 and output.endswith(b'\n')), 'missing newline'
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
39 assert not re.search(br'[^ \w\\/\r\n()*?]', expected + output), \
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
40 b'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
41 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
42 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
43 return 'special: ' + match
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
44 elif isinstance(match, bytes):
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
45 return 'special: ' + match.decode('utf-8')
20273
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
46 else:
d9d6cbbeef0d run-tests: suggest to append glob when only path sep does not match
Simon Heimberg <simohe@besonet.ch>
parents: 20271
diff changeset
47 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
48
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
49 def wintests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
50 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
51
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
52 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
53 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
54 >>> os.altsep = True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
55
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
56 valid match on windows
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
57 >>> lm(b'g/a*/d (glob)\n', b'g\\abc/d\n')
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
58 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
59
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
60 direct matching, glob unnecessary
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
61 >>> lm(b'g/b (glob)\n', b'g/b\n')
20274
7a259dfe24f7 run-tests: print more information on unnecessary glob matching
Simon Heimberg <simohe@besonet.ch>
parents: 20273
diff changeset
62 'special: -glob'
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
63
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
64 missing glob
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
65 >>> lm(b'/g/c/d/fg\n', b'\\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
66 'special: +glob'
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
67
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
68 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
69 >>> os.altsep = _osaltsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
70 """
20284
e1e6ddaef299 tests: fix test-run-tests.py on OS X
Simon Heimberg <simohe@besonet.ch>
parents: 20274
diff changeset
71 pass
20271
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 def otherostests():
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
74 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
75
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
76 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
77 >>> _osaltsep = os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
78 >>> os.altsep = False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
79
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
80 backslash does not match slash
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
81 >>> lm(b'h/a* (glob)\n', b'h\\ab\n')
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
82 False
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 direct matching glob can not be recognized
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
85 >>> lm(b'h/b (glob)\n', b'h/b\n')
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
86 True
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
87
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
88 missing glob can not not be recognized
25061
625dd917f04f test-run-tests: fix for Python 3.5
Augie Fackler <augie@google.com>
parents: 21315
diff changeset
89 >>> lm(b'/h/c/df/g/\n', b'\\h/c\\df/g\\\n')
20271
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
90 False
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
91
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
92 restore os.altsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
93 >>> os.altsep = _osaltsep
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
94 """
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
95 pass
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
96
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
97 if __name__ == '__main__':
4453d08a616a tests: new test for line matching functions in run-tests
Simon Heimberg <simohe@besonet.ch>
parents:
diff changeset
98 doctest.testmod()