sapling/tests/test-errorredirect.t
Jun Wu a6e1589c4f errorredirect: wrap handlecommandexception instead of sys.exit
Summary:
Since `handlecommandexception` is in core, wrap it to suppress original
crash text, instead of doing an ugly `sys.exit()`. It's much simpler and
cleaner than before. It also fixes an issue with current chg since chgserver
will print an traceback when it encounters SystemExit.

Although `logtoprocess` are doing very similar things with `errorredirect`,
it currently cannot replace `errorredirect` because we need synchronized
behavior to return the user to their shell prompt correctly. If we can get
the synchronized behavior and a way to disable builtin warning (may be tricky)
in `logtoprocess` upstream, the `errorredirect` extension could be just a thin
wrapper around `logtoprocess` using `setconfig`.

Besides, we no longer need `suppresscommandfailure` since the feature will
be either in `errorredirect` or `logtoprocess`.

Test Plan:
Run `hg crash` with `errorredirect.script` set to confirm it is compatible
with the old behavior.

Also run unittest `test-errorredirect.t`

Reviewers: #sourcecontrol, ttung, mjpieters

Reviewed By: mjpieters

Subscribers: rmcelroy, durham, lcharignon, mjpieters

Differential Revision: https://phabricator.fb.com/D3191840

Signature: t1:3191840:1461088280:77febd539c2f38a55778af3977738c045f63a0d8
2016-04-19 10:59:22 -07:00

26 lines
734 B
Perl

$ extpath=`dirname $TESTDIR`
$ cp $extpath/errorredirect.py $TESTTMP
$ cat > $TESTTMP/crash.py << EOF
> from mercurial import cmdutil
> cmdtable = {}
> command = cmdutil.command(cmdtable)
> @command('crash', [])
> def crash(ui, repo):
> raise 'crash'
> EOF
$ cat >> $HGRCPATH << EOF
> [extensions]
> errorredirect=$TESTTMP/errorredirect.py
> crash=$TESTTMP/crash.py
> EOF
Test errorredirect will respect original behavior by default
$ hg init
$ hg crash 2>&1 | grep -o 'Unknown exception encountered'
Unknown exception encountered
Test the errorredirect script will override stack trace output
$ hg crash --config errorredirect.script='echo overridden-message'
overridden-message
[255]