summaryrefslogtreecommitdiffstats
path: root/htesting/test_helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'htesting/test_helpers.go')
-rw-r--r--htesting/test_helpers.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/htesting/test_helpers.go b/htesting/test_helpers.go
index 21b4b831e..ff14de58d 100644
--- a/htesting/test_helpers.go
+++ b/htesting/test_helpers.go
@@ -20,8 +20,11 @@ import (
"runtime"
"strconv"
"strings"
+ "testing"
"time"
+ qt "github.com/frankban/quicktest"
+
"github.com/spf13/afero"
)
@@ -124,6 +127,11 @@ func GoMinorVersion() int {
return extractMinorVersionFromGoTag(runtime.Version())
}
+// IsWindows reports whether this runs on Windows.
+func IsWindows() bool {
+ return runtime.GOOS == "windows"
+}
+
var goMinorVersionRe = regexp.MustCompile(`go1.(\d*)`)
func extractMinorVersionFromGoTag(tag string) int {
@@ -140,5 +148,33 @@ func extractMinorVersionFromGoTag(tag string) int {
// a commit hash, not useful.
return -1
+}
+
+// NewPinnedRunner creates a new runner that will only Run tests matching the given regexp.
+// This is added mostly to use in combination with https://marketplace.visualstudio.com/items?itemName=windmilleng.vscode-go-autotest
+func NewPinnedRunner(t testing.TB, pinnedTestRe string) *PinnedRunner {
+ if pinnedTestRe == "" {
+ pinnedTestRe = ".*"
+ }
+ pinnedTestRe = strings.ReplaceAll(pinnedTestRe, "_", " ")
+ re := regexp.MustCompile("(?i)" + pinnedTestRe)
+ return &PinnedRunner{
+ c: qt.New(t),
+ re: re,
+ }
+}
+
+type PinnedRunner struct {
+ c *qt.C
+ re *regexp.Regexp
+}
+func (r *PinnedRunner) Run(name string, f func(c *qt.C)) bool {
+ if !r.re.MatchString(name) {
+ if IsGitHubAction() {
+ r.c.Fatal("found pinned test when running in CI")
+ }
+ return true
+ }
+ return r.c.Run(name, f)
}