diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
| commit | 7638a44fa613f23434318bdf136723aa010e8638 (patch) | |
| tree | 7b5270ed4e9b6d7f1ee0f28c58d8077aa1d18005 /container/stub | |
| parent | a14b6535a66cb7ac0fc4827f767ffaee0ce04b57 (diff) | |
treewide: parallel tests
Most tests already had no global state, however parallel was never enabled. This change enables it for all applicable tests.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/stub')
| -rw-r--r-- | container/stub/call_test.go | 4 | ||||
| -rw-r--r-- | container/stub/errors_test.go | 7 | ||||
| -rw-r--r-- | container/stub/exit_test.go | 16 | ||||
| -rw-r--r-- | container/stub/stub_test.go | 39 |
4 files changed, 66 insertions, 0 deletions
diff --git a/container/stub/call_test.go b/container/stub/call_test.go index 67187987..db0b59dc 100644 --- a/container/stub/call_test.go +++ b/container/stub/call_test.go @@ -8,13 +8,17 @@ import ( ) func TestCallError(t *testing.T) { + t.Parallel() + t.Run("contains false", func(t *testing.T) { + t.Parallel() if err := new(stub.Call).Error(true, false, true); !reflect.DeepEqual(err, stub.ErrCheck) { t.Errorf("Error: %#v, want %#v", err, stub.ErrCheck) } }) t.Run("passthrough", func(t *testing.T) { + t.Parallel() wantErr := stub.UniqueError(0xbabe) if err := (&stub.Call{Err: wantErr}).Error(true); !reflect.DeepEqual(err, wantErr) { t.Errorf("Error: %#v, want %#v", err, wantErr) diff --git a/container/stub/errors_test.go b/container/stub/errors_test.go index 4d9252de..604841ac 100644 --- a/container/stub/errors_test.go +++ b/container/stub/errors_test.go @@ -9,7 +9,10 @@ import ( ) func TestUniqueError(t *testing.T) { + t.Parallel() + t.Run("format", func(t *testing.T) { + t.Parallel() want := "unique error 2989 injected by the test suite" if got := stub.UniqueError(0xbad).Error(); got != want { t.Errorf("Error: %q, want %q", got, want) @@ -17,13 +20,17 @@ func TestUniqueError(t *testing.T) { }) t.Run("is", func(t *testing.T) { + t.Parallel() + t.Run("type", func(t *testing.T) { + t.Parallel() if errors.Is(stub.UniqueError(0), syscall.ENOTRECOVERABLE) { t.Error("Is: unexpected true") } }) t.Run("val", func(t *testing.T) { + t.Parallel() if errors.Is(stub.UniqueError(0), stub.UniqueError(1)) { t.Error("Is: unexpected true") } diff --git a/container/stub/exit_test.go b/container/stub/exit_test.go index 4e935ff4..15ad31f1 100644 --- a/container/stub/exit_test.go +++ b/container/stub/exit_test.go @@ -32,13 +32,20 @@ func (o *overrideTFailNow) Fail() { } func TestHandleExit(t *testing.T) { + t.Parallel() + t.Run("exit", func(t *testing.T) { + t.Parallel() defer stub.HandleExit(t) panic(stub.PanicExit) }) t.Run("goexit", func(t *testing.T) { + t.Parallel() + t.Run("FailNow", func(t *testing.T) { + t.Parallel() + ot := &overrideTFailNow{T: t} defer func() { if !ot.failNow { @@ -50,6 +57,8 @@ func TestHandleExit(t *testing.T) { }) t.Run("Fail", func(t *testing.T) { + t.Parallel() + ot := &overrideTFailNow{T: t} defer func() { if !ot.fail { @@ -62,11 +71,16 @@ func TestHandleExit(t *testing.T) { }) t.Run("nil", func(t *testing.T) { + t.Parallel() defer stub.HandleExit(t) }) t.Run("passthrough", func(t *testing.T) { + t.Parallel() + t.Run("toplevel", func(t *testing.T) { + t.Parallel() + defer func() { want := 0xcafebabe if r := recover(); r != want { @@ -79,6 +93,8 @@ func TestHandleExit(t *testing.T) { }) t.Run("new", func(t *testing.T) { + t.Parallel() + defer func() { want := 0xcafe if r := recover(); r != want { diff --git a/container/stub/stub_test.go b/container/stub/stub_test.go index de9971f3..9c9b0eb8 100644 --- a/container/stub/stub_test.go +++ b/container/stub/stub_test.go @@ -36,8 +36,14 @@ func (t *overrideT) Errorf(format string, args ...any) { } func TestStub(t *testing.T) { + t.Parallel() + t.Run("goexit", func(t *testing.T) { + t.Parallel() + t.Run("FailNow", func(t *testing.T) { + t.Parallel() + defer func() { if r := recover(); r != panicFailNow { t.Errorf("recover: %v", r) @@ -47,6 +53,8 @@ func TestStub(t *testing.T) { }) t.Run("SkipNow", func(t *testing.T) { + t.Parallel() + defer func() { want := "invalid call to SkipNow" if r := recover(); r != want { @@ -57,6 +65,8 @@ func TestStub(t *testing.T) { }) t.Run("Skip", func(t *testing.T) { + t.Parallel() + defer func() { want := "invalid call to Skip" if r := recover(); r != want { @@ -67,6 +77,8 @@ func TestStub(t *testing.T) { }) t.Run("Skipf", func(t *testing.T) { + t.Parallel() + defer func() { want := "invalid call to Skipf" if r := recover(); r != want { @@ -78,7 +90,11 @@ func TestStub(t *testing.T) { }) t.Run("new", func(t *testing.T) { + t.Parallel() + t.Run("success", func(t *testing.T) { + t.Parallel() + s := New(t, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{ {"New", ExpectArgs{}, nil, nil}, }, Tracks: []Expect{{Calls: []Call{ @@ -112,6 +128,8 @@ func TestStub(t *testing.T) { }) t.Run("overrun", func(t *testing.T) { + t.Parallel() + ot := &overrideT{T: t} ot.error.Store(checkError(t, "New: track overrun")) s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{ @@ -135,7 +153,11 @@ func TestStub(t *testing.T) { }) t.Run("expects", func(t *testing.T) { + t.Parallel() + t.Run("overrun", func(t *testing.T) { + t.Parallel() + ot := &overrideT{T: t} ot.error.Store(checkError(t, "Expects: advancing beyond expected calls")) s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{}) @@ -143,7 +165,11 @@ func TestStub(t *testing.T) { }) t.Run("separator", func(t *testing.T) { + t.Parallel() + t.Run("overrun", func(t *testing.T) { + t.Parallel() + ot := &overrideT{T: t} ot.errorf.Store(checkErrorf(t, "Expects: func = %s, separator overrun", "meow")) s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{ @@ -153,6 +179,8 @@ func TestStub(t *testing.T) { }) t.Run("mismatch", func(t *testing.T) { + t.Parallel() + ot := &overrideT{T: t} ot.errorf.Store(checkErrorf(t, "Expects: separator, want %s", "panic")) s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{ @@ -163,6 +191,8 @@ func TestStub(t *testing.T) { }) t.Run("mismatch", func(t *testing.T) { + t.Parallel() + ot := &overrideT{T: t} ot.errorf.Store(checkErrorf(t, "Expects: func = %s, want %s", "meow", "nya")) s := New(ot, func(s *Stub[stubHolder]) stubHolder { return stubHolder{s} }, Expect{Calls: []Call{ @@ -176,6 +206,8 @@ func TestStub(t *testing.T) { func TestCheckArg(t *testing.T) { t.Run("oob negative", func(t *testing.T) { + t.Parallel() + defer func() { want := "invalid call to CheckArg" if r := recover(); r != want { @@ -191,12 +223,14 @@ func TestCheckArg(t *testing.T) { {"panic", ExpectArgs{PanicExit}, nil, nil}, {"meow", ExpectArgs{-1}, nil, nil}, }}) + t.Run("match", func(t *testing.T) { s.Expects("panic") if !CheckArg(s, "v", PanicExit, 0) { t.Errorf("CheckArg: unexpected false") } }) + t.Run("mismatch", func(t *testing.T) { defer HandleExit(t) s.Expects("meow") @@ -205,6 +239,7 @@ func TestCheckArg(t *testing.T) { t.Errorf("CheckArg: unexpected true") } }) + t.Run("oob", func(t *testing.T) { s.pos++ defer func() { @@ -218,7 +253,11 @@ func TestCheckArg(t *testing.T) { } func TestCheckArgReflect(t *testing.T) { + t.Parallel() + t.Run("oob lower", func(t *testing.T) { + t.Parallel() + defer func() { want := "invalid call to CheckArgReflect" if r := recover(); r != want { |
