| 1 |
#require no-windows |
| 2 |
|
| 3 |
ATTENTION: logtoprocess runs commands asynchronously. Be sure to append "| cat" |
| 4 |
to hg commands, to wait for the output, if you want to test its output. |
| 5 |
Otherwise the test will be flaky. |
| 6 |
|
| 7 |
Test if logtoprocess correctly captures command-related log calls. |
| 8 |
|
| 9 |
$ hg init |
| 10 |
$ cat > $TESTTMP/foocommand.py << EOF |
| 11 |
> from mercurial import registrar |
| 12 |
> cmdtable = {} |
| 13 |
> command = registrar.command(cmdtable) |
| 14 |
> configtable = {} |
| 15 |
> configitem = registrar.configitem(configtable) |
| 16 |
> configitem(b'logtoprocess', b'foo', |
| 17 |
> default=None, |
| 18 |
> ) |
| 19 |
> @command(b'foobar', []) |
| 20 |
> def foo(ui, repo): |
| 21 |
> ui.log(b'foo', b'a message: %s\n', b'spam') |
| 22 |
> EOF |
| 23 |
$ cp $HGRCPATH $HGRCPATH.bak |
| 24 |
$ cat >> $HGRCPATH << EOF |
| 25 |
> [extensions] |
| 26 |
> logtoprocess= |
| 27 |
> foocommand=$TESTTMP/foocommand.py |
| 28 |
> [logtoprocess] |
| 29 |
> command=(echo 'logtoprocess command output:'; |
| 30 |
> echo "\$EVENT"; |
| 31 |
> echo "\$MSG1") > $TESTTMP/command.log |
| 32 |
> commandfinish=(echo 'logtoprocess commandfinish output:'; |
| 33 |
> echo "\$EVENT"; |
| 34 |
> echo "\$MSG1"; |
| 35 |
> echo "canonical: \$OPT_CANONICAL_COMMAND") > $TESTTMP/commandfinish.log |
| 36 |
> foo=(echo 'logtoprocess foo output:'; |
| 37 |
> echo "\$EVENT"; |
| 38 |
> echo "\$MSG1") > $TESTTMP/foo.log |
| 39 |
> EOF |
| 40 |
|
| 41 |
Running a command triggers both a ui.log('command') and a |
| 42 |
ui.log('commandfinish') call. The foo command also uses ui.log. |
| 43 |
|
| 44 |
Use sort to avoid ordering issues between the various processes we spawn: |
| 45 |
$ hg fooba |
| 46 |
$ sleep 1 |
| 47 |
$ cat $TESTTMP/command.log | sort |
| 48 |
|
| 49 |
command |
| 50 |
fooba |
| 51 |
logtoprocess command output: |
| 52 |
|
| 53 |
#if no-chg |
| 54 |
$ cat $TESTTMP/commandfinish.log | sort |
| 55 |
|
| 56 |
canonical: foobar |
| 57 |
commandfinish |
| 58 |
fooba exited 0 after * seconds (glob) |
| 59 |
logtoprocess commandfinish output: |
| 60 |
$ cat $TESTTMP/foo.log | sort |
| 61 |
|
| 62 |
a message: spam |
| 63 |
foo |
| 64 |
logtoprocess foo output: |
| 65 |
#endif |
| 66 |
|
| 67 |
Confirm that logging blocked time catches stdio properly: |
| 68 |
$ cp $HGRCPATH.bak $HGRCPATH |
| 69 |
$ cat >> $HGRCPATH << EOF |
| 70 |
> [extensions] |
| 71 |
> logtoprocess= |
| 72 |
> pager= |
| 73 |
> [logtoprocess] |
| 74 |
> uiblocked=echo "\$EVENT stdio \$OPT_STDIO_BLOCKED ms command \$OPT_COMMAND_DURATION ms" > $TESTTMP/uiblocked.log |
| 75 |
> [ui] |
| 76 |
> logblockedtimes=True |
| 77 |
> EOF |
| 78 |
|
| 79 |
$ hg log |
| 80 |
$ sleep 1 |
| 81 |
$ cat $TESTTMP/uiblocked.log |
| 82 |
uiblocked stdio [0-9]+.[0-9]* ms command [0-9]+.[0-9]* ms (re) |
| 83 |
|
| 84 |
Try to confirm that pager wait on logtoprocess: |
| 85 |
|
| 86 |
Add a script that waits on a file to appear. If the script is awaited by hg, |
| 87 |
the script will die after the timeout before we could touch the file and the |
| 88 |
resulting file will not exist. If not, we will touch the file and see it. |
| 89 |
|
| 90 |
$ cat >> fakepager.py <<EOF |
| 91 |
> import sys |
| 92 |
> printed = False |
| 93 |
> for line in sys.stdin: |
| 94 |
> sys.stdout.write(line) |
| 95 |
> printed = True |
| 96 |
> if not printed: |
| 97 |
> sys.stdout.write('paged empty output!\n') |
| 98 |
> EOF |
| 99 |
|
| 100 |
$ cat > $TESTTMP/wait-output.sh << EOF |
| 101 |
> #!/bin/sh |
| 102 |
> set -eu |
| 103 |
> "$RUNTESTDIR/testlib/wait-on-file" 10 "$TESTTMP/wait-for-touched" |
| 104 |
> touch "$TESTTMP/touched" |
| 105 |
> EOF |
| 106 |
$ chmod +x $TESTTMP/wait-output.sh |
| 107 |
|
| 108 |
$ cat >> $HGRCPATH << EOF |
| 109 |
> [extensions] |
| 110 |
> logtoprocess= |
| 111 |
> pager= |
| 112 |
> [pager] |
| 113 |
> pager = "$PYTHON" $TESTTMP/fakepager.py |
| 114 |
> [logtoprocess] |
| 115 |
> commandfinish=$TESTTMP/wait-output.sh |
| 116 |
> EOF |
| 117 |
$ hg version -q --pager=always |
| 118 |
Mercurial Distributed SCM (version *) (glob) |
| 119 |
$ touch $TESTTMP/wait-for-touched |
| 120 |
$ "$RUNTESTDIR/testlib/wait-on-file" 5 "$TESTTMP/touched" |
| 121 |
$ test -f $TESTTMP/touched && echo "SUCCESS Pager is not waiting on ltp" || echo "FAIL Pager is waiting on ltp" |
| 122 |
SUCCESS Pager is not waiting on ltp |