Mercurial > hg
annotate tests/test-revlog.t @ 40093:726cfc47f17a
contrib: add an utility module to parse test scripts
This patch centralizes the logic to pick up code fragments embedded in
*.t script, in order to:
- apply checking with patterns in check-code.py on such embedded
code fragments
Now, check-code.py completely ignores embedded code
fragments. I'll post another patch series to check them.
- replace similar code path in contrib/import-checker.py
Current import-checker.py has problems below. Fixing each of them
is a little difficult, because parsing logic and pattern strings
are tightly coupled.
- overlook (or mis-detect) the end of inline script in doctest
style
8a8dd6e4a97a fixed a part of this issue, but not enough.
- it overlooks inline script in doctest style at the end of file
(and ignores invalid un-closed heredoc at the end of file, too)
- it overlooks code fragment in styles below
- "python <<EOF" (heredoc should be "cat > file <<EOF" style)
- "cat > foobar.py << ANYLIMIT" (limit mark should be "EOF")
- "cat << EOF > foobar.py" (filename should be placed before limit mark)
- "cat >> foobar.py << EOF" (appending is ignored)
- it is not extensible for other than python code fragments
(e.g. shell script, hgrc file, and so on)
This new module can detect python code fragments in styles below:
- inline script in doctest style (starting by " >>> " line)
- python invocation with heredoc script ("python <<EOF")
- python script in heredoc style (redirected into ".py" file)
As an example of extensibility of new module, this patch also contains
implementation to pick up code fragment below. This will be useful to
add additional restriction for them, for example.
- shell script in heredoc style (redirected into ".sh" file)
- hgrc configuration in heredoc style (redirected into hgrc or $HGRCPATH)
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Thu, 23 Aug 2018 12:25:54 +0900 |
parents | 803b7569c9ea |
children | 29b0e9cd02f4 |
rev | line source |
---|---|
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
1 $ hg init empty-repo |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
2 $ cd empty-repo |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
3 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
4 Flags on revlog version 0 are rejected |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
5 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
6 >>> with open('.hg/store/00changelog.i', 'wb') as fh: |
38080
0a10f142299d
py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37283
diff
changeset
|
7 ... fh.write(b'\x00\x01\x00\x00') and None |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
8 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
9 $ hg log |
32392
36d3559c69a6
revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32391
diff
changeset
|
10 abort: unknown flags (0x01) in version 0 revlog 00changelog.i! |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
11 [255] |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
12 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
13 Unknown flags on revlog version 1 are rejected |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
14 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
15 >>> with open('.hg/store/00changelog.i', 'wb') as fh: |
38080
0a10f142299d
py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37283
diff
changeset
|
16 ... fh.write(b'\x00\x04\x00\x01') and None |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
17 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
18 $ hg log |
32392
36d3559c69a6
revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32391
diff
changeset
|
19 abort: unknown flags (0x04) in version 1 revlog 00changelog.i! |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
20 [255] |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
21 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
22 Unknown version is rejected |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
23 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
24 >>> with open('.hg/store/00changelog.i', 'wb') as fh: |
38080
0a10f142299d
py3: suppress the output from .write() calls in few tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
37283
diff
changeset
|
25 ... fh.write(b'\x00\x00\x00\x02') and None |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
26 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
27 $ hg log |
32392
36d3559c69a6
revlog: tweak wording and logic for flags validation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32391
diff
changeset
|
28 abort: unknown version (2) in revlog 00changelog.i! |
32391
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
29 [255] |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
30 |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
31 $ cd .. |
3ea1f1e71a0a
tests: tests for revlog version and flags loading
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32371
diff
changeset
|
32 |
28656
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 Test for CVE-2016-3630 |
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
34 |
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
35 $ hg init |
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
36 |
36484
71d1bbf1617e
py3: add b'' prefixes in tests/test-revlog.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32392
diff
changeset
|
37 >>> open("a.i", "wb").write( |
71d1bbf1617e
py3: add b'' prefixes in tests/test-revlog.t
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32392
diff
changeset
|
38 ... b"""eJxjYGZgZIAAYQYGxhgom+k/FMx8YKx9ZUaKSOyqo4cnuKb8mbqHV5cBCVTMWb1Cwqkhe4Gsg9AD |
28656
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
39 ... Joa3dYtcYYYBAQ8Qr4OqZAYRICPTSr5WKd/42rV36d+8/VmrNpv7NP1jQAXrQE4BqQUARngwVA==""" |
39903
803b7569c9ea
py3: suppress the output from .write() calls in the remaining tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
39282
diff
changeset
|
40 ... .decode("base64").decode("zlib")) and None |
28656
b6ed2505d6cf
parsers: fix list sizing rounding error (SEC)
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
41 |
39282
828a45233036
debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39280
diff
changeset
|
42 $ hg debugrevlogindex a.i |
37283
d4e62df1c73d
debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37282
diff
changeset
|
43 rev linkrev nodeid p1 p2 |
d4e62df1c73d
debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37282
diff
changeset
|
44 0 2 99e0332bd498 000000000000 000000000000 |
d4e62df1c73d
debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37282
diff
changeset
|
45 1 3 6674f57a23d8 99e0332bd498 000000000000 |
39280
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
46 |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
47 >>> from mercurial import revlog, vfs |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
48 >>> tvfs = vfs.vfs(b'.') |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
49 >>> tvfs.options = {b'revlogv1': True} |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
50 >>> rl = revlog.revlog(tvfs, b'a.i') |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
51 >>> rl.revision(1) |
da459d426c20
tests: use inline Python for revlog test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38080
diff
changeset
|
52 mpatchError('patch cannot be decoded',) |