Skip to content

Commit

Permalink
testscript: add gc and gccgo conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne authored and mvdan committed Mar 12, 2022
1 parent f1aca1d commit b00b079
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 0 additions & 6 deletions gotooltest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ func Setup(p *testscript.Params) error {
p.Cmds["go"] = cmdGo
origCondition := p.Condition
p.Condition = func(cond string) (bool, error) {
if cond == "gc" || cond == "gccgo" {
// TODO this reflects the compiler that the current
// binary was built with but not necessarily the compiler
// that will be used.
return cond == runtime.Compiler, nil
}
if goVersionRegex.MatchString(cond) {
for _, v := range build.Default.ReleaseTags {
if cond == v {
Expand Down
2 changes: 2 additions & 0 deletions testscript/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ should only run when the condition is satisfied. The predefined conditions are:
- [link] for whether the OS has hard link support
- [symlink] for whether the OS has symbolic link support
- [exec:prog] for whether prog is available for execution (found by exec.LookPath)
- [gc] for whether Go was built with gc
- [gccgo] for whether Go was built with gccgo
A condition can be negated: [!short] means to run the rest of the line
when testing.Short() is false.
Expand Down
6 changes: 6 additions & 0 deletions testscript/testdata/cond.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[!exec:sh] skip 'sh not found in $PATH'

# test that exactly one of gc and gccgo is set
[gc] exec sh -c 'echo gc >> go-compiler'
[gccgo] exec sh -c 'echo gccgo >> go-compiler'
grep '\A(gc|gccgo)\n\z' go-compiler
5 changes: 5 additions & 0 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ func (ts *TestScript) condition(cond string) (bool, error) {
return err == nil
}).(bool)
return ok, nil
case cond == "gc" || cond == "gccgo":
// TODO this reflects the compiler that the current
// binary was built with but not necessarily the compiler
// that will be used.
return cond == runtime.Compiler, nil
case ts.params.Condition != nil:
return ts.params.Condition(cond)
default:
Expand Down

0 comments on commit b00b079

Please sign in to comment.