Skip to content

Commit

Permalink
feat(checkhealth): add check for CGO_ENABLED and -race arg
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Nov 3, 2024
1 parent 9034a4e commit 27c4115
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lua/neotest-golang/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function M.check()
M.is_plugin_available("nvim-treesitter")
M.is_plugin_available("nio")
M.is_plugin_available("plenary")
M.race_detection_enabled_without_cgo_enabled()

start("DAP (optional)")
M.binary_found_on_path("dlv")
Expand Down Expand Up @@ -148,4 +149,24 @@ function M.gotestsum_installed_but_not_used()
end
end

function M.race_detection_enabled_without_cgo_enabled()
local is_cgo_enabled = true
local env_cgo_enabled = vim.fn.getenv("CGO_ENABLED")
if env_cgo_enabled == vim.NIL or env_cgo_enabled == "0" then
is_cgo_enabled = false
end

local go_test_args = options.get().go_test_args
local has_race_detection = false
for _, value in ipairs(go_test_args) do
if value == "-race" then
has_race_detection = true
end
end

if has_race_detection and not is_cgo_enabled then
error("CGO_ENABLED is disabled but -race is part of go_test_args.")
end
end

return M

0 comments on commit 27c4115

Please sign in to comment.