From ab678d7f42267b0f482b8f3e4d786ab3113e798e Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 27 Jan 2023 15:06:32 +1100 Subject: [PATCH] error format for panic in null-ls go tests --- lua/go/gotest.lua | 22 +++++++++++++--------- lua/go/null_ls.lua | 4 ++-- lua/go/utils.lua | 42 +++++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lua/go/gotest.lua b/lua/go/gotest.lua index c77b731..b5dbfea 100644 --- a/lua/go/gotest.lua +++ b/lua/go/gotest.lua @@ -30,30 +30,34 @@ local short_opts = 'a:cC:t:bsFmpn:v' local bench_opts = { '-benchmem', '-cpuprofile', 'profile.out' } M.efm = function() - -- local indent = [[%\\%( %\\)]] + local indent = [[%\\%( %\\)]] local efm = [[%-G=== RUN %.%#]] - efm = efm .. [[,%-G" .. indent .. "%#--- PASS: %.%#]] + efm = efm .. [[,%-G]] .. indent .. [[%#--- PASS: %.%#]] efm = efm .. [[,%G--- FAIL: %\\%(Example%\\)%\\@=%m (%.%#)]] - efm = efm .. [[,%G" .. indent .. "%#--- FAIL: %m (%.%#)]] - efm = efm .. [[,%A" .. indent .. "%\\+%[%^:]%\\+: %f:%l: %m]] + efm = efm .. [[,%G]] .. indent .. [[%#--- FAIL: %m (%.%#)]] + efm = efm .. [[,%A]] .. indent .. [[%\\+%[%^:]%\\+: %f:%l: %m]] efm = efm .. [[,%+Gpanic: test timed out after %.%\\+]] efm = efm .. ',%+Afatal error: %.%# [recovered]' efm = efm .. [[,%+Afatal error: %.%#]] efm = efm .. [[,%+Apanic: %.%#]] - - -- exit + -- + -- -- exit efm = efm .. ',%-Cexit status %[0-9]%\\+' efm = efm .. ',exit status %[0-9]%\\+' - -- failed lines + -- -- failed lines efm = efm .. ',%-CFAIL%\\t%.%#' efm = efm .. ',FAIL%\\t%.%#' -- compiling error efm = efm .. ',%A%f:%l:%c: %m' efm = efm .. ',%A%f:%l: %m' - efm = efm .. ',%G%\\t%m' - efm = efm .. ',%-C%.%#' + efm = efm .. ',%f:%l +0x%[0-9A-Fa-f]%\\+' -- pannic with adress + efm = efm .. ',%-G%\\t%\\f%\\+:%\\d%\\+ +0x%[0-9A-Fa-f]%\\+' -- test failure, address invalid inside +-- multi-line + efm = efm .. ',%+G%\\t%m' + efm = efm .. ',%-C%.%#' -- ignore rest of unmatched lines efm = efm .. ',%-G%.%#' + efm = string.gsub(efm, ' ', [[\ ]]) -- log(efm) return efm diff --git a/lua/go/null_ls.lua b/lua/go/null_ls.lua index 325eeea..3b512c1 100644 --- a/lua/go/null_ls.lua +++ b/lua/go/null_ls.lua @@ -55,8 +55,8 @@ local function handler() -- reset output = '' elseif entry.Action == 'fail' and vim.fn.empty(output) == 0 then - log(entry) - if filename:find(fn.expand('%:t')) then -- can be output from other files + -- log(entry) + if filename and filename:find(fn.expand('%:t')) then -- can be output from other files table.insert(diags, { file = filename, row = tonumber(line), diff --git a/lua/go/utils.lua b/lua/go/utils.lua index bb3b3cf..6ee0d08 100644 --- a/lua/go/utils.lua +++ b/lua/go/utils.lua @@ -789,42 +789,49 @@ end local namepath = {} util.extract_filepath = function(msg) - msg = msg or "" - util.log(msg) + msg = msg or '' + -- util.log(msg) --[[ or [[ findAllSubStr_test.go:234: Error inserting caseResult1: operation error DynamoDB: PutItem, exceeded maximum number of attempts]] - -- or 'path/path2/filename.go:50:11: Error xxx + -- or 'path/path2/filename.go:50:11: Error invaild + -- or /home/ray/go/src/github/sample/app/driver.go:342 +0x19e5 local pos, _ = msg:find([[[%w_-%./]+%.go:%d+:]]) - if pos then - local pos2 = msg:find(":") - local s = msg:sub(1, pos2 - 1) - if vim.fn.filereadable(s) == 1 then - -- no need to extract path, already quickfix format - return - end + if not pos then + pos, _ = msg:find([[[%w_-%./]+%.go:%d+ ]]) -- test failure with panic end - - pos, _ = msg:find([[[%w_-]+_test%.go:%d+:]]) - if pos == nil then + local pos2 + if not pos then + return + end + pos2 = msg:find(':') + local s = msg:sub(1, pos2 - 1) + if vim.fn.filereadable(s) == 1 then + util.log('filename', s) + -- no need to extract path, already quickfix format + return + end + if not pos2 then + util.log('incorrect format', msg) return end - local pos2 = msg:find(":") + local pos2 = msg:find(':') local s = msg:sub(pos, pos2 - 1) + util.log(s) if namepath[s] ~= nil then return namepath[s] end if vim.fn.filereadable(s) == 1 then return end - if vim.fn.executable("find") == 0 then + if vim.fn.executable('find') == 0 then return end -- note: slow operations - local cmd = "find ./ -type f -name " .. s + local cmd = 'find ./ -type f -name ' .. s local path = vim.fn.systemlist(cmd) if vim.v.shell_error ~= 0 then - util.warn("find failed " .. cmd .. vim.inspect(path)) + util.warn('find failed ' .. cmd .. vim.inspect(path)) return end for _, value in pairs(path) do @@ -839,5 +846,6 @@ util.extract_filepath = function(msg) end end +print(util.extract_filepath([[/home/ray/go/src/github/sample/app/driver.go:342 +0x19e5]])) return util