From dcba6827a0d2e3d52a41121a803f6364e7672a42 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 5 Mar 2023 11:51:11 -0800 Subject: [PATCH] gotypes: handle change in error message in go 1.20 Uses a regular expression to handle the change in error message introduced in: https://github.com/golang/go/commit/2da95e0ec80cb7df1f89a7b7f147dde42ad17a19 Updates #367 --- gotypes/signature_test.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/gotypes/signature_test.go b/gotypes/signature_test.go index 03f8e9b3..ffb80a9d 100644 --- a/gotypes/signature_test.go +++ b/gotypes/signature_test.go @@ -3,7 +3,7 @@ package gotypes import ( "go/token" "go/types" - "strings" + "regexp" "testing" "golang.org/x/tools/go/packages" @@ -118,17 +118,22 @@ func TestParseSignature(t *testing.T) { func TestParseSignatureErrors(t *testing.T) { cases := []struct { - Expr string - ErrorContains string + Expr string + ErrorPattern string }{ - {"idkjklol", "undeclared name"}, - {"struct{}", "not a function signature"}, - {"uint32(0xfeedbeef)", "should have nil value"}, + {"idkjklol", `(undeclared|undefined)`}, + {"struct{}", `not a function signature`}, + {"uint32(0xfeedbeef)", `should have nil value`}, } for _, c := range cases { + errrx, err := regexp.Compile(c.ErrorPattern) + if err != nil { + t.Fatal(err) + } + s, err := ParseSignature(c.Expr) - if s != nil || err == nil || !strings.Contains(err.Error(), c.ErrorContains) { - t.Errorf("expect error from expression %s\ngot: %s\nexpect substring: %s\n", c.Expr, err, c.ErrorContains) + if s != nil || err == nil || !errrx.MatchString(err.Error()) { + t.Errorf("expect error from expression %s\ngot: %s\nexpect match: %s\n", c.Expr, err, c.ErrorPattern) } } }