Skip to content

Commit 257ca10

Browse files
committed
feat: support filetests
1 parent 1d25f4a commit 257ca10

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lua/gno-nvim/gnotest.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local M = {}
1010

1111
---@class GnoTestCtx
1212
---@field is_unit? boolean
13+
---@field is_golden? boolean
1314
---@field file? string
1415
---@field testcase? string
1516
---@field label string
@@ -32,6 +33,7 @@ local function get_test_context()
3233
if is_unit or is_golden then
3334
return {
3435
is_unit = is_unit,
36+
is_golden = is_golden,
3537
file = vim.fn.fnamemodify(current_file, ":t"),
3638
label = vim.fn.fnamemodify(current_file, ":."),
3739
dir = dirname,
@@ -102,7 +104,13 @@ local function show_test_picker(ctx, gno_opts, opts)
102104
local bufnr = vim.api.nvim_get_current_buf()
103105
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
104106

105-
local options = queries.find_test_cases(bufnr, row)
107+
local options
108+
if ctx.is_unit then
109+
options = queries.find_test_cases(bufnr, row)
110+
else
111+
options = { "file/" .. ctx.file }
112+
end
113+
106114
if not options or #options == 0 then
107115
call_gnotest({
108116
label = ctx.label,
@@ -165,7 +173,7 @@ function M.run_command(opts, gno_opts)
165173
verb = { ctx.file or "." }
166174
test_label = ctx.label
167175

168-
if ctx.is_unit then
176+
if ctx.is_unit or ctx.is_golden then
169177
show_test_picker(ctx, gno_opts, opts)
170178
return
171179
end

0 commit comments

Comments
 (0)