Reputation: 223
I set my makeprg
to PHPUnit
setlocal makeprg=phpunit\ --configuration\ tests/phpunit.xml
But then it's being a nightmare to try and make the errorformat work. The output of PHPUnit is this:
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
F
Time: 177 ms, Memory: 12.50MB
There was 1 failure:
1) dummy_test::testController
Failed asserting that 1 matches expected 2.
/Users/david/Sites/apr2/frontend/intranet/tests/unit/dummy_test.php:44
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
And my attempted errorformat
is: setlocal errorformat=%A%.%#,%C%n\)\ %.%#,%m,%.%#,%Z%f:%l,%-G%.%#
Which only prints lines with ||
. How should I debug this? I feel like I'm lashing out in the dark.
Upvotes: 2
Views: 722
Reputation: 3086
The main problem with your attempt is that errors are not matched the way you expect them to be. It actually goes something like this: an error line is read, and it's matched in turn against the rules in errorformat
; the first rule matching wins. Then another error line is read, and it's again matched in turn against the rules in errorformat
. And so on. There are things like %>
that can affect the order the rules are tried, and there is limited support for passing information from one rule to another, but basically, if you can't differentiate an error line from the others by matching, you can't assign it to a given field.
In particular, if you can't differentiate the line Failed asserting that 1 matches expected 2.
from Time: 177 ms, Memory: 12.50MB
, from F
, and from Tests: 1, Assertions: 1, Failures: 1.
, you can't include it in an error message. To overcome that problem you probably need to "preprocess" errors the way syntastic does, to get 1) dummy_test::testController
and Failed asserting that 1 matches expected 2.
on the same line, so that you can parse them.
Anyway, with all that in mind, here's a rudimentary framework (based on this illuminating post), and an equally crude errorformat
:
let &errorformat =
\ '%-G,' .
\ '%-GPHPUnit %.%#,' .
\ '%-GF,' .
\ '%-GTime: %.%#\, Memory: %.%#,' .
\ '%-GThere was 1 failure:,' .
\ '%-GFAILURES!,' .
\ '%-GTests: %.%#\, Assertions: %.%#\, Failures: %.%#,' .
\ '%E%n) %m,' .
\ '%C%f:%l,' .
\ '%C%m'
cgetexpr [
\ 'PHPUnit 4.8.27 by Sebastian Bergmann and contributors.',
\ '',
\ 'F',
\ '',
\ 'Time: 177 ms, Memory: 12.50MB',
\ '',
\ 'There was 1 failure:',
\ '',
\ '1) dummy_test::testController',
\ 'Failed asserting that 1 matches expected 2.',
\ '',
\ '/Users/david/Sites/apr2/frontend/intranet/tests/unit/dummy_test.php:44',
\ '',
\ 'FAILURES!',
\ 'Tests: 1, Assertions: 1, Failures: 1.',
\ ]
echomsg string(map(getqflist(), '[v:val.text, v:val.valid]'))
echomsg string(getqflist())
copen
wincmd p
The errorformat
above produces the following, which is not completely useful, but not completely useless either:
/Users/david/Sites/apr2/frontend/intranet/tests/unit/dummy_test.php|44 error 1| dummy_test::testController
Perhaps you could improve this by killing the known fixed patterns Time:...
, There was 1 failure:
etc., and then gobbling the remaining lines to the error messages. You'll still have fun dealing with empty lines though. Good luck hunting it down. :)
Edit: I changed the errorformat
to remove the known fixed patterns. You'll probably need to fiddle some more, and the result will still be fragile.
Upvotes: 4