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

x/playground: func Test doesn't work in module mode: function main is undeclared #66451

Closed
dolmen opened this issue Mar 21, 2024 · 4 comments
Closed
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dolmen
Copy link
Contributor

dolmen commented Mar 21, 2024

func Test(*testing.T) is not executed on https://go.dev/play when a go.mod file is provided.

What did you do?

This doesn't run: https://go.dev/play/p/ZDFf4aGucoB

package main

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test(t *testing.T) {
	assert.True(t, true)
}
-- go.mod --
module play.ground

require github.com/stretchr/testify v1.9.0

What did you see happen?

Output:

go: downloading github.com/stretchr/testify v1.9.0
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.1
# play.ground
runtime.main_main·f: function main is undeclared in the main package

What did you expect to see?

If I remove the go.mod, it runs correctly.

Example: https://go.dev/play/p/AsRNcxCRdWx

=== RUN   Test
--- PASS: Test (0.00s)
PASS
@gopherbot gopherbot added this to the Unreleased milestone Mar 21, 2024
@dolmen dolmen changed the title x/playground: Test function doesn't work in module mode: function main is undeclared x/playground: func Test doesn't work in module mode: function main is undeclared Mar 21, 2024
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 25, 2024
@dr2chase
Copy link
Contributor

I am not sure this is a bug, there is in fact no main function in the main package.
Not-module-mode is now a special case, at least as I understand it.

@rsc (for go/build) and @golang/tools-team (for the playground).

@dolmen
Copy link
Contributor Author

dolmen commented Mar 26, 2024

Reproducible builds on the Go playground (enforced by locking dependencies with go.mod) are an important feature (even if still underused) to help bug reporters to demonstrate issues. A func(*testing.T) is a good way to convey that as the code provided can easily be integrated in a test suite.

This may not qualify as "bug" but "feature request" or "proposal", but I argue it is an important feature for the Go community.

@matloob
Copy link
Contributor

matloob commented Jun 11, 2024

On the bottom of go.dev/play it says

If the program contains tests or examples and no main function, the service runs the tests.

It sounds like we should either support this or update that text to make it clear it's not supported in module mode?

On the issue of reproducibility, it's harder to guarantee that what's on the playground is reproducible. The playground runs the build with -mod=mod which will pull in dependencies that are missing from an untidy go.mod and will set the module's go version (which controls language semantics) to the version of the go command that's running.

@seankhliao
Copy link
Member

Duplicate of #32403

@seankhliao seankhliao marked this as a duplicate of #32403 Jul 7, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants