test-bundle2.t
407 lines
| 10.8 KiB
| text/troff
|
Tads3Lexer
/ tests / test-bundle2.t
|
r20801 | |||
Create an extension to test bundle2 API | ||||
$ cat > bundle2.py << EOF | ||||
> """A small extension to test bundle2 implementation | ||||
> | ||||
> Current bundle2 implementation is far too limited to be used in any core | ||||
> code. We still need to be able to test it while it grow up. | ||||
> """ | ||||
> | ||||
|
r20802 | > import sys | ||
|
r20801 | > from mercurial import cmdutil | ||
|
r20813 | > from mercurial import util | ||
|
r20801 | > from mercurial import bundle2 | ||
> cmdtable = {} | ||||
> command = cmdutil.command(cmdtable) | ||||
> | ||||
|
r20876 | > ELEPHANTSSONG = """Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | ||
> Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | ||||
> Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.""" | ||||
> assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it. | ||||
> | ||||
|
r20890 | > @bundle2.parthandler('test:song') | ||
|
r20889 | > def songhandler(repo, part): | ||
> """handle a "test:song" bundle2 part, printing the lyrics on stdin""" | ||||
> repo.ui.write('The choir start singing:\n') | ||||
> for line in part.data.split('\n'): | ||||
> repo.ui.write(' %s\n' % line) | ||||
> | ||||
|
r20804 | > @command('bundle2', | ||
|
r20856 | > [('', 'param', [], 'stream level parameter'), | ||
|
r20891 | > ('', 'unknown', False, 'include an unknown mandatory part in the bundle'), | ||
|
r20856 | > ('', 'parts', False, 'include some arbitrary parts to the bundle'),], | ||
|
r20841 | > '[OUTPUTFILE]') | ||
> def cmdbundle2(ui, repo, path=None, **opts): | ||||
|
r20801 | > """write a bundle2 container on standard ouput""" | ||
|
r20842 | > bundler = bundle2.bundle20(ui) | ||
|
r20804 | > for p in opts['param']: | ||
|
r20809 | > p = p.split('=', 1) | ||
|
r20813 | > try: | ||
> bundler.addparam(*p) | ||||
> except ValueError, exc: | ||||
> raise util.Abort('%s' % exc) | ||||
|
r20809 | > | ||
|
r20856 | > if opts['parts']: | ||
> part = bundle2.part('test:empty') | ||||
> bundler.addpart(part) | ||||
> # add a second one to make sure we handle multiple parts | ||||
> part = bundle2.part('test:empty') | ||||
> bundler.addpart(part) | ||||
|
r20876 | > part = bundle2.part('test:song', data=ELEPHANTSSONG) | ||
> bundler.addpart(part) | ||||
|
r20877 | > part = bundle2.part('test:math', | ||
> [('pi', '3.14'), ('e', '2.72')], | ||||
> [('cooking', 'raw')], | ||||
> '42') | ||||
> bundler.addpart(part) | ||||
|
r20891 | > if opts['unknown']: | ||
> part = bundle2.part('test:UNKNOWN', | ||||
> data='some random content') | ||||
> bundler.addpart(part) | ||||
|
r20856 | > | ||
|
r20841 | > if path is None: | ||
> file = sys.stdout | ||||
> else: | ||||
> file = open(path, 'w') | ||||
> | ||||
|
r20804 | > for chunk in bundler.getchunks(): | ||
|
r20841 | > file.write(chunk) | ||
|
r20802 | > | ||
|
r20889 | > @command('unbundle2', [], '') | ||
> def cmdunbundle2(ui, repo): | ||||
> """process a bundle2 stream from stdin on the current repo""" | ||||
|
r20891 | > try: | ||
|
r20946 | > lock = repo.lock() | ||
|
r20892 | > try: | ||
|
r20947 | > unbundler = bundle2.unbundle20(ui, sys.stdin) | ||
> bundle2.processbundle(repo, unbundler) | ||||
|
r20892 | > except KeyError, exc: | ||
> raise util.Abort('missing support for %s' % exc) | ||||
> finally: | ||||
|
r20946 | > lock.release() | ||
|
r20892 | > remains = sys.stdin.read() | ||
> ui.write('%i unread bytes\n' % len(remains)) | ||||
|
r20889 | > | ||
|
r20888 | > @command('statbundle2', [], '') | ||
> def cmdstatbundle2(ui, repo): | ||||
> """print statistic on the bundle2 container read from stdin""" | ||||
|
r20843 | > unbundler = bundle2.unbundle20(ui, sys.stdin) | ||
|
r20844 | > try: | ||
> params = unbundler.params | ||||
> except KeyError, exc: | ||||
> raise util.Abort('unknown parameters: %s' % exc) | ||||
> ui.write('options count: %i\n' % len(params)) | ||||
> for key in sorted(params): | ||||
|
r20805 | > ui.write('- %s\n' % key) | ||
|
r20844 | > value = params[key] | ||
|
r20810 | > if value is not None: | ||
> ui.write(' %s\n' % value) | ||||
|
r20802 | > parts = list(unbundler) | ||
> ui.write('parts count: %i\n' % len(parts)) | ||||
|
r20864 | > for p in parts: | ||
> ui.write(' :%s:\n' % p.type) | ||||
|
r20877 | > ui.write(' mandatory: %i\n' % len(p.mandatoryparams)) | ||
> ui.write(' advisory: %i\n' % len(p.advisoryparams)) | ||||
|
r20876 | > ui.write(' payload: %i bytes\n' % len(p.data)) | ||
|
r20801 | > EOF | ||
$ cat >> $HGRCPATH << EOF | ||||
> [extensions] | ||||
> bundle2=$TESTTMP/bundle2.py | ||||
> EOF | ||||
The extension requires a repo (currently unused) | ||||
$ hg init main | ||||
$ cd main | ||||
|
r20803 | $ touch a | ||
$ hg add a | ||||
$ hg commit -m 'a' | ||||
|
r20801 | |||
|
r20804 | |||
Empty bundle | ||||
================= | ||||
- no option | ||||
- no parts | ||||
Test bundling | ||||
|
r20801 | |||
$ hg bundle2 | ||||
HG20\x00\x00\x00\x00 (no-eol) (esc) | ||||
|
r20802 | |||
|
r20804 | Test unbundling | ||
|
r20802 | |||
|
r20888 | $ hg bundle2 | hg statbundle2 | ||
|
r20802 | options count: 0 | ||
parts count: 0 | ||||
|
r20803 | |||
Test old style bundle are detected and refused | ||||
$ hg bundle --all ../bundle.hg | ||||
1 changesets found | ||||
|
r20888 | $ hg statbundle2 < ../bundle.hg | ||
|
r20803 | abort: unknown bundle version 10 | ||
[255] | ||||
|
r20804 | |||
Test parameters | ||||
================= | ||||
- some options | ||||
- no parts | ||||
advisory parameters, no value | ||||
------------------------------- | ||||
Simplest possible parameters form | ||||
|
r20805 | Test generation simple option | ||
|
r20804 | |||
$ hg bundle2 --param 'caution' | ||||
HG20\x00\x07caution\x00\x00 (no-eol) (esc) | ||||
|
r20805 | Test unbundling | ||
|
r20888 | $ hg bundle2 --param 'caution' | hg statbundle2 | ||
|
r20805 | options count: 1 | ||
- caution | ||||
parts count: 0 | ||||
|
r20804 | Test generation multiple option | ||
$ hg bundle2 --param 'caution' --param 'meal' | ||||
HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc) | ||||
|
r20805 | |||
Test unbundling | ||||
|
r20888 | $ hg bundle2 --param 'caution' --param 'meal' | hg statbundle2 | ||
|
r20805 | options count: 2 | ||
- caution | ||||
- meal | ||||
parts count: 0 | ||||
|
r20809 | advisory parameters, with value | ||
------------------------------- | ||||
Test generation | ||||
$ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants' | ||||
HG20\x00\x1ccaution meal=vegan elephants\x00\x00 (no-eol) (esc) | ||||
|
r20810 | Test unbundling | ||
|
r20888 | $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants' | hg statbundle2 | ||
|
r20810 | options count: 3 | ||
- caution | ||||
- elephants | ||||
- meal | ||||
vegan | ||||
parts count: 0 | ||||
|
r20811 | |||
parameter with special char in value | ||||
--------------------------------------------------- | ||||
Test generation | ||||
$ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple | ||||
HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc) | ||||
|
r20812 | |||
Test unbundling | ||||
|
r20888 | $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple | hg statbundle2 | ||
|
r20812 | options count: 2 | ||
- e|! 7/ | ||||
babar%#==tutu | ||||
- simple | ||||
parts count: 0 | ||||
|
r20813 | |||
|
r20844 | Test unknown mandatory option | ||
--------------------------------------------------- | ||||
|
r20888 | $ hg bundle2 --param 'Gravity' | hg statbundle2 | ||
|
r20844 | abort: unknown parameters: 'Gravity' | ||
[255] | ||||
|
r20841 | Test debug output | ||
--------------------------------------------------- | ||||
|
r20843 | bundling debug | ||
|
r20841 | $ hg bundle2 --debug --param 'e|! 7/=babar%#==tutu' --param simple ../out.hg2 | ||
|
r20842 | start emission of HG20 stream | ||
bundle parameter: e%7C%21%207/=babar%25%23%3D%3Dtutu simple | ||||
|
r20856 | start of parts | ||
|
r20842 | end of bundle | ||
|
r20841 | |||
file content is ok | ||||
$ cat ../out.hg2 | ||||
HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc) | ||||
|
r20843 | unbundling debug | ||
|
r20888 | $ hg statbundle2 --debug < ../out.hg2 | ||
|
r20843 | start processing of HG20 stream | ||
reading bundle2 stream parameters | ||||
|
r20844 | ignoring unknown parameter 'e|! 7/' | ||
ignoring unknown parameter 'simple' | ||||
|
r20843 | options count: 2 | ||
- e|! 7/ | ||||
babar%#==tutu | ||||
- simple | ||||
start extraction of bundle2 parts | ||||
|
r20864 | part header size: 0 | ||
|
r20843 | end of bundle2 stream | ||
parts count: 0 | ||||
|
r20813 | Test buggy input | ||
--------------------------------------------------- | ||||
empty parameter name | ||||
$ hg bundle2 --param '' --quiet | ||||
abort: empty parameter name | ||||
[255] | ||||
|
r20814 | |||
bad parameter name | ||||
$ hg bundle2 --param 42babar | ||||
abort: non letter first character: '42babar' | ||||
[255] | ||||
|
r20856 | |||
Test part | ||||
================= | ||||
$ hg bundle2 --parts ../parts.hg2 --debug | ||||
start emission of HG20 stream | ||||
bundle parameter: | ||||
start of parts | ||||
bundle part: "test:empty" | ||||
bundle part: "test:empty" | ||||
|
r20876 | bundle part: "test:song" | ||
|
r20877 | bundle part: "test:math" | ||
|
r20856 | end of bundle | ||
$ cat ../parts.hg2 | ||||
HG20\x00\x00\x00\r (esc) | ||||
test:empty\x00\x00\x00\x00\x00\x00\x00\r (esc) | ||||
|
r20876 | test:empty\x00\x00\x00\x00\x00\x00\x00\x0c test:song\x00\x00\x00\x00\x00\xb2Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko (esc) | ||
Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | ||||
|
r20877 | Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.\x00\x00\x00\x00\x00' test:math\x02\x01\x02\x04\x01\x04\x07\x03pi3.14e2.72cookingraw\x00\x00\x00\x0242\x00\x00\x00\x00\x00\x00 (no-eol) (esc) | ||
|
r20856 | |||
|
r20888 | $ hg statbundle2 < ../parts.hg2 | ||
|
r20864 | options count: 0 | ||
|
r20877 | parts count: 4 | ||
|
r20876 | :test:empty: | ||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 0 bytes | ||
|
r20864 | :test:empty: | ||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 0 bytes | ||
:test:song: | ||||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 178 bytes | ||
|
r20877 | :test:math: | ||
mandatory: 2 | ||||
advisory: 1 | ||||
payload: 2 bytes | ||||
|
r20864 | |||
|
r20888 | $ hg statbundle2 --debug < ../parts.hg2 | ||
|
r20864 | start processing of HG20 stream | ||
reading bundle2 stream parameters | ||||
options count: 0 | ||||
start extraction of bundle2 parts | ||||
part header size: 13 | ||||
part type: "test:empty" | ||||
part parameters: 0 | ||||
payload chunk size: 0 | ||||
part header size: 13 | ||||
part type: "test:empty" | ||||
part parameters: 0 | ||||
payload chunk size: 0 | ||||
|
r20876 | part header size: 12 | ||
part type: "test:song" | ||||
part parameters: 0 | ||||
payload chunk size: 178 | ||||
payload chunk size: 0 | ||||
|
r20877 | part header size: 39 | ||
part type: "test:math" | ||||
part parameters: 3 | ||||
payload chunk size: 2 | ||||
payload chunk size: 0 | ||||
|
r20864 | part header size: 0 | ||
end of bundle2 stream | ||||
|
r20877 | parts count: 4 | ||
|
r20876 | :test:empty: | ||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 0 bytes | ||
|
r20864 | :test:empty: | ||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 0 bytes | ||
:test:song: | ||||
|
r20877 | mandatory: 0 | ||
advisory: 0 | ||||
|
r20876 | payload: 178 bytes | ||
|
r20877 | :test:math: | ||
mandatory: 2 | ||||
advisory: 1 | ||||
payload: 2 bytes | ||||
|
r20889 | |||
Test actual unbundling | ||||
======================== | ||||
Process the bundle | ||||
$ hg unbundle2 --debug < ../parts.hg2 | ||||
start processing of HG20 stream | ||||
reading bundle2 stream parameters | ||||
start extraction of bundle2 parts | ||||
part header size: 13 | ||||
part type: "test:empty" | ||||
part parameters: 0 | ||||
payload chunk size: 0 | ||||
ignoring unknown advisory part 'test:empty' | ||||
part header size: 13 | ||||
part type: "test:empty" | ||||
part parameters: 0 | ||||
payload chunk size: 0 | ||||
ignoring unknown advisory part 'test:empty' | ||||
part header size: 12 | ||||
part type: "test:song" | ||||
part parameters: 0 | ||||
payload chunk size: 178 | ||||
payload chunk size: 0 | ||||
found an handler for part 'test:song' | ||||
The choir start singing: | ||||
Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | ||||
Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | ||||
Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. | ||||
part header size: 39 | ||||
part type: "test:math" | ||||
part parameters: 3 | ||||
payload chunk size: 2 | ||||
payload chunk size: 0 | ||||
ignoring unknown advisory part 'test:math' | ||||
part header size: 0 | ||||
end of bundle2 stream | ||||
|
r20892 | 0 unread bytes | ||
|
r20891 | |||
$ hg bundle2 --parts --unknown ../unknown.hg2 | ||||
$ hg unbundle2 < ../unknown.hg2 | ||||
The choir start singing: | ||||
Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko | ||||
Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko | ||||
Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko. | ||||
|
r20892 | 0 unread bytes | ||
|
r20891 | abort: missing support for 'test:unknown' | ||
[255] | ||||