Skip to content

x/website/_content/doc/tutorial: go vet flags tutorial code for non-constant format string #73845

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

Closed
FelixDobler opened this issue May 23, 2025 · 4 comments
Labels
Documentation Issues describing a change to documentation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. website
Milestone

Comments

@FelixDobler
Copy link

What is the URL of the page with the issue?

https://go.dev/doc/tutorial/add-a-test

What is your user agent?

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0

Screenshot

Image

What did you do?

Follow the steps in the tutorial.

What did you expect to see?

I expected to see the same command output for go test in the tutorial as on my local machine when executing the command.

What did you see instead?

For step 5, the outputs don't match. It seems like go now does advanced code checking and already detects a static issue without running the actual test.

Tutorial Output

$ go test
--- FAIL: TestHelloName (0.00s)
    greetings_test.go:15: Hello("Gladys") = "Hail, %v! Well met!", <nil>, want match for `\bGladys\b`, nil
FAIL
exit status 1
FAIL    example.com/greetings   0.182s

Local Output

using go version go1.24.2 windows/amd64

$ go test
# exammple.com/greetings
# [exammple.com/greetings]
.\greetings.go:20:25: non-constant format string in call to fmt.Sprintf
FAIL    exammple.com/greetings [build failed]
@gopherbot gopherbot added this to the Unreleased milestone May 23, 2025
@FelixDobler
Copy link
Author

If desired, I can create a PR that circumvents the changed test behavior by e.g. replacing the name to be used in the formatted string with a static one.

@gabyhelp gabyhelp added the Documentation Issues describing a change to documentation. label May 23, 2025
@seankhliao seankhliao changed the title x/website: Mismatching console output of go test x/website/_content/doc/tutorial: go vet flags tutorial code for non-constant format string May 24, 2025
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 24, 2025
@adonovan
Copy link
Member

Thanks for the bug report. I read through the tutorial but was unable to see any mistake that would cause that error. Can you include the exact contents of the files at the moment you observed the error? I wonder whether you have a stray backquote, for example fmt.Sprintf(`pattern, arg`) instead of fmt.Sprintf(`pattern`, arg) .

@adonovan adonovan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 27, 2025
@FelixDobler
Copy link
Author

Oh you're right, in step 4 of the "create a test" tutorial it replaces
message := fmt.Sprintf(randomFormat(), name)
with
message := fmt.Sprint(randomFormat())
removing the f from Sprintf and hence changing the function signature.

Sorry for binding resources with such a simple oversight.
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues describing a change to documentation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. website
Projects
None yet
Development

No branches or pull requests

5 participants