簡體   English   中英

調試Vim錯誤格式

[英]Debugging vim errorformat

我將我的makeprg設置為PHPUnit

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

但是,嘗試使errorformat正常工作真是一場噩夢。 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.

我嘗試的錯誤errorformat是: setlocal errorformat=%A%.%#,%C%n\\)\\ %.%#,%m,%.%#,%Z%f:%l,%-G%.%#

僅使用||打印行 我應該如何調試呢? 我覺得我在黑暗中猛烈抨擊。

嘗試的主要問題是錯誤與您期望的錯誤方式不匹配。 它實際上是這樣的:讀取錯誤行,並依次與errorformat中的規則匹配; 第一個匹配的規則獲勝。 然后讀取另一條錯誤行,並再次與errorformat中的規則進行匹配。 等等。 諸如%>類的東西可能會影響規則的嘗試順序,並且對將信息從一個規則傳遞到另一條規則的支持有限,但是基本上,如果您無法通過匹配將錯誤線與其他規則區分開,則可以不要將其分配給給定的字段。

特別是,如果您無法區分行Failed asserting that 1 matches expected 2.則從Time: 177 ms, Memory: 12.50MB ,從F以及從Tests: 1, Assertions: 1, Failures: 1. ,您可以不要將其包含在錯誤消息中。 為了克服這個問題,您可能需要像syntastic一樣“預處理”錯誤,以獲取1) dummy_test::testControllerFailed asserting that 1 matches expected 2.在同一行上Failed asserting that 1 matches expected 2. ,以便您可以解析它們。

無論如何,考慮到所有這些,這是一個基本框架(基於啟發性文章)以及同樣粗略的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

上面的errorformat產生以下內容,這並不是完全有用,但也不是完全沒用的:

/Users/david/Sites/apr2/frontend/intranet/tests/unit/dummy_test.php|44 error 1| dummy_test::testController

也許您可以通過取消已知的固定模式Time:...解決此問題,該模式There was 1 failure: error There was 1 failure:等,然后將其余行插入錯誤消息。 不過,您仍然會很高興處理空行。 祝你好運。 :)

編輯:我更改了errorformat以刪除已知的固定模式。 您可能需要再擺弄一些,結果仍然很脆弱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM