简体   繁体   English

phpunit的Vim errorformat

[英]Vim errorformat for phpunit

I'm working on a Vim compiler plugin for PHPUnit. 我正在为PHPUnit开发一个Vim编译器插件。

I've written the following errorformat . 我写了以下错误errorformat The error message is correctly extracted, but file and line numbers are not. 正确提取错误消息,但文件和行号不是。

CompilerSet errorformat=%E%n)\ %.%#,
                       \%C%m,
                       \%+C%$,
                       \%C%f:%l,
                       \%Z%$

PHPUnit's output looks something like this: PHPUnit的输出看起来像这样:

PHPUnit 3.5.12 by Sebastian Bergmann.

...............................................................  63 / 134 ( 47%)
.........................E.....

Time: 0 seconds, Memory: 11.25Mb

There was 1 error:

1) SomeClassTest::testSomething
Undefined property: SomeClass::$var

/path/to/SomeClass.php:99
/path/to/SomeClassTest.php:15

FAILURES!
Tests: 94, Assertions: 170, Errors: 1.

Press ENTER or type command to continue

I'm happy for the reported file and line to be either the first or last entry in the stack trace. 我很高兴报告的文件和行成为堆栈跟踪中的第一个或最后一个条目。 The deepest call is the actual source of the issue. 最深刻的呼吁是问题的实际来源。 Jumping to the top-level call means I can use to step down into the call stack. 跳转到顶级调用意味着我可以用来进入调用堆栈。 I would prefer the latter, SomeClassTest.php:15 in the example above. 在上面的例子中,我更喜欢后者, SomeClassTest.php:15

I think the problem is the phrasing of the %Z rule. 我认为问题在于%Z规则的措辞。 First I came up with this: 首先我想出了这个:

:set errorformat=%E%n)\ %.%#,%Z%f:%l,%C%m,%-G%.%#

That'll catch the first filename and associate that with the error message. 这将捕获第一个文件名并将其与错误消息相关联。

For some reason, association the last filename mentioned was a whole lot harder. 出于某种原因,关联提到的最后一个文件名要困难得多。 I wasn't able to do it with efm , but instead hacked together this Python filter: 我无法用efm做到这一点,而是将这个Python过滤器一起攻击:

import sys                                                                  
import re
errors = []
OTHER = 0
MESSAGE = 1
FILE_LINE = 2
next_is = OTHER
lines = sys.stdin.readlines()
for line in lines:
    line = line.strip()
    if (next_is == OTHER):
        if (re.search("^[0-9]+\)", line)):
            next_is = MESSAGE
    elif (next_is == MESSAGE):
        errors.append([line, ''])
        next_is = FILE_LINE
    elif (next_is == FILE_LINE):
        if (re.search("^.+:[0-9]+", line)):
            errors[-1][1] = line
        elif (len(line) == 0 and len(errors[-1][1]) > 0):
            next_is = OTHER

for error in errors:
    print "{0}:{1}".format(error[1], error[0])

This will capture all the errors and output them in a single-line format. 这将捕获所有错误并以单行格式输出。 The associated filename and line number are the last ones mentioned for the error. 相关的文件名和行号是错误中提到的最后一个。 This script clobbers all other output, but that'd be solved by adding eg a print line after line = line.strip() . 这个脚本破坏了所有其他输出,但是这可以通过在line = line.strip()之后添加例如print line来解决。

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

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