Skip to content

Commit

Permalink
t.Parallel for all that's possible
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Aug 18, 2023
1 parent 035a755 commit a6012a9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions assert/goid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

func TestGoid(t *testing.T) {
t.Parallel()
stackBytes := []byte(`goroutine 518 [running]:
`)

Expand Down
15 changes: 12 additions & 3 deletions internal/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestFullName(t *testing.T) {
}

func TestIsAnchor(t *testing.T) {
t.Parallel()
type args struct {
input string
StackInfo
Expand Down Expand Up @@ -78,8 +79,10 @@ func TestIsAnchor(t *testing.T) {
"github.com/lainio/err2/try.To1[...](...)",
StackInfo{"lainio/err2", "", 0, nil, nil}}, true},
}
for _, tt := range tests {
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
test.Require(t, tt.retval == tt.isAnchor(tt.input), "equal")
})
}
Expand Down Expand Up @@ -132,6 +135,7 @@ func TestIsFuncAnchor(t *testing.T) {
}

func TestFnLNro(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
Expand All @@ -141,8 +145,10 @@ func TestFnLNro(t *testing.T) {
" /Users/harrilainio/go/pkg/mod/github.com/lainio/err2@v0.8.5/internal/handler/handler.go:69 +0xbc",
69},
}
for _, tt := range tests {
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
output := fnLNro(tt.input)
test.Require(t, output == tt.output, output)
})
Expand Down Expand Up @@ -210,6 +216,7 @@ func TestStackPrint_noLimits(t *testing.T) {
}

func TestStackPrintForTest(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
Expand All @@ -220,8 +227,10 @@ func TestStackPrintForTest(t *testing.T) {
{"short", input, outputForTestLvl2, 2},
//{"real test trace", inputFromTest, outputFromTest, 4},
}
for _, tt := range tests {
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
r := strings.NewReader(tt.input)
w := new(bytes.Buffer)
printStackForTest(r, w, tt.lvl)
Expand Down
11 changes: 9 additions & 2 deletions internal/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestProcess(t *testing.T) {
t.Parallel()
type args struct {
handler.Info
}
Expand Down Expand Up @@ -113,8 +114,10 @@ func TestProcess(t *testing.T) {
errStr: "error",
}},
}
for _, tt := range tests {
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if handler.WorkToDo(tt.args.Any, tt.args.Err) {
handler.Process(&tt.args.Info)

Expand Down Expand Up @@ -142,6 +145,7 @@ func Handle() {
}

func TestPreProcess_debug(t *testing.T) {
t.Parallel()
// in real case PreProcess is called from Handle function. So, we make our
// own Handle here. Now our test function name will be the Handle caller
// and that's what error stack tracing is all about
Expand All @@ -159,6 +163,7 @@ func TestPreProcess_debug(t *testing.T) {
}

func TestPreProcess(t *testing.T) {
t.Parallel()
type args struct {
handler.Info
a []any
Expand Down Expand Up @@ -225,8 +230,10 @@ func TestPreProcess(t *testing.T) {
errStr: "",
}},
}
for _, tt := range tests {
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if handler.WorkToDo(tt.args.Any, tt.args.Err) &&
len(tt.args.a) > 0 {

Expand Down
9 changes: 4 additions & 5 deletions internal/str/str_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ func TestDecamel(t *testing.T) {
{"unnatural method and anonym", args{"(**DIDAgent)...AssertWallet...Func1"}, "didagent assert wallet: func1"},
{"from spf13 cobra", args{"bot.glob..func5"}, "bot: glob: func5"},
}
for _, tt := range tests {
s := tt.args.s
want := tt.want
for _, ttv := range tests {
tt := ttv
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := str.Decamel(s)
test.RequireEqual(t, got, want)
got := str.Decamel(tt.args.s)
test.RequireEqual(t, got, tt.want)
})
}
}
2 changes: 2 additions & 0 deletions try/out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func ExampleResult1_Logf() {
}

func TestResult2_Logf(t *testing.T) {
t.Parallel()
// Set log tracing to stdout that we can see it in Example output. In
// normal cases that would be a Logging stream or stderr.
err2.SetLogTracer(os.Stdout)
Expand All @@ -110,6 +111,7 @@ func TestResult2_Logf(t *testing.T) {
}

func TestResult_Handle(t *testing.T) {
t.Parallel()
// try out f() |err| handle to show how to stop propagate error
callFn := func(mode int) (err error) {
defer err2.Handle(&err)
Expand Down

0 comments on commit a6012a9

Please sign in to comment.