annotate tests/test-fix-metadata.t @ 46067:cc0b332ab9fc

run-tests: stuff a `python3.exe` into the test bin directory on Windows Windows doesn't have `python3.exe` as part of the python.org distribution, and that broke every script with a shebang after c102b704edb5. Windows itself provides a `python3.exe` app execution alias[1], but it is some sort of reparse point that MSYS is incapable of handling[2]. When run by MSYS, it simply prints $ python3 -V - Cannot open That in turn caused every `hghave` check, and test that invokes shebang scripts directly, to fail. Rather than try to patch up every script call to be invoked with `$PYTHON` (and regress when non Windows developers forget), copying the executable into the test binary directory with the new name just works. Since this directory is prepended to the system PATH value, it also overrides the broken execution alias. (The `_tmpbindir` is used instead of `_bindir` because the latter causes python3.exe to be copied into the repo next to hg.exe when `test-run-tests.t` runs. Something runs with this version of the executable and subsequent runs of `run-tests.py` inside `test-run-tests.t` try to copy over it while it is in use, and fail. This avoids the failures and the clutter.) I didn't conditionalize this on py3 because `python3.exe` needs to be present (for the shebangs) even when running py2 tests. It shouldn't matter to these simple scripts, and I think the intention is to make the test runner use py3 always, even if testing a py2 build. For now, still supporting py2 is helping to clean up the mess that is py3 tests. [1] https://stackoverflow.com/a/57168165 [2] https://stackoverflow.com/questions/59148628/solved-unable-to-run-python-3-7-on-windows-10-permission-denied#comment104524397_59148666 Differential Revision: https://phab.mercurial-scm.org/D9543
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 07 Dec 2020 16:18:28 -0500
parents 2d70b1118af2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
1 A python hook for "hg fix" that prints out the number of files and revisions
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
2 that were affected, along with which fixer tools were applied. Also checks how
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
3 many times it sees a specific key generated by one of the fixer tools defined
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
4 below.
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
5
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
6 $ cat >> $TESTTMP/postfixhook.py <<EOF
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
7 > import collections
42429
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
8 > def file(ui, repo, rev=None, path=b'', metadata=None, **kwargs):
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
9 > ui.status(b'fixed %s in revision %d using %s\n' %
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
10 > (path, rev, b', '.join(metadata.keys())))
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
11 > def summarize(ui, repo, replacements=None, wdirwritten=False,
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
12 > metadata=None, **kwargs):
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
13 > counts = collections.defaultdict(int)
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
14 > keys = 0
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
15 > for fixername, metadatalist in metadata.items():
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
16 > for metadata in metadatalist:
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
17 > if metadata is None:
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
18 > continue
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
19 > counts[fixername] += 1
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
20 > if 'key' in metadata:
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
21 > keys += 1
42429
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
22 > ui.status(b'saw "key" %d times\n' % (keys,))
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
23 > for name, count in sorted(counts.items()):
42429
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
24 > ui.status(b'fixed %d files with %s\n' % (count, name))
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
25 > if replacements:
42429
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
26 > ui.status(b'fixed %d revisions\n' % (len(replacements),))
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
27 > if wdirwritten:
42429
6ed04139ed37 py3: fix test-fix-metadata.t
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42194
diff changeset
28 > ui.status(b'fixed the working copy\n')
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
29 > EOF
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
30
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
31 Some mock output for fixer tools that demonstrate what could go wrong with
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
32 expecting the metadata output format.
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
33
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
34 $ printf 'new content\n' > $TESTTMP/missing
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
35 $ printf 'not valid json\0new content\n' > $TESTTMP/invalid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
36 $ printf '{"key": "value"}\0new content\n' > $TESTTMP/valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
37
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
38 Configure some fixer tools based on the output defined above, and enable the
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
39 hooks defined above. Disable parallelism to make output of the parallel file
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
40 processing phase stable.
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
41
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
42 $ cat >> $HGRCPATH <<EOF
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
43 > [extensions]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
44 > fix =
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
45 > [fix]
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
46 > metadatafalse:command=cat $TESTTMP/missing
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
47 > metadatafalse:pattern=metadatafalse
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
48 > metadatafalse:metadata=false
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
49 > missing:command=cat $TESTTMP/missing
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
50 > missing:pattern=missing
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
51 > missing:metadata=true
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
52 > invalid:command=cat $TESTTMP/invalid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
53 > invalid:pattern=invalid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
54 > invalid:metadata=true
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
55 > valid:command=cat $TESTTMP/valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
56 > valid:pattern=valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
57 > valid:metadata=true
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
58 > [hooks]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
59 > postfixfile = python:$TESTTMP/postfixhook.py:file
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
60 > postfix = python:$TESTTMP/postfixhook.py:summarize
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
61 > [worker]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
62 > enabled=false
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
63 > EOF
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
64
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
65 See what happens when we execute each of the fixer tools. Some print warnings,
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
66 some write back to the file.
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
67
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
68 $ hg init repo
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
69 $ cd repo
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
70
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
71 $ printf "old content\n" > metadatafalse
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
72 $ printf "old content\n" > invalid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
73 $ printf "old content\n" > missing
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
74 $ printf "old content\n" > valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
75 $ hg add -q
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
76
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
77 $ hg fix -w
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
78 ignored invalid output from fixer tool: invalid
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
79 fixed metadatafalse in revision 2147483647 using metadatafalse
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
80 ignored invalid output from fixer tool: missing
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
81 fixed valid in revision 2147483647 using valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
82 saw "key" 1 times
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
83 fixed 1 files with valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
84 fixed the working copy
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
85
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
86 $ cat metadatafalse
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
87 new content
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
88 $ cat missing
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
89 old content
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
90 $ cat invalid
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
91 old content
42757
2d70b1118af2 fix: correctly parse the :metadata subconfig
Danny Hooper <hooper@google.com>
parents: 42429
diff changeset
92 $ cat valid
42194
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
93 new content
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
94
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
95 $ cd ..