diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t --- a/tests/test-dispatch.t +++ b/tests/test-dispatch.t @@ -217,3 +217,94 @@ [1] #endif + +Test various exit codes and methods + + $ cd $TESTTMP + + $ cat >> $TESTTMP/exitmodes.py <<'EOF' + > from mercurial import pycompat, registrar, commands + > cmdtable = {} + > command = registrar.command(cmdtable) + > @command(b'exit', [], b'[MODE] [VALUE]', norepo=True) + > def exitmodes(ui, mode, value=None): + > if mode == b'returnint': + > return int(value) + > elif mode == b'returnstring': + > # sysstr is to make testing easier, since Python 2 and 3 will + > # format bytes and unicode types differently when printed. + > return pycompat.sysstr(value) + > elif mode == b'returnnone': + > return None + > elif mode == b'returnempty': + > return + > elif mode == b'systemexitint': + > raise SystemExit(int(value)) + > elif mode == b'systemexitstring': + > raise SystemExit(pycompat.sysstr(value)) + > elif mode == b'systemexitnoarg': + > raise SystemExit() + > elif mode == b'systemexitnone': + > raise SystemExit(None) + > elif mode == b'returndict': + > return {'key1': 'value1'} + > elif mode == b'systemexitdict': + > raise SystemExit({'key1': 'value1'}) + > else: + > raise Exception('unknown mode: %s' % mode) + > EOF + + $ cat >> $HGRCPATH <<'EOF' + > [extensions] + > exitmodes = $TESTTMP/exitmodes.py + > EOF + + $ hg exit returnint 42 + [42] + + $ hg exit returnstring 'some message' + Traceback (most recent call last): + File "*/hg", line *, in (glob) + dispatch.run() + File "*/mercurial/dispatch.py", line *, in run (glob) + sys.exit(status & 255) + TypeError: unsupported operand type(s) for &: 'str' and 'int' + [1] + + $ hg exit returnnone + + $ hg exit returnempty + + $ hg exit returndict + Traceback (most recent call last): + File "*/hg", line *, in (glob) + dispatch.run() + File "*/mercurial/dispatch.py", line *, in run (glob) + sys.exit(status & 255) + TypeError: unsupported operand type(s) for &: 'dict' and 'int' + [1] + + $ hg exit systemexitint 42 + [42] + + $ hg exit systemexitstring 'failure message' + Traceback (most recent call last): + File "*/hg", line *, in (glob) + dispatch.run() + File "*/mercurial/dispatch.py", line *, in run (glob) + sys.exit(status & 255) + TypeError: unsupported operand type(s) for &: 'str' and 'int' + [1] + + $ hg exit systemexitnoarg + + $ hg exit systemexitnone + + $ hg exit systemexitdict + Traceback (most recent call last): + File "*/hg", line *, in (glob) + dispatch.run() + File "*/mercurial/dispatch.py", line *, in run (glob) + sys.exit(status & 255) + TypeError: unsupported operand type(s) for &: 'dict' and 'int' + [1]