Skip to content

Commit b00b079

Browse files
twpaynemvdan
authored andcommitted
testscript: add gc and gccgo conditions
1 parent f1aca1d commit b00b079

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

gotooltest/setup.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ func Setup(p *testscript.Params) error {
106106
p.Cmds["go"] = cmdGo
107107
origCondition := p.Condition
108108
p.Condition = func(cond string) (bool, error) {
109-
if cond == "gc" || cond == "gccgo" {
110-
// TODO this reflects the compiler that the current
111-
// binary was built with but not necessarily the compiler
112-
// that will be used.
113-
return cond == runtime.Compiler, nil
114-
}
115109
if goVersionRegex.MatchString(cond) {
116110
for _, v := range build.Default.ReleaseTags {
117111
if cond == v {

testscript/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ should only run when the condition is satisfied. The predefined conditions are:
105105
- [link] for whether the OS has hard link support
106106
- [symlink] for whether the OS has symbolic link support
107107
- [exec:prog] for whether prog is available for execution (found by exec.LookPath)
108+
- [gc] for whether Go was built with gc
109+
- [gccgo] for whether Go was built with gccgo
108110
109111
A condition can be negated: [!short] means to run the rest of the line
110112
when testing.Short() is false.

testscript/testdata/cond.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[!exec:sh] skip 'sh not found in $PATH'
2+
3+
# test that exactly one of gc and gccgo is set
4+
[gc] exec sh -c 'echo gc >> go-compiler'
5+
[gccgo] exec sh -c 'echo gccgo >> go-compiler'
6+
grep '\A(gc|gccgo)\n\z' go-compiler

testscript/testscript.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ func (ts *TestScript) condition(cond string) (bool, error) {
592592
return err == nil
593593
}).(bool)
594594
return ok, nil
595+
case cond == "gc" || cond == "gccgo":
596+
// TODO this reflects the compiler that the current
597+
// binary was built with but not necessarily the compiler
598+
// that will be used.
599+
return cond == runtime.Compiler, nil
595600
case ts.params.Condition != nil:
596601
return ts.params.Condition(cond)
597602
default:

0 commit comments

Comments
 (0)