awslabs / ar-go-tools

ar-go-tools (Argot) is a collection of analysis tools for Go
Apache License 2.0
9 stars 1 forks source link

Tests fail in macOS Terminal.app but pass in GoLand #67

Closed samarth-aws closed 4 months ago

samarth-aws commented 4 months ago

make test fails on my machine when I run it in the terminal app but passes when I run it in the GoLand terminal.

Comparing go env

go env output in GoLand:

❯ /opt/homebrew/opt/go/libexec/bin/go env 
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/samarkis/Library/Caches/go-build'
GOENV='/Users/samarkis/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/samarkis/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/samarkis/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Volumes/workplace/argot/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9h/q3bs2z813ybdjn_1595ncv5r0000gr/T/go-build354285742=/tmp/go-build -gno-record-gcc-switches -fno-common'

go env output in Terminal:

❯ /opt/homebrew/opt/go/libexec/bin/go env                                                  
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/samarkis/Library/Caches/go-build'
GOENV='/Users/samarkis/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/samarkis/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/samarkis/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/samarkis/workplace/argot/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9h/q3bs2z813ybdjn_1595ncv5r0000gr/T/go-build2914932166=/tmp/go-build -gno-record-gcc-switches -fno-common'

Results

The main difference here is the GOMOD variable ("Volumes/workplace/argot/go.mod" vs "/Users/samarkis/workplace/argot/go.mod"). However, it cannot be modified:

❯ go env -w GOMOD=/Volumes/workplace/argot/go.mod 
go: GOMOD cannot be modified

The issue is that /Volumes/workplace is a symlink to /Users/samarkis/workplace. When doing string comparisons of filenames in tests, the difference in directory names causes the tests to fail.

The fix

Evaluating the symlinks when parsing directory paths should fix the tests.