简体   繁体   English

调试Vim错误格式

[英]Debugging vim errorformat

I set my makeprg to PHPUnit 我将我的makeprg设置为PHPUnit

setlocal makeprg=phpunit\\ --configuration\\ tests/phpunit.xml

But then it's being a nightmare to try and make the errorformat work. 但是,尝试使errorformat正常工作真是一场噩梦。 The output of PHPUnit is this: PHPUnit的输出是这样的:

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%.%# 我尝试的错误errorformat是: 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. 我觉得我在黑暗中猛烈抨击。

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 ; 它实际上是这样的:读取错误行,并依次与errorformat中的规则匹配; the first rule matching wins. 第一个匹配的规则获胜。 Then another error line is read, and it's again matched in turn against the rules in errorformat . 然后读取另一条错误行,并再次与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. 特别是,如果您无法区分行Failed asserting that 1 matches expected 2.则从Time: 177 ms, Memory: 12.50MB ,从F以及从Tests: 1, Assertions: 1, Failures: 1. ,您可以不要将其包含在错误消息中。 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. 为了克服这个问题,您可能需要像syntastic一样“预处理”错误,以获取1) dummy_test::testControllerFailed asserting that 1 matches expected 2.在同一行上Failed asserting that 1 matches expected 2. ,以便您可以解析它们。

Anyway, with all that in mind, here's a rudimentary framework (based on this illuminating post), and an equally crude errorformat : 无论如何,考虑到所有这些,这是一个基本框架(基于启发性文章)以及同样粗略的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: 上面的errorformat产生以下内容,这并不是完全有用,但也不是完全没用的:

/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. 也许您可以通过取消已知的固定模式Time:...解决此问题,该模式There was 1 failure: error There was 1 failure:等,然后将其余行插入错误消息。 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. 编辑:我更改了errorformat以删除已知的固定模式。 You'll probably need to fiddle some more, and the result will still be fragile. 您可能需要再摆弄一些,结果仍然很脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM