sapling/tests/test-errorredirect.t
Jun Wu 95b5e7d167 errorredirect: pipe error message to a custom script
Summary:
In case of crash, instead of printing an ugly stack trace, we want to
paste the message to some pastebin-like places. This extension allows
us to do so.

Test Plan:
1. Add `raise 1` to a random hg command, for example, `hg status`
2. Modify `~/.hgrc`:
```
[errorredirect]
script = (echo HEADER; cat; echo FOOTER) | cat > /tmp/a && echo '/tmp/a written'
```
3. Run `hg status` and confirm the shell script works and no stack trace is printed

Also, run `test-errorredirect.t`

Reviewers: rmcelroy, #sourcecontrol, ttung

Reviewed By: ttung

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

Tasks: 9259456

Signature: t1:2715697:1449173573:7a5abdb3cf3087128bdf688a596d97bb13f27783
2015-12-03 15:03:07 -08:00

26 lines
731 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 overrided-message'
overrided-message
[1]