*: replace fmt.Errorf with errors.New (#3752)

This commit is contained in:
Oleksandr Redko
2024-06-20 22:50:18 +03:00
committed by GitHub
parent 7e753701d4
commit 0d0d2e1b16
24 changed files with 163 additions and 155 deletions

View File

@ -122,8 +122,8 @@ func TestVariableEvaluation2(t *testing.T) {
{"a6.Baz", true, "8", "20", "int", nil},
{"a7.Baz", true, "5", "25", "int", nil},
{"a8.Baz", true, "\"feh\"", "", "string", nil},
{"a9.Baz", true, "nil", "", "int", fmt.Errorf("a9 is nil")},
{"a9.NonExistent", true, "nil", "", "int", fmt.Errorf("a9 has no member NonExistent")},
{"a9.Baz", true, "nil", "", "int", errors.New("a9 is nil")},
{"a9.NonExistent", true, "nil", "", "int", errors.New("a9 has no member NonExistent")},
{"a8", true, "main.FooBar2 {Bur: 10, Baz: \"feh\"}", "", "main.FooBar2", nil}, // reread variable after member
{"i32", true, "[2]int32 [1,2]", "", "[2]int32", nil},
{"b1", true, "true", "false", "bool", nil},
@ -139,10 +139,10 @@ func TestVariableEvaluation2(t *testing.T) {
{"ms", true, "main.Nest {Level: 0, Nest: *main.Nest {Level: 1, Nest: *(*main.Nest)(…", "", "main.Nest", nil},
{"ms.Nest.Nest", true, "*main.Nest {Level: 2, Nest: *main.Nest {Level: 3, Nest: *(*main.Nest)(…", "", "*main.Nest", nil},
{"ms.Nest.Nest.Nest.Nest.Nest", true, "*main.Nest nil", "", "*main.Nest", nil},
{"ms.Nest.Nest.Nest.Nest.Nest.Nest", true, "", "", "*main.Nest", fmt.Errorf("ms.Nest.Nest.Nest.Nest.Nest is nil")},
{"ms.Nest.Nest.Nest.Nest.Nest.Nest", true, "", "", "*main.Nest", errors.New("ms.Nest.Nest.Nest.Nest.Nest is nil")},
{"main.p1", true, "10", "12", "int", nil},
{"p1", true, "10", "13", "int", nil},
{"NonExistent", true, "", "", "", fmt.Errorf("could not find symbol value for NonExistent")},
{"NonExistent", true, "", "", "", errors.New("could not find symbol value for NonExistent")},
}
protest.AllowRecording(t)
@ -262,8 +262,8 @@ func TestVariableEvaluationShort(t *testing.T) {
{"a6.Baz", true, "8", "", "int", nil},
{"a7.Baz", true, "5", "", "int", nil},
{"a8.Baz", true, "\"feh\"", "", "string", nil},
{"a9.Baz", true, "nil", "", "int", fmt.Errorf("a9 is nil")},
{"a9.NonExistent", true, "nil", "", "int", fmt.Errorf("a9 has no member NonExistent")},
{"a9.Baz", true, "nil", "", "int", errors.New("a9 is nil")},
{"a9.NonExistent", true, "nil", "", "int", errors.New("a9 has no member NonExistent")},
{"a8", true, "main.FooBar2 {Bur: 10, Baz: \"feh\"}", "", "main.FooBar2", nil}, // reread variable after member
{"i32", true, "[2]int32 [...]", "", "[2]int32", nil},
{"b1", true, "true", "false", "bool", nil},
@ -279,10 +279,10 @@ func TestVariableEvaluationShort(t *testing.T) {
{"ms", true, "main.Nest {Level: 0, Nest: (*main.Nest)(0x…", "", "main.Nest", nil},
{"ms.Nest.Nest", true, "(*main.Nest)(0x…", "", "*main.Nest", nil},
{"ms.Nest.Nest.Nest.Nest.Nest", true, "*main.Nest nil", "", "*main.Nest", nil},
{"ms.Nest.Nest.Nest.Nest.Nest.Nest", true, "", "", "*main.Nest", fmt.Errorf("ms.Nest.Nest.Nest.Nest.Nest is nil")},
{"ms.Nest.Nest.Nest.Nest.Nest.Nest", true, "", "", "*main.Nest", errors.New("ms.Nest.Nest.Nest.Nest.Nest is nil")},
{"main.p1", true, "10", "", "int", nil},
{"p1", true, "10", "", "int", nil},
{"NonExistent", true, "", "", "", fmt.Errorf("could not find symbol value for NonExistent")},
{"NonExistent", true, "", "", "", errors.New("could not find symbol value for NonExistent")},
}
protest.AllowRecording(t)
@ -538,18 +538,18 @@ func getEvalExpressionTestCases() []varTest {
{"s1[2]", false, "\"three\"", "\"three\"", "string", nil},
{"s1[3]", false, "\"four\"", "\"four\"", "string", nil},
{"s1[4]", false, "\"five\"", "\"five\"", "string", nil},
{"s1[5]", false, "", "", "string", fmt.Errorf("index out of bounds")},
{"s1[5]", false, "", "", "string", errors.New("index out of bounds")},
{"a1[0]", false, "\"one\"", "\"one\"", "string", nil},
{"a1[1]", false, "\"two\"", "\"two\"", "string", nil},
{"a1[2]", false, "\"three\"", "\"three\"", "string", nil},
{"a1[3]", false, "\"four\"", "\"four\"", "string", nil},
{"a1[4]", false, "\"five\"", "\"five\"", "string", nil},
{"a1[5]", false, "", "", "string", fmt.Errorf("index out of bounds")},
{"a1[5]", false, "", "", "string", errors.New("index out of bounds")},
{"str1[0]", false, "48", "48", "byte", nil},
{"str1[1]", false, "49", "49", "byte", nil},
{"str1[2]", false, "50", "50", "byte", nil},
{"str1[10]", false, "48", "48", "byte", nil},
{"str1[11]", false, "", "", "byte", fmt.Errorf("index out of bounds")},
{"str1[11]", false, "", "", "byte", errors.New("index out of bounds")},
// slice/array/string reslicing
{"a1[2:4]", false, "[]string len: 2, cap: 2, [\"three\",\"four\"]", "[]string len: 2, cap: 2, [\"three\",\"four\"]", "[]string", nil},
@ -558,8 +558,8 @@ func getEvalExpressionTestCases() []varTest {
{"str1[0:11]", false, "\"01234567890\"", "\"01234567890\"", "string", nil},
{"str1[:3]", false, "\"012\"", "\"012\"", "string", nil},
{"str1[3:]", false, "\"34567890\"", "\"34567890\"", "string", nil},
{"str1[0:12]", false, "", "", "string", fmt.Errorf("index out of bounds")},
{"str1[5:3]", false, "", "", "string", fmt.Errorf("index out of bounds")},
{"str1[0:12]", false, "", "", "string", errors.New("index out of bounds")},
{"str1[5:3]", false, "", "", "string", errors.New("index out of bounds")},
{"str1[11:]", false, "\"\"", "\"\"", "string", nil},
{"longbyteslice[:70]", false, "[]uint8 len: 70, cap: 70, [118,101,114,121,32,108,111,110,103,32,115,116,114,105,110,103,32,48,49,50,51,52,53,54,55,56,57,97,48,49,50,51,52,53,54,55,56,57,98,48,49,50,51,52,53,54,55,56,57,99,48,49,50,51,52,53,54,55,56,57,100,48,49,50,51,52,53,54,55,56]", "[]uint8 len: 70, cap: 70, [118,101,114,121,32,108,111,110,103,32,115,116,114,105,110,103,32,48,49,50,51,52,53,54,55,56,57,97,48,49,50,51,52,53,54,55,56,57,98,48,49,50,51,52,53,54,55,56,57,99,48,49,50,51,52,53,54,55,56,57,100,48,49,50,51,52,53,54,55,56]", "[]uint8", nil},
@ -572,12 +572,12 @@ func getEvalExpressionTestCases() []varTest {
{"*p2", false, "5", "5", "int", nil},
{"p2", true, "*5", "(*int)(0x…", "*int", nil},
{"p3", true, "*int nil", "*int nil", "*int", nil},
{"*p3", false, "", "", "int", fmt.Errorf("nil pointer dereference")},
{"*p3", false, "", "", "int", errors.New("nil pointer dereference")},
// channels
{"ch1", true, "chan int 4/11", "chan int 4/11", "chan int", nil},
{"chnil", true, "chan int nil", "chan int nil", "chan int", nil},
{"ch1+1", false, "", "", "", fmt.Errorf("can not convert 1 constant to chan int")},
{"ch1+1", false, "", "", "", errors.New("can not convert 1 constant to chan int")},
{"int3chan.buf", false, "*[5]main.ThreeInts [{a: 1, b: 0, c: 0},{a: 2, b: 0, c: 0},{a: 3, b: 0, c: 0},{a: 0, b: 0, c: 0},{a: 0, b: 0, c: 0}]", "(*[5]main.ThreeInts)(…", "*[5]main.ThreeInts", nil},
// maps
@ -586,8 +586,8 @@ func getEvalExpressionTestCases() []varTest {
{"m2[c1.sa[2].B-4].A", false, "10", "10", "int", nil},
{"m2[*p1].B", false, "11", "11", "int", nil},
{"m3[as1]", false, "42", "42", "int", nil},
{"mnil[\"Malone\"]", false, "", "", "", fmt.Errorf("key not found")},
{"m1[80:]", false, "", "", "", fmt.Errorf("map index out of bounds")},
{"mnil[\"Malone\"]", false, "", "", "", errors.New("key not found")},
{"m1[80:]", false, "", "", "", errors.New("map index out of bounds")},
// interfaces
{"err1", true, "error(*main.astruct) *{A: 1, B: 2}", "error(*main.astruct) 0x…", "error", nil},
@ -601,13 +601,13 @@ func getEvalExpressionTestCases() []varTest {
{"iface4", true, "interface {}([]go/constant.Value) [4]", "interface {}([]go/constant.Value) [...]", "interface {}", nil},
{"ifacenil", true, "interface {} nil", "interface {} nil", "interface {}", nil},
{"err1 == err2", false, "false", "false", "", nil},
{"err1 == iface1", false, "", "", "", fmt.Errorf("mismatched types \"error\" and \"interface {}\"")},
{"err1 == iface1", false, "", "", "", errors.New("mismatched types \"error\" and \"interface {}\"")},
{"errnil == nil", false, "true", "true", "", nil},
{"errtypednil == nil", false, "false", "false", "", nil},
{"nil == errnil", false, "true", "true", "", nil},
{"err1.(*main.astruct)", false, "*main.astruct {A: 1, B: 2}", "(*main.astruct)(0x…", "*main.astruct", nil},
{"err1.(*main.bstruct)", false, "", "", "", fmt.Errorf("interface conversion: error is *main.astruct, not *main.bstruct")},
{"errnil.(*main.astruct)", false, "", "", "", fmt.Errorf("interface conversion: error is nil, not *main.astruct")},
{"err1.(*main.bstruct)", false, "", "", "", errors.New("interface conversion: error is *main.astruct, not *main.bstruct")},
{"errnil.(*main.astruct)", false, "", "", "", errors.New("interface conversion: error is nil, not *main.astruct")},
{"const1", true, "go/constant.Value(go/constant.int64Val) 3", "go/constant.Value(go/constant.int64Val) 3", "go/constant.Value", nil},
// combined expressions
@ -663,8 +663,8 @@ func getEvalExpressionTestCases() []varTest {
// builtins
{"cap(parr)", false, "4", "4", "", nil},
{"len(parr)", false, "4", "4", "", nil},
{"cap(p1)", false, "", "", "", fmt.Errorf("invalid argument p1 (type *int) for cap")},
{"len(p1)", false, "", "", "", fmt.Errorf("invalid argument p1 (type *int) for len")},
{"cap(p1)", false, "", "", "", errors.New("invalid argument p1 (type *int) for cap")},
{"len(p1)", false, "", "", "", errors.New("invalid argument p1 (type *int) for len")},
{"cap(a1)", false, "5", "5", "", nil},
{"len(a1)", false, "5", "5", "", nil},
{"cap(s3)", false, "6", "6", "", nil},
@ -691,11 +691,11 @@ func getEvalExpressionTestCases() []varTest {
// nil
{"nil", false, "nil", "nil", "", nil},
{"nil+1", false, "", "", "", fmt.Errorf("operator + can not be applied to \"nil\"")},
{"nil+1", false, "", "", "", errors.New("operator + can not be applied to \"nil\"")},
{"fn1", false, "main.afunc", "main.afunc", "main.functype", nil},
{"fn2", false, "nil", "nil", "main.functype", nil},
{"nilslice", false, "[]int len: 0, cap: 0, nil", "[]int len: 0, cap: 0, nil", "[]int", nil},
{"fn1 == fn2", false, "", "", "", fmt.Errorf("can not compare func variables")},
{"fn1 == fn2", false, "", "", "", errors.New("can not compare func variables")},
{"fn1 == nil", false, "false", "false", "", nil},
{"fn1 != nil", false, "true", "true", "", nil},
{"fn2 == nil", false, "true", "true", "", nil},
@ -713,31 +713,31 @@ func getEvalExpressionTestCases() []varTest {
{"p1 != nil", false, "true", "true", "", nil},
{"ch1 == nil", false, "false", "false", "", nil},
{"chnil == nil", false, "true", "true", "", nil},
{"ch1 == chnil", false, "", "", "", fmt.Errorf("can not compare chan variables")},
{"ch1 == chnil", false, "", "", "", errors.New("can not compare chan variables")},
{"m1 == nil", false, "false", "false", "", nil},
{"mnil == m1", false, "", "", "", fmt.Errorf("can not compare map variables")},
{"mnil == m1", false, "", "", "", errors.New("can not compare map variables")},
{"mnil == nil", false, "true", "true", "", nil},
{"nil == 2", false, "", "", "", fmt.Errorf("can not compare int to nil")},
{"2 == nil", false, "", "", "", fmt.Errorf("can not compare int to nil")},
{"nil == 2", false, "", "", "", errors.New("can not compare int to nil")},
{"2 == nil", false, "", "", "", errors.New("can not compare int to nil")},
// errors
{"&3", false, "", "", "", fmt.Errorf("can not take address of \"3\"")},
{"*3", false, "", "", "", fmt.Errorf("expression \"3\" (int) can not be dereferenced")},
{"&(i2 + i3)", false, "", "", "", fmt.Errorf("can not take address of \"(i2 + i3)\"")},
{"i2 + p1", false, "", "", "", fmt.Errorf("mismatched types \"int\" and \"*int\"")},
{"i2 + f1", false, "", "", "", fmt.Errorf("mismatched types \"int\" and \"float64\"")},
{"i2 << f1", false, "", "", "", fmt.Errorf("shift count type float64, must be unsigned integer")},
{"i2 << -1", false, "", "", "", fmt.Errorf("shift count must not be negative")},
{"*(i2 + i3)", false, "", "", "", fmt.Errorf("expression \"(i2 + i3)\" (int) can not be dereferenced")},
{"i2.member", false, "", "", "", fmt.Errorf("i2 (type int) is not a struct")},
{"fmt.Println(\"hello\")", false, "", "", "", fmt.Errorf("function calls not allowed without using 'call'")},
{"*nil", false, "", "", "", fmt.Errorf("nil can not be dereferenced")},
{"!nil", false, "", "", "", fmt.Errorf("operator ! can not be applied to \"nil\"")},
{"&nil", false, "", "", "", fmt.Errorf("can not take address of \"nil\"")},
{"nil[0]", false, "", "", "", fmt.Errorf("expression \"nil\" (nil) does not support indexing")},
{"nil[2:10]", false, "", "", "", fmt.Errorf("can not slice \"nil\" (type nil)")},
{"nil.member", false, "", "", "", fmt.Errorf("nil (type nil) is not a struct")},
{"(map[string]main.astruct)(0x4000)", false, "", "", "", fmt.Errorf("can not convert \"0x4000\" to map[string]main.astruct")},
{"&3", false, "", "", "", errors.New("can not take address of \"3\"")},
{"*3", false, "", "", "", errors.New("expression \"3\" (int) can not be dereferenced")},
{"&(i2 + i3)", false, "", "", "", errors.New("can not take address of \"(i2 + i3)\"")},
{"i2 + p1", false, "", "", "", errors.New("mismatched types \"int\" and \"*int\"")},
{"i2 + f1", false, "", "", "", errors.New("mismatched types \"int\" and \"float64\"")},
{"i2 << f1", false, "", "", "", errors.New("shift count type float64, must be unsigned integer")},
{"i2 << -1", false, "", "", "", errors.New("shift count must not be negative")},
{"*(i2 + i3)", false, "", "", "", errors.New("expression \"(i2 + i3)\" (int) can not be dereferenced")},
{"i2.member", false, "", "", "", errors.New("i2 (type int) is not a struct")},
{"fmt.Println(\"hello\")", false, "", "", "", errors.New("function calls not allowed without using 'call'")},
{"*nil", false, "", "", "", errors.New("nil can not be dereferenced")},
{"!nil", false, "", "", "", errors.New("operator ! can not be applied to \"nil\"")},
{"&nil", false, "", "", "", errors.New("can not take address of \"nil\"")},
{"nil[0]", false, "", "", "", errors.New("expression \"nil\" (nil) does not support indexing")},
{"nil[2:10]", false, "", "", "", errors.New("can not slice \"nil\" (type nil)")},
{"nil.member", false, "", "", "", errors.New("nil (type nil) is not a struct")},
{"(map[string]main.astruct)(0x4000)", false, "", "", "", errors.New("can not convert \"0x4000\" to map[string]main.astruct")},
// typecasts
{"uint(i2)", false, "2", "2", "uint", nil},