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

"Not Package Main" error when attempting to run tests for GO module #3684

Open
lordofscripts opened this issue Feb 18, 2025 · 1 comment
Open
Milestone

Comments

@lordofscripts
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

Version: 1.97.2 (user setup) Commit: e54c774e0add60467559eb0d1e229c6452cf8447 Date: 2025-02-12T23:20:35.343Z Electron: 32.2.7 ElectronBuildId: 10982180 Chromium: 128.0.6613.186 Node.js: 20.18.1 V8: 12.8.374.38-electron.0 OS: Windows_NT x64 10.0.19045
  • Run go version to get version of Go from the VS Code integrated terminal.
    • 1.23.4 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.17.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.97.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.44.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • Tools Configuration

Environment

GOBIN: undefined
toolsGopath:
gopath: C:\Users\LoS\go
GOROOT: C:\Program Files\Go
PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Go\bin;C:\Program Files\VSCodium\bin;C:\Users\LoS\AppData\Local\Microsoft\WindowsApps;C:\Users\LoS\go\bin

Tools

go:	C:\Program Files\Go\bin\go.exe: go version go1.23.4 windows/amd64

gopls:	C:\Users\LoS\go\bin\gopls.exe	(version: v0.17.1 built with go: go1.23.4)
gotests:	not installed
gomodifytags:	not installed
impl:	not installed
goplay:	not installed
dlv:	C:\Users\LoS\go\bin\dlv.exe	(version: v1.24.0 built with go: go1.23.4)
staticcheck:	C:\Users\LoS\go\bin\staticcheck.exe	(version: v0.5.1 built with go: go1.23.4)

Go env

Workspace Folder (gocaesarx): c:\Users\LoS\go\gocaesarx

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\LoS\AppData\Local\go-build
set GOENV=C:\Users\LoS\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\LoS\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\LoS\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.4
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\LoS\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=c:\Users\LoS\go\gocaesarx\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\LoS\AppData\Local\Temp\go-build3728956750=/tmp/go-build -gno-record-gcc-switches

Describe the bug

When trying to run ANY of the tests the go.exe test command is run by the IDE and a few moments later the linker throws out an error not package main so ALL tests fail.

I know, someone will be quick to say that my tests are wrong or that they are failing. Well, no. I had this project in VSCodium prior to installing VSCode and all is fine. I have no problems running Go apps or Go tests in VSCodium once I installed the Go Extension. But on VSCode it just doesn't seem to work. I don't know what else is missing.

Steps to reproduce the behavior:

  1. Open the folder that contains the Go project module mymodule(unit tests are in the mymodule/tests folder and have package name mymodule_test
  2. Wait for the environment setup to complete
  3. Go to the Test tab on the left panel
  4. Select any test and run it

The error that appears is

BLAH BLAH BLAH: not package main
FAIL    gocaesarx/tests [build failed]
@gopherbot gopherbot added this to the Untriaged milestone Feb 18, 2025
@findleyr
Copy link
Member

@lordofscripts what happens when you copy the exact test invocation from the test output, and run it from the VS Code integrated terminal? Do you get the same error?

This doesn't seem to be a widespread problem, so is likely related to the VS Code environment or your Go install. Running in the VS Code terminal will help narrow that down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants