tests/test-logtoprocess.t
changeset 28901 a368da441b32
child 30976 e92daf156d5c
equal deleted inserted replaced
28900:b65966f50058 28901:a368da441b32
       
     1 Test if logtoprocess correctly captures command-related log calls.
       
     2 
       
     3   $ hg init
       
     4   $ cat > $TESTTMP/foocommand.py << EOF
       
     5   > from mercurial import cmdutil
       
     6   > from time import sleep
       
     7   > cmdtable = {}
       
     8   > command = cmdutil.command(cmdtable)
       
     9   > @command('foo', [])
       
    10   > def foo(ui, repo):
       
    11   >     ui.log('foo', 'a message: %(bar)s\n', bar='spam')
       
    12   > EOF
       
    13   $ cat >> $HGRCPATH << EOF
       
    14   > [extensions]
       
    15   > logtoprocess=
       
    16   > foocommand=$TESTTMP/foocommand.py
       
    17   > [logtoprocess]
       
    18   > command=echo 'logtoprocess command output:';
       
    19   >     echo "\$EVENT";
       
    20   >     echo "\$MSG1";
       
    21   >     echo "\$MSG2"
       
    22   > commandfinish=echo 'logtoprocess commandfinish output:';
       
    23   >     echo "\$EVENT";
       
    24   >     echo "\$MSG1";
       
    25   >     echo "\$MSG2";
       
    26   >     echo "\$MSG3"
       
    27   > foo=echo 'logtoprocess foo output:';
       
    28   >     echo "\$EVENT";
       
    29   >     echo "\$MSG1";
       
    30   >     echo "\$OPT_BAR"
       
    31   > EOF
       
    32 
       
    33 Running a command triggers both a ui.log('command') and a
       
    34 ui.log('commandfinish') call. The foo command also uses ui.log.
       
    35 
       
    36 Use head to ensure we wait for all lines to be produced, and sort to avoid
       
    37 ordering issues between the various processes we spawn:
       
    38   $ hg foo | head -n 17 | sort
       
    39   
       
    40   
       
    41   
       
    42   0
       
    43   a message: spam
       
    44   command
       
    45   commandfinish
       
    46   foo
       
    47   foo
       
    48   foo
       
    49   foo
       
    50   foo exited 0 after * seconds (glob)
       
    51   logtoprocess command output:
       
    52   logtoprocess commandfinish output:
       
    53   logtoprocess foo output:
       
    54   spam