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 bba9bc1 commit 67a2676
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 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 @@ -117,6 +118,36 @@ local function is_windows_uname()
return os_info.sysname:lower():find("windows") ~= nil
end

local function is_macos_uname()
local os_info = vim.loop.os_uname()
return os_info.sysname:lower():find("darwin") ~= nil
end

function M.race_detection_enabled_without_cgo_enabled()
if is_macos_uname() then
-- https://tip.golang.org/doc/go1.20#cgo mentions how this is not a problem on macOS since go 1.20
return
end

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

function M.gotestsum_recommended_on_windows()
if is_windows_uname() then
if options.get().runner ~= "gotestsum" then
Expand Down

0 comments on commit 67a2676

Please sign in to comment.