sapling/tests/test-fb-hgext-errorredirect.t
Jun Wu c754e0147b commands: provide in-core blackbox command
Summary:
The in-core blackbox command displays blackbox entries in the given time range.

The `blackbox` command provided by the blackbox extension was removed. They
can still be accessed via `.hg/blackbox.log`, though.

Tests are updated. Most `| grep` patterns were changed to use structured pattern
matching `--pattern` instead. Tests that are not interesting (ex. bundlebackup,
since we are moving away from bundle files slowly) are just removed.

Reviewed By: markbt

Differential Revision: D15640718

fbshipit-source-id: 7e5da60ca2b15ae9495d0242b340a066979d5a4f
2019-06-26 11:03:27 -07:00

71 lines
2.3 KiB
Perl

$ cat > $TESTTMP/crash.py << EOF
> from edenscm.mercurial import registrar
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command('crash', [])
> def crash(ui, repo):
> raise 'crash'
> EOF
$ cat >> $HGRCPATH << EOF
> [extensions]
> errorredirect=
> crash=$TESTTMP/crash.py
> mock=$TESTDIR/mockblackbox.py
> EOF
Test errorredirect will respect original behavior by default
$ hg init
$ hg crash 2>&1 | grep -o 'crashed'
crashed
Test the errorredirect script will override stack trace output
$ hg crash --config errorredirect.script='echo overridden-message'
overridden-message
[255]
If the script returns non-zero, print the trace
$ hg crash --config errorredirect.script='echo It works && exit 1' 2>&1 | grep '^[IT]'
It works
Traceback (most recent call last):
TypeError: exceptions must be old-style classes or derived from BaseException, not str
$ printf '#!%sbin/sh\necho It works && false' '/' > a.sh
$ chmod +x $TESTTMP/a.sh
$ PATH=$TESTTMP:$PATH hg crash --config errorredirect.script=a.sh 2>&1 | grep '^[IT]'
It works
Traceback (most recent call last):
TypeError: exceptions must be old-style classes or derived from BaseException, not str
If the script is terminated by SIGTERM (Ctrl+C), do not print the trace
$ hg crash --config errorredirect.script='echo It works && kill -TERM $$' 2>&1
It works
[255]
$ printf '#!%sbin/sh\necho It works && kill -TERM $$' '/' > a.sh
$ chmod +x $TESTTMP/a.sh
$ PATH=$TESTTMP:$PATH hg crash --config errorredirect.script=a.sh 2>&1
It works
[255]
If the script cannot be executed (not found in PATH), print the trace
$ hash SCRIPT-DOES-NOT-EXIST 2>/dev/null && exit 80
[1]
$ hg crash --config errorredirect.script='SCRIPT-DOES-NOT-EXIST' 2>&1 | grep '^[IT]'
Traceback (most recent call last):
TypeError: exceptions must be old-style classes or derived from BaseException, not str
Traces are logged in blackbox
$ cat >> $HGRCPATH << EOF
> [extensions]
> blackbox=
> [blackbox]
> track = command, command_exception
> logsource = 1
> EOF
$ hg crash --config errorredirect.script='echo Works'
Works
[255]
$ hg blackbox --pattern '{"legacy_log":{"service":"command_exception"}}' | head -n 1
* [legacy][command_exception] ** has crashed: (glob)