Mercurial > hg
annotate tests/hghave @ 49603:3eda36e9b3d6 stable
matcher: fix issues regex flag contained in pattern (issue6759)
Python 3.11 is now enforcing that flag must be at the beginning of the regex
This creates a serious regression for people using Python 3.11 with an hgignore
using flag in a "relre" pattern.
We now detect any flags in such pattern and "prepend" our ".*" pattern after them.
In addition, we now insert the flag in the regexp to only affect the pattern we
are rewriting. Otherwise, the regex built from the combined pattern would these
flags in the middle of it anyway.
As a side effect of this last change, we fix a bug… before this change regex
flag in a pattern would affect all combined patterns. That was bad and is not
longer the case.
The Rust code needs to be updated to fix that very bug, but we will do it in
another changeset.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 16 Nov 2022 13:05:01 +0100 |
parents | 6000f5b25c9b |
children |
rev | line source |
---|---|
47500
23f5ed6dbcb1
run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45830
diff
changeset
|
1 #!/usr/bin/env python |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 """Test the running system for features availability. Exit with zero |
5084
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
3 if all features are there, non-zero otherwise. If a feature name is |
80309fa23cdb
hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents:
5081
diff
changeset
|
4 prefixed with "no-", the absence of feature is tested. |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 """ |
28283
544444991c83
hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28047
diff
changeset
|
6 |
544444991c83
hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28047
diff
changeset
|
7 |
29161
f8b274df33dc
py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29141
diff
changeset
|
8 import hghave |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
9 import optparse |
29161
f8b274df33dc
py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29141
diff
changeset
|
10 import os |
f8b274df33dc
py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29141
diff
changeset
|
11 import sys |
9446
57d682d7d2da
test-gendoc: test documentation generation
Martin Geisler <mg@lazybytes.net>
parents:
9395
diff
changeset
|
12 |
16966
23f621ca04b5
tests/hghave: extract hghave.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
16891
diff
changeset
|
13 checks = hghave.checks |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
14 |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
15 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
16 def list_features(): |
29141
ba8999547f81
hghave: switch from iteritems to items
timeless <timeless@mozdev.org>
parents:
28283
diff
changeset
|
17 for name, feature in sorted(checks.items()): |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
18 desc = feature[1] |
28283
544444991c83
hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28047
diff
changeset
|
19 print(name + ':', desc) |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
20 |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
21 |
8059
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
22 def test_features(): |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
23 failed = 0 |
29141
ba8999547f81
hghave: switch from iteritems to items
timeless <timeless@mozdev.org>
parents:
28283
diff
changeset
|
24 for name, feature in checks.items(): |
8059
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
25 check, _ = feature |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
26 try: |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
27 check() |
28047
863075fd4cd0
misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26068
diff
changeset
|
28 except Exception as e: |
28283
544444991c83
hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28047
diff
changeset
|
29 print("feature %s failed: %s" % (name, e)) |
8059
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
30 failed += 1 |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
31 return failed |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
32 |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
33 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 parser = optparse.OptionParser("%prog [options] [features]") |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
35 parser.add_option( |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
36 "--test-features", action="store_true", help="test available features" |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
37 ) |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
38 parser.add_option( |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
39 "--list-features", action="store_true", help="list available features" |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
40 ) |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
41 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
26068
05e7f57c74ac
hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26067
diff
changeset
|
43 def _loadaddon(): |
25732
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
44 if 'TESTDIR' in os.environ: |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
45 # loading from '.' isn't needed, because `hghave` should be |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
46 # running at TESTTMP in this case |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
47 path = os.environ['TESTDIR'] |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
48 else: |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
49 path = '.' |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
50 |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
51 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')): |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
52 return |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
53 |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
54 sys.path.insert(0, path) |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
55 try: |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
56 import hghaveaddon |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
57 |
29231
b1b35a9051c3
hghave: silence future pyflakes warning of unused import
Yuya Nishihara <yuya@tcha.org>
parents:
29161
diff
changeset
|
58 assert hghaveaddon # silence pyflakes |
28047
863075fd4cd0
misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26068
diff
changeset
|
59 except BaseException as inst: |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
60 sys.stderr.write( |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
61 'failed to import hghaveaddon.py from %r: %s\n' % (path, inst) |
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
62 ) |
25732
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
63 sys.exit(2) |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
64 sys.path.pop(0) |
b94df10cc3b5
hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22762
diff
changeset
|
65 |
43691
47ef023d0165
black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29231
diff
changeset
|
66 |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
67 if __name__ == '__main__': |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
68 options, args = parser.parse_args() |
26068
05e7f57c74ac
hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26067
diff
changeset
|
69 _loadaddon() |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
70 if options.list_features: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
71 list_features() |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
72 sys.exit(0) |
5081
ea7b982b6c08
Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5074
diff
changeset
|
73 |
8059
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
74 if options.test_features: |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
75 sys.exit(test_features()) |
41a2c5cbcb6a
hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7823
diff
changeset
|
76 |
26068
05e7f57c74ac
hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26067
diff
changeset
|
77 hghave.require(args) |