annotate tests/test-fix-metadata.t @ 42483:a4a468b00d44

rust-filepatterns: silence warning of non_upper_case_globals
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Jun 2019 10:35:53 +0900
parents 6ed04139ed37
children 2d70b1118af2
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]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
46 > 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
47 > 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
48 > 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
49 > 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
50 > 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
51 > 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
52 > 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
53 > 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
54 > 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
55 > [hooks]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
56 > 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
57 > 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
58 > [worker]
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
59 > enabled=false
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
60 > EOF
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
61
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
62 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
63 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
64
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
65 $ 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
66 $ cd repo
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 $ 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
69 $ 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
70 $ 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
71 $ 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
72
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
73 $ 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
74 ignored invalid output from fixer tool: invalid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
75 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
76 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
77 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
78 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
79 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
80
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
81 $ cat missing invalid valid
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
82 old content
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
83 old content
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
84 new content
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
85
0da689a60163 fix: allow fixer tools to return metadata in addition to the file content
Danny Hooper <hooper@google.com>
parents:
diff changeset
86 $ cd ..