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
testscript: add go:version condition #149
Conversation
f3eb37b
to
99120a2
Compare
Are you aware that you can use build tags for this, such as |
No, I was not aware. Are you sure that this is the case? The word "tag" does appear anywhere in the $ go test ./testscript
--- FAIL: TestScripts (0.00s)
--- FAIL: TestScripts/goversion (0.00s)
testscript.go:397:
> [go1.16] exec sh -c 'exit 0'
FAIL: testdata/goversion.txt:4: unknown condition "go1.16"
FAIL
FAIL github.com/rogpeppe/go-internal/testscript 0.846s
FAIL |
Ah, I was slightly wrong. We do already support this via conditions, but only if you opt into gotooltest: go-internal/gotooltest/setup.go Lines 115 to 122 in 115ce09
|
So I think you could classify this as "gotooltest is not particularly well documented" :) Though, then again, its code is barely 150 lines. |
Ah, thank you. In my case I'm looking to test an application built with Go rather than the Using build tags is a much nicer solution that what's in this PR. What do you think about replacing this PR with a PR that implements the |
Yeah, perhaps using gotooltest would be a bit overkill. An alternative might be to promote those conditionals to the testscript package. I really don't see why they are specific to testing Go tools. You might want to write conditionals based on the Go version for the standard library changes, like you say. That seems to me like a smaller change overall, since we wouldn't end up with two ways to write the same conditional. I'm also not sure your proposed fix is right, because it seems to only look at ReleaseTags, so I'm pretty sure it won't work for any arbitrary build tag like |
Are the actual build tags like |
Closing in favor of #150. |
Changes in Go's standard library can affect program behavior. For example, Go 1.18's
text/template
changes the behavior of theand
andor
to lazily evaluate their arguments. This can impact application behavior.This PR adds a
go:version
condition that allows testscripts to be conditional on the Go version being used.