Mercurial > hg
annotate tests/test-run-tests.py @ 23923:ab6fd3205dad stable
largefiles: fix commit of a directory with no largefile changes (issue4330)
When a directory is named in the commit file list, the previous behavior was to
walk the list, and if no normal files in the directory were also named, add the
corresponding standin for each largefile in that directory. The directory is
then dropped from the list, so that committing a directory with no normal file
changes works. It then added the corresponding standin directory for the first
largefile seen, by prefixing it with '.hglf/'.
The latter is unnecessary since each affected largefile is explicitly referenced
by its standin in the list. It also caused an abort if there were no changed
largefiles in the directory, because none of its standins changed:
abort: .hglf/foo/bar: no match under directory!
This list of files is used to tweak a matcher in lfutil.updatestandinsbymatch(),
which is what is passed to commit().
The status() call that is ultimately done in the commit code with this matcher
seems to have some OS specific differences. It is not necessary to append '.'
for Windows to run the largefiles tests cleanly. But if '.' is not added to the
list, the match function isn't called on Linux, so status() would miss any
normal files that were also in a named directory. The commit then proceeds
without those normal files, or says "nothing changed" if there were no changed
largefiles in the directory. This is not filesystem specific, as VFAT on Linux
had the same behavior as when run on ext4. It is also not an issue with
lfilesrepo.status(), since that only calls the overridden implementation when
paths are passed to commit. I dont have access to an OS X machine ATM to test
there.
Maybe there's a better way to do this. But since the standin directory for the
first largefile was previously being added, and that caused the same walk in
status(), there's no preformance change to this. There is no danger of
erroneously committing files in '.', because the original match function is
called, and if it fails, the lfutil.updatestandinsbymatch() tweaked matcher only
indicates a match if the file is in the list of standins- and '.' never is. The
added tests confirm this.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 18 Jan 2015 15:15:40 -0500 |
parents | 56610da39b48 |
children | 625dd917f04f |
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() |