This commit is contained in:
2026-02-19 10:07:43 +00:00
parent 007438e372
commit 6e637ecf77
1763 changed files with 60820 additions and 279516 deletions

View File

@@ -6,6 +6,7 @@
package testenv
import (
"context"
"flag"
"tailscale.com/types/lazy"
@@ -19,3 +20,48 @@ func InTest() bool {
return flag.Lookup("test.v") != nil
})
}
// TB is testing.TB, to avoid importing "testing" in non-test code.
type TB interface {
Cleanup(func())
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
Fatal(args ...any)
Fatalf(format string, args ...any)
Helper()
Log(args ...any)
Logf(format string, args ...any)
Name() string
Setenv(key, value string)
Chdir(dir string)
Skip(args ...any)
SkipNow()
Skipf(format string, args ...any)
Skipped() bool
TempDir() string
Context() context.Context
}
// InParallelTest reports whether t is running as a parallel test.
//
// Use of this function taints t such that its Parallel method (assuming t is an
// actual *testing.T) will panic if called after this function.
func InParallelTest(t TB) (isParallel bool) {
defer func() {
if r := recover(); r != nil {
isParallel = true
}
}()
t.Chdir(".") // panics in a t.Parallel test
return false
}
// AssertInTest panics if called outside of a test binary.
func AssertInTest() {
if !InTest() {
panic("func called outside of test binary")
}
}