Skip to content

Commit

Permalink
Fix crash on empty stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
quolpr committed Jan 15, 2025
1 parent 21df661 commit adae37a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
28 changes: 14 additions & 14 deletions lua/quicktest/colored_printer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ end
function ColoredPrinter:setup_highlight_groups()
local basic_colors = {
["30"] = "Black",
["31"] = "Red",
["32"] = "Green",
["33"] = "Yellow",
["34"] = "Blue",
["35"] = "Magenta",
["36"] = "Cyan",
["37"] = "White",
["90"] = "Grey",
["91"] = "Red",
["92"] = "Green",
["93"] = "Yellow",
["94"] = "Blue",
["95"] = "Magenta",
["96"] = "Cyan",
["31"] = "DarkRed",
["32"] = "DarkGreen",
["33"] = "DarkYellow",
["34"] = "DarkBlue",
["35"] = "DarkMagenta",
["36"] = "DarkCyan",
["37"] = "LightGrey",
["90"] = "DarkGrey",
["91"] = "LightRed",
["92"] = "LightGreen",
["93"] = "LightYellow",
["94"] = "LightBlue",
["95"] = "LightMagenta",
["96"] = "LightCyan",
["97"] = "White",
}

Expand Down
31 changes: 21 additions & 10 deletions lua/quicktest/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ function M.run(adapter, params, config, opts)
ui.scroll_down(buf)
end

---@diagnostic disable-next-line: missing-parameter
a.run(function()
local runLoop = function()
local sender, receiver = a.control.channel.mpsc()
local pid = adapter.run(params, function(data)
sender.send(data)
Expand Down Expand Up @@ -236,16 +235,18 @@ function M.run(adapter, params, config, opts)
end

if result.type == "stderr" then
local line_count = vim.api.nvim_buf_line_count(buf)
local lines = vim.split(result.output, "\n")
if result.output then
local line_count = vim.api.nvim_buf_line_count(buf)
local lines = vim.split(result.output, "\n")

table.insert(lines, "")
table.insert(lines, "")
if #lines > 0 then
set_ansi_lines(buf, line_count - 2, -1, false, lines)
table.insert(lines, "")
table.insert(lines, "")
if #lines > 0 then
set_ansi_lines(buf, line_count - 2, -1, false, lines)

for i = 0, #lines - 1 do
vim.api.nvim_buf_add_highlight(buf, -1, "DiagnosticError", line_count - 2 + i, 0, -1)
for i = 0, #lines - 1 do
vim.api.nvim_buf_add_highlight(buf, -1, "DiagnosticError", line_count - 2 + i, 0, -1)
end
end
end
end
Expand All @@ -257,6 +258,16 @@ function M.run(adapter, params, config, opts)

print_status()
end
end

---@diagnostic disable-next-line: missing-parameter
a.run(function()
xpcall(runLoop, function(err)
print("Error in async job:", err)
print("Stack trace:", debug.traceback())

notify.error("Test run failed: " .. err)
end)
end)
end

Expand Down
3 changes: 0 additions & 3 deletions plugin/quicktest.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
-- vim.api.nvim_create_user_command("C", function()
-- require("lazy.core.loader").reload("quicktest.nvim")
--
-- -- require("quicktest").open_win("popup")
-- -- local module = require("quicktest.module")
-- --
-- -- module.run(require("quicktest.adapters.golang"), {
-- -- func_names = { "TestSum" },
-- -- sub_func_names = {},
Expand Down
4 changes: 2 additions & 2 deletions tests/support/gotest/abc/abc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package abc_test

import (
"fmt"
"gotest/abc"
"math"
"os"
"testing"
"time"

"gotest/abc"
)

func TestSum(t *testing.T) {
Expand All @@ -28,7 +29,6 @@ func TestSum(t *testing.T) {
if c != a+b+1 {
t.Errorf("Sum(%d, %d) = %d, want %d", a, b, c, a+b)
}

}

func TestGradient(t *testing.T) {
Expand Down

0 comments on commit adae37a

Please sign in to comment.