aboutsummaryrefslogtreecommitdiff
path: root/src/testing/sub_test.go
diff options
context:
space:
mode:
authorVladimir Varankin <vladimir@varank.in>2024-08-21 20:47:11 +0200
committerGopher Robot <gobot@golang.org>2024-08-21 20:52:09 +0000
commit440c9ee73d2698912918755d023e5de813ec2f83 (patch)
treea40a6bcdc8933b558a572212c33edbb378ea58a2 /src/testing/sub_test.go
parent31a9c139419dadf35df1b162115da69a0b4cb917 (diff)
downloadgo-440c9ee73d2698912918755d023e5de813ec2f83.tar.xz
testing: rename testContext to testState
Following up to CL 603959, update internals of testing package to reduce the confusion around "context". The changes rename testContext/benchContext/fuzzContext to testState/benchState/fuzzState. Change-Id: Ib8855dab456d41ab343488fcf5fefff2431f7b72 Reviewed-on: https://go-review.googlesource.com/c/go/+/607555 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/testing/sub_test.go')
-rw-r--r--src/testing/sub_test.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index 90c2afe605..82ec5809e5 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -21,12 +21,11 @@ func init() {
benchTime.d = 100 * time.Millisecond
}
-func TestTestContext(t *T) {
+func TestTestState(t *T) {
const (
add1 = 0
done = 1
)
- // After each of the calls are applied to the context, the
type call struct {
typ int // run or done
// result from applying the call
@@ -72,7 +71,7 @@ func TestTestContext(t *T) {
},
}}
for i, tc := range testCases {
- ctx := &testContext{
+ tstate := &testState{
startParallel: make(chan bool),
maxParallel: tc.max,
}
@@ -88,18 +87,18 @@ func TestTestContext(t *T) {
started := false
switch call.typ {
case add1:
- signal := doCall(ctx.waitParallel)
+ signal := doCall(tstate.waitParallel)
select {
case <-signal:
started = true
- case ctx.startParallel <- true:
+ case tstate.startParallel <- true:
<-signal
}
case done:
- signal := doCall(ctx.release)
+ signal := doCall(tstate.release)
select {
case <-signal:
- case <-ctx.startParallel:
+ case <-tstate.startParallel:
started = true
<-signal
}
@@ -107,11 +106,11 @@ func TestTestContext(t *T) {
if started != call.started {
t.Errorf("%d:%d:started: got %v; want %v", i, j, started, call.started)
}
- if ctx.running != call.running {
- t.Errorf("%d:%d:running: got %v; want %v", i, j, ctx.running, call.running)
+ if tstate.running != call.running {
+ t.Errorf("%d:%d:running: got %v; want %v", i, j, tstate.running, call.running)
}
- if ctx.numWaiting != call.waiting {
- t.Errorf("%d:%d:waiting: got %v; want %v", i, j, ctx.numWaiting, call.waiting)
+ if tstate.numWaiting != call.waiting {
+ t.Errorf("%d:%d:waiting: got %v; want %v", i, j, tstate.numWaiting, call.waiting)
}
}
}
@@ -507,7 +506,7 @@ func TestTRun(t *T) {
}}
for _, tc := range testCases {
t.Run(tc.desc, func(t *T) {
- ctx := newTestContext(tc.maxPar, allMatcher())
+ tstate := newTestState(tc.maxPar, allMatcher())
buf := &strings.Builder{}
root := &T{
common: common{
@@ -516,14 +515,14 @@ func TestTRun(t *T) {
name: "",
w: buf,
},
- context: ctx,
+ tstate: tstate,
}
if tc.chatty {
root.chatty = newChattyPrinter(root.w)
root.chatty.json = tc.json
}
ok := root.Run(tc.desc, tc.f)
- ctx.release()
+ tstate.release()
if ok != tc.ok {
t.Errorf("%s:ok: got %v; want %v", tc.desc, ok, tc.ok)
@@ -531,8 +530,8 @@ func TestTRun(t *T) {
if ok != !root.Failed() {
t.Errorf("%s:root failed: got %v; want %v", tc.desc, !ok, root.Failed())
}
- if ctx.running != 0 || ctx.numWaiting != 0 {
- t.Errorf("%s:running and waiting non-zero: got %d and %d", tc.desc, ctx.running, ctx.numWaiting)
+ if tstate.running != 0 || tstate.numWaiting != 0 {
+ t.Errorf("%s:running and waiting non-zero: got %d and %d", tc.desc, tstate.running, tstate.numWaiting)
}
got := strings.TrimSpace(buf.String())
want := strings.TrimSpace(tc.output)
@@ -790,8 +789,8 @@ func TestRacyOutput(t *T) {
}
root := &T{
- common: common{w: &funcWriter{raceDetector}},
- context: newTestContext(1, allMatcher()),
+ common: common{w: &funcWriter{raceDetector}},
+ tstate: newTestState(1, allMatcher()),
}
root.chatty = newChattyPrinter(root.w)
root.Run("", func(t *T) {
@@ -815,7 +814,7 @@ func TestRacyOutput(t *T) {
// The late log message did not include the test name. Issue 29388.
func TestLogAfterComplete(t *T) {
- ctx := newTestContext(1, allMatcher())
+ tstate := newTestState(1, allMatcher())
var buf bytes.Buffer
t1 := &T{
common: common{
@@ -824,7 +823,7 @@ func TestLogAfterComplete(t *T) {
signal: make(chan bool, 1),
w: &buf,
},
- context: ctx,
+ tstate: tstate,
}
c1 := make(chan bool)