-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/cuetest: add support for issue-based conditions/checkers
Often tests (whether pure Go tests or testscript scripts) need to be skipped until such a time as a linked issue is fixed. This change adds support for a testscript condition and a Go testing helper function that take a Go/CUE issue link as an argument. In the case of a testscript condition, it is satisfied unless the CUE_NON_ISSUES environment variable contains a regular expression that matches the argument, indicating such issues are no longer issues. This condition is generally used in conjunction with the skip command. The Go testing helping function skips a test under the same condition. The CUE_NON_ISSUES environment variable can therefore be set to different patterns in order to vary which tests are run (i.e. not skipped). CUE_NON_ISSUES=. will cause all tests guarded by this check to be run (assuming the testscript condition is used in conjunction with skip). Et cetera. Having structured skips of this sort makes it easier in future to analyse and verify that issues remain issues, etc. Change-Id: I6545c87b1c60d3fdf13abb301d90eca6d615153d Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8761 Reviewed-by: CUE cueckoo <cueckoo@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.org.uk> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
- Loading branch information
Showing
2 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package cuetest | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestCondition(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
env string | ||
con string | ||
want bool | ||
err string | ||
}{ | ||
// issue cases covered by TestCheckIssueCondition | ||
{ | ||
name: "long", | ||
con: "long", | ||
want: Long, // not really testing much here | ||
}, | ||
{ | ||
name: "bad condition", | ||
env: ".", | ||
con: "golang.org/Issue/1234", // note typo Issue | ||
want: false, | ||
err: "unknown condition golang.org/Issue/1234", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
os.Setenv(envNonIssues, c.env) | ||
got, err := Condition(c.con) | ||
if got != c.want { | ||
t.Errorf("expected %v; got %v", c.want, got) | ||
} | ||
if c.err != "" { | ||
if err == nil { | ||
t.Errorf("expected error %q; got nil", c.err) | ||
} else if e := err.Error(); e != c.err { | ||
t.Errorf("expected error %q; got %q", c.err, e) | ||
} | ||
} else if err != nil { | ||
t.Errorf("expected no error; got %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCheckIssueCondition(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
env string | ||
con string | ||
isIssue bool | ||
nonIssue bool | ||
err string | ||
}{ | ||
{ | ||
name: "empty env", | ||
con: "golang.org/issue/1234", | ||
isIssue: true, | ||
nonIssue: false, | ||
}, | ||
{ | ||
name: "match all issues", | ||
env: ".", | ||
con: "golang.org/issue/1234", | ||
isIssue: true, | ||
nonIssue: true, | ||
}, | ||
{ | ||
name: "bad issue URL", | ||
con: "golang.org/Issue/1234", // note typo | ||
isIssue: false, | ||
}, | ||
{ | ||
name: "bad env", | ||
env: `\`, | ||
con: "golang.org/issue/1234", | ||
isIssue: false, | ||
err: "failed to compile regexp \"\\\\\" specified via CUE_NON_ISSUES: error parsing regexp: trailing backslash at end of expression: ``", | ||
}, | ||
} | ||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
os.Setenv(envNonIssues, c.env) | ||
isIssue, nonIssue, err := checkIssueCondition(c.con) | ||
if isIssue != c.isIssue { | ||
t.Errorf("expected isIssue %v; got %v", c.isIssue, isIssue) | ||
} | ||
if nonIssue != c.nonIssue { | ||
t.Errorf("expected nonIssue %v; got %v", c.nonIssue, nonIssue) | ||
} | ||
if c.err != "" { | ||
if err == nil { | ||
t.Errorf("expected error %q; got nil", c.err) | ||
} else if e := err.Error(); e != c.err { | ||
t.Errorf("expected error %q; got %q", c.err, e) | ||
} | ||
} else if err != nil { | ||
t.Errorf("expected no error; got %q", err) | ||
} | ||
}) | ||
} | ||
|
||
} |