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(checkhealth): add check for CGO_ENABLED and -race arg #212

Merged
merged 1 commit into from
Nov 3, 2024
Merged
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
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
Loading