poll: Continue(): use format.Message for formatting#279
poll: Continue(): use format.Message for formatting#279dnephin merged 1 commit intogotestyourself:mainfrom
Conversation
7e0fb1f to
97d125f
Compare
|
Windows failure looks unrelated; not sure what's causing it though; |
|
fix for the panic in this PR: |
|
@dnephin @vdemeester PTAL 🤗 |
dnephin
left a comment
There was a problem hiding this comment.
It is possible this could be a breaking change for some code, but it seems unlikely.
The problem the linter is complaining about is still there. Ex:
errorMsg := "invalid %size% value '4f'"
poll.Continue(errorMsg)
// invalid %!s(MISSING)ize%!v(MISSING)alue '4f'Maybe there should have been both a Continue and Continuef.
Another option would be to add an issues.exclude-rule to https://github.com/moby/moby/blob/master/.golangci.yml:
// ignore possible invalid format strings in test helper
- path: _test\.go
linters: [govet]
text: non-constant format string in call to gotest.tools/v3/poll.Continue
or to be safe
return poll.Continue("%v", msg)
dnephin
left a comment
There was a problem hiding this comment.
Ah, I forgot Continue handled this already!
Would something that keeps the function signature work?
func Continue(message string, args ...interface{}) Result {
return result{message: format.Message(append([]interface{}{message}, args...)...)}
Yes, works for me! I was initially considering doing that, but then went for the Let me update. |
Current versions of govet check for printf functions called with a format
string, but no arguments. This results in linting errors for uses of Continue
with a fixed message, for example:
poll/poll.go:154:18: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet)
return Continue(buf.String())
^
While not explicitly called out in the function's GoDoc, I think the intent
was to provide the same behavior as the msgAndArgs arguments in the assert
package, which allows for either a literal message (or value), or a format
with arguments to be passed.
Accepting a non-string variable as first argument would require a change
of the function's signature, but we can use the format.Message function
internally to fix the linting issue.
Signed-off-by: Sebastiaan van Stijn <[email protected]>
97d125f to
7f28766
Compare
|
Oh; forgot to coment; I updated with your suggestions; @dnephin PTAL 🤗 |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [gotest.tools/v3](https://github.com/gotestyourself/gotest.tools) | require | patch | `v3.5.1` -> `v3.5.2` | --- ### Release Notes <details> <summary>gotestyourself/gotest.tools (gotest.tools/v3)</summary> ### [`v3.5.2`](https://github.com/gotestyourself/gotest.tools/releases/tag/v3.5.2) [Compare Source](gotestyourself/gotest.tools@v3.5.1...v3.5.2) #### What's Changed - assert: ensure message is always displayed & fix under bazel by [@​cstrahan](https://github.com/cstrahan) in gotestyourself/gotest.tools#276 - go.mod: golang.org/x/tools v0.13.0 for go1.22+ compatibility by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#282 - poll: Continue(): use format.Message for formatting by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#279 - fix TestFromDirSymlink on Windows due to missing drive-letter by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#283 - Fix various linting issues and minor bugs by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#280 - fix badges in readme, gofmt, and minor linting fix by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#284 - circleci: add go1.21, go1.22, go1.23, and update golangci-lint to v1.60.3 by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#285 - assert, assert/cmp: un-deprecate assert.ErrorType for now by [@​thaJeztah](https://github.com/thaJeztah) in gotestyourself/gotest.tools#286 #### New Contributors - [@​cstrahan](https://github.com/cstrahan) made their first contribution in gotestyourself/gotest.tools#276 **Full Changelog**: gotestyourself/gotest.tools@v3.5.1...v3.5.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC), Automerge - Between 12:00 AM and 03:59 AM ( * 0-3 * * * ) (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTIuMCIsInVwZGF0ZWRJblZlciI6IjM5LjI1Mi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/524 Co-authored-by: Renovate Bot <[email protected]> Co-committed-by: Renovate Bot <[email protected]>
Current versions of govet check for printf functions called with a format
string, but no arguments. This results in linting errors for uses of Continue
with a fixed message, for example:
While not explicitly called out in the function's GoDoc, I think the intent
was to provide the same behavior as the msgAndArgs arguments in the assert
package, which allows for either a literal message (or value), or a format
with arguments to be passed.
Accepting a non-string variable as first argument would require a change
of the function's signature, but we can use the format.Message function
internally to fix the linting issue.