From 0cbd8973927c1b49ce2b01fe57f44804f6a01992 Mon Sep 17 00:00:00 2001 From: Yuxin Wang Date: Fri, 31 May 2024 10:52:31 -0400 Subject: [PATCH] update --- assertion/function/trustedfunc/cfg.go | 2 +- .../go.uber.org/abnormalflow/abnormalflow.go | 88 ++++++++++++++++++- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/assertion/function/trustedfunc/cfg.go b/assertion/function/trustedfunc/cfg.go index 964ea1d7..ae087b18 100644 --- a/assertion/function/trustedfunc/cfg.go +++ b/assertion/function/trustedfunc/cfg.go @@ -40,7 +40,7 @@ var _cfgTrimSuccs = map[trustedFuncSig]bool{ { kind: _method, enclosingRegex: regexp.MustCompile(`^testing.(T|B|F|TB)$`), - funcNameRegex: regexp.MustCompile(`^(FailNow|Skip|Skipf|SkipNow)$`), + funcNameRegex: regexp.MustCompile(`^(FailNow)|(Skip(f|Now)?)$`), }: true, } diff --git a/testdata/src/go.uber.org/abnormalflow/abnormalflow.go b/testdata/src/go.uber.org/abnormalflow/abnormalflow.go index f2987578..6d618a1a 100644 --- a/testdata/src/go.uber.org/abnormalflow/abnormalflow.go +++ b/testdata/src/go.uber.org/abnormalflow/abnormalflow.go @@ -25,7 +25,7 @@ import ( "testing" ) -func testDirectDereference(msg string, t *testing.T, tb testing.TB) { +func testDirectDereference(msg string, t *testing.T, b *testing.B, f *testing.F, tb testing.TB) { var nilable *int switch msg { case "print": @@ -61,6 +61,21 @@ func testDirectDereference(msg string, t *testing.T, tb testing.TB) { case "testing.T.Skipf": t.Skipf("msg") print(*nilable) + case "testing.B.Fatal": + b.Fatal("foo") + print(*nilable) + case "testing.B.Fatalf": + b.Fatalf("foo") + print(*nilable) + case "testing.B.SkipNow": + b.SkipNow() + print(*nilable) + case "testing.B.Skip": + b.Skip() + print(*nilable) + case "testing.B.Skipf": + b.Skipf("msg") + print(*nilable) case "testing.TB.Fatal": tb.Fatal("foo") print(*nilable) @@ -76,6 +91,21 @@ func testDirectDereference(msg string, t *testing.T, tb testing.TB) { case "testing.TB.Skipf": tb.Skipf("msg") print(*nilable) + case "testing.F.Fatal": + f.Fatal("foo") + print(*nilable) + case "testing.F.Fatalf": + f.Fatalf("foo") + print(*nilable) + case "testing.F.SkipNow": + f.SkipNow() + print(*nilable) + case "testing.F.Skip": + f.Skip() + print(*nilable) + case "testing.F.Skipf": + f.Skipf("msg") + print(*nilable) } } @@ -87,8 +117,8 @@ func errReturn(a bool) (*int, error) { return nil, errors.New("some error") } -func testErrReturn(msg string, b bool, t *testing.T, tb testing.TB) { - ptr, err := errReturn(b) +func testErrReturn(msg string, val bool, t *testing.T, b *testing.B, f *testing.F, tb testing.TB) { + ptr, err := errReturn(val) switch msg { case "print": if err != nil { @@ -151,6 +181,56 @@ func testErrReturn(msg string, b bool, t *testing.T, tb testing.TB) { t.Skipf("msg %s", err) } print(*ptr) + case "testing.B.Fatal": + if err != nil { + b.Fatal(err) + } + print(*ptr) + case "testing.B.Fatalf": + if err != nil { + b.Fatalf("msg %s", err) + } + print(*ptr) + case "testing.B.SkipNow": + if err != nil { + b.SkipNow() + } + print(*ptr) + case "testing.B.Skip": + if err != nil { + b.Skip(err) + } + print(*ptr) + case "testing.B.Skipf": + if err != nil { + b.Skipf("msg %s", err) + } + print(*ptr) + case "testing.F.Fatal": + if err != nil { + f.Fatal(err) + } + print(*ptr) + case "testing.F.Fatalf": + if err != nil { + f.Fatalf("msg %s", err) + } + print(*ptr) + case "testing.F.SkipNow": + if err != nil { + f.SkipNow() + } + print(*ptr) + case "testing.F.Skip": + if err != nil { + f.Skip(err) + } + print(*ptr) + case "testing.F.Skipf": + if err != nil { + f.Skipf("msg %s", err) + } + print(*ptr) case "testing.TB.Fatal": if err != nil { tb.Fatal(err) @@ -177,4 +257,4 @@ func testErrReturn(msg string, b bool, t *testing.T, tb testing.TB) { } print(*ptr) } -} \ No newline at end of file +}