Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use --run flag when executing single test #1

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/neotest-go/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ function adapter.build_spec(args)
if fn.isdirectory(position.path) ~= 1 then
location = fn.fnamemodify(position.path, ":h")
end

local run_flag = {}
if position.type == "test" then
run_flag = { "--run", "\\^" .. utils.get_prefix(args.tree, position.name) .. "\\$" }
end

local command = vim.tbl_flatten({
"cd",
location,
Expand All @@ -171,8 +177,10 @@ function adapter.build_spec(args)
"-json",
utils.get_build_tags(),
vim.list_extend(get_args(), args.extra_args or {}),
run_flag,
dir,
})

return {
command = table.concat(command, " "),
context = {
Expand Down
14 changes: 14 additions & 0 deletions lua/spec/neotest-go/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ describe("build_spec", function()
assert.are.same(expected_command, result.command)
assert.are.same(path, result.context.file)
end)
async.it("build specification for single test", function()
local path = vim.loop.cwd() .. "/neotest_go/main_test.go"
local tree = plugin.discover_positions(path):children()[1]

local args = { tree = tree }
local expected_command = "cd "
.. vim.loop.cwd()
.. "/neotest_go && go test -v -json -count=1 -timeout=60s --run \\^TestAddOne\\$ ./"
local result = plugin.build_spec(args)
assert.are.same(expected_command, result.command)
assert.are.same(path, result.context.file)
end)

-- This test is overwriting plugin global state, keep it at end of the file or face the consequences ¯\_(ツ)_/¯
async.it("build specification for many_table_test.go recuresive run", function()
local plugin_with_recursive_run = require("neotest-go")({ recursive_run = true })
local path = vim.loop.cwd() .. "/neotest_go/many_table_test.go"
Expand Down