From b5abfb57d262abc31440a886499ad1f2651f2a04 Mon Sep 17 00:00:00 2001 From: tjk Date: Sun, 28 Feb 2021 10:07:10 +0800 Subject: [PATCH] fix err check --- types/convert_test.go | 6 ++- types/datum_test.go | 5 ++- types/mydecimal_benchmark_test.go | 20 +++++++-- types/mydecimal_test.go | 75 ++++++++++++++++++++----------- types/time_test.go | 18 ++++++-- 5 files changed, 86 insertions(+), 38 deletions(-) diff --git a/types/convert_test.go b/types/convert_test.go index 1015972b095ba..9c3326a7ae846 100644 --- a/types/convert_test.go +++ b/types/convert_test.go @@ -763,8 +763,10 @@ func (s *testTypeConvertSuite) TestConvert(c *C) { signedAccept(c, mysql.TypeNewDecimal, "-123.456", "-123.456") signedAccept(c, mysql.TypeNewDecimal, NewDecFromInt(12300000), "12300000") dec := NewDecFromInt(-123) - dec.Shift(-5) - dec.Round(dec, 5, ModeHalfEven) + err := dec.Shift(-5) + c.Assert(err, IsNil) + err = dec.Round(dec, 5, ModeHalfEven) + c.Assert(err, IsNil) signedAccept(c, mysql.TypeNewDecimal, dec, "-0.00123") } diff --git a/types/datum_test.go b/types/datum_test.go index 138bbd2e2c041..ef3dc177b0a16 100644 --- a/types/datum_test.go +++ b/types/datum_test.go @@ -533,7 +533,10 @@ func BenchmarkCompareDatum(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { for j, v := range vals { - v.CompareDatum(sc, &vals1[j]) + _, err := v.CompareDatum(sc, &vals1[j]) + if err != nil { + b.Fatal(err) + } } } } diff --git a/types/mydecimal_benchmark_test.go b/types/mydecimal_benchmark_test.go index 3c484799f8caa..fc2d05aafeb95 100644 --- a/types/mydecimal_benchmark_test.go +++ b/types/mydecimal_benchmark_test.go @@ -41,19 +41,31 @@ func BenchmarkRound(b *testing.B) { } for i := 0; i < len(tests); i++ { - tests[i].inputDec.FromString([]byte(tests[i].input)) + err := tests[i].inputDec.FromString([]byte(tests[i].input)) + if err != nil { + b.Fatal(err) + } } b.StartTimer() for n := 0; n < b.N; n++ { for i := 0; i < len(tests); i++ { - tests[i].inputDec.Round(&roundTo, tests[i].scale, ModeHalfEven) + err := tests[i].inputDec.Round(&roundTo, tests[i].scale, ModeHalfEven) + if err != nil { + b.Fatal(err) + } } for i := 0; i < len(tests); i++ { - tests[i].inputDec.Round(&roundTo, tests[i].scale, ModeTruncate) + err := tests[i].inputDec.Round(&roundTo, tests[i].scale, ModeTruncate) + if err != nil { + b.Fatal(err) + } } for i := 0; i < len(tests); i++ { - tests[i].inputDec.Round(&roundTo, tests[i].scale, modeCeiling) + err := tests[i].inputDec.Round(&roundTo, tests[i].scale, modeCeiling) + if err != nil { + b.Fatal(err) + } } } } diff --git a/types/mydecimal_test.go b/types/mydecimal_test.go index 215d12bbb0747..fbad96a624365 100644 --- a/types/mydecimal_test.go +++ b/types/mydecimal_test.go @@ -82,7 +82,8 @@ func (s *testMyDecimalSuite) TestToInt(c *C) { } for _, tt := range tests { var dec MyDecimal - dec.FromString([]byte(tt.input)) + err := dec.FromString([]byte(tt.input)) + c.Assert(err, IsNil) result, ec := dec.ToInt() c.Check(ec, Equals, tt.err) c.Check(result, Equals, tt.output) @@ -106,7 +107,8 @@ func (s *testMyDecimalSuite) TestToUint(c *C) { } for _, tt := range tests { var dec MyDecimal - dec.FromString([]byte(tt.input)) + err := dec.FromString([]byte(tt.input)) + c.Assert(err, IsNil) result, ec := dec.ToUint() c.Check(ec, Equals, tt.err) c.Check(result, Equals, tt.output) @@ -144,7 +146,8 @@ func (s *testMyDecimalSuite) TestToFloat(c *C) { } for _, ca := range tests { var dec MyDecimal - dec.FromString([]byte(ca.s)) + err := dec.FromString([]byte(ca.s)) + c.Assert(err, IsNil) f, err := dec.ToFloat64() c.Check(err, IsNil) c.Check(f, Equals, ca.f) @@ -402,9 +405,10 @@ func (s *testMyDecimalSuite) TestRoundWithHalfEven(c *C) { for _, ca := range tests { var dec MyDecimal - dec.FromString([]byte(ca.input)) + err := dec.FromString([]byte(ca.input)) + c.Assert(err, IsNil) var rounded MyDecimal - err := dec.Round(&rounded, ca.scale, ModeHalfEven) + err = dec.Round(&rounded, ca.scale, ModeHalfEven) c.Check(err, Equals, ca.err) result := rounded.ToString() c.Check(string(result), Equals, ca.output) @@ -436,9 +440,10 @@ func (s *testMyDecimalSuite) TestRoundWithTruncate(c *C) { } for _, ca := range tests { var dec MyDecimal - dec.FromString([]byte(ca.input)) + err := dec.FromString([]byte(ca.input)) + c.Assert(err, IsNil) var rounded MyDecimal - err := dec.Round(&rounded, ca.scale, ModeTruncate) + err = dec.Round(&rounded, ca.scale, ModeTruncate) c.Check(err, Equals, ca.err) result := rounded.ToString() c.Check(string(result), Equals, ca.output) @@ -471,9 +476,10 @@ func (s *testMyDecimalSuite) TestRoundWithCeil(c *C) { } for _, ca := range tests { var dec MyDecimal - dec.FromString([]byte(ca.input)) + err := dec.FromString([]byte(ca.input)) + c.Assert(err, IsNil) var rounded MyDecimal - err := dec.Round(&rounded, ca.scale, modeCeiling) + err = dec.Round(&rounded, ca.scale, modeCeiling) c.Check(err, Equals, ca.err) result := rounded.ToString() c.Check(string(result), Equals, ca.output) @@ -544,7 +550,8 @@ func (s *testMyDecimalSuite) TestToString(c *C) { } for _, ca := range tests { var dec MyDecimal - dec.FromString([]byte(ca.input)) + err := dec.FromString([]byte(ca.input)) + c.Assert(err, IsNil) result := dec.ToString() c.Check(string(result), Equals, ca.output) } @@ -641,8 +648,10 @@ func (s *testMyDecimalSuite) TestCompare(c *C) { } for _, tt := range tests { var a, b MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) c.Assert(a.Compare(&b), Equals, tt.cmp) } } @@ -759,9 +768,11 @@ func (s *testMyDecimalSuite) TestSub(c *C) { } for _, tt := range tests { var a, b, sum MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) - err := DecimalSub(&a, &b, &sum) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) + err = DecimalSub(&a, &b, &sum) c.Assert(err, Equals, tt.err) result := sum.ToString() c.Assert(string(result), Equals, tt.result) @@ -791,9 +802,11 @@ func (s *testMyDecimalSuite) TestMul(c *C) { } for _, tt := range tests { var a, b, product MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) - err := DecimalMul(&a, &b, &product) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) + err = DecimalMul(&a, &b, &product) c.Check(err, Equals, tt.err) result := product.String() c.Assert(result, Equals, tt.result) @@ -826,9 +839,11 @@ func (s *testMyDecimalSuite) TestDivMod(c *C) { } for _, tt := range tests { var a, b, to MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) - err := DecimalDiv(&a, &b, &to, 5) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) + err = DecimalDiv(&a, &b, &to, 5) c.Check(err, Equals, tt.err) if tt.err == ErrDivByZero { continue @@ -849,8 +864,10 @@ func (s *testMyDecimalSuite) TestDivMod(c *C) { } for _, tt := range tests { var a, b, to MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) ec := DecimalMod(&a, &b, &to) c.Check(ec, Equals, tt.err) if tt.err == ErrDivByZero { @@ -870,8 +887,10 @@ func (s *testMyDecimalSuite) TestDivMod(c *C) { } for _, tt := range tests { var a, b, to MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) ec := DecimalDiv(&a, &b, &to, DivFracIncr) c.Check(ec, Equals, tt.err) if tt.err == ErrDivByZero { @@ -888,8 +907,10 @@ func (s *testMyDecimalSuite) TestDivMod(c *C) { } for _, tt := range tests { var a, b, to MyDecimal - a.FromString([]byte(tt.a)) - b.FromString([]byte(tt.b)) + err := a.FromString([]byte(tt.a)) + c.Assert(err, IsNil) + err = b.FromString([]byte(tt.b)) + c.Assert(err, IsNil) ec := DecimalMod(&a, &b, &to) c.Check(ec, Equals, tt.err) if tt.err == ErrDivByZero { diff --git a/types/time_test.go b/types/time_test.go index 9dc3c4851e486..6d294494b0082 100644 --- a/types/time_test.go +++ b/types/time_test.go @@ -1139,7 +1139,8 @@ func (s *testTimeSuite) TestConvertTimeZone(c *C) { for _, test := range tests { t := types.NewTime(test.input, 0, 0) - t.ConvertTimeZone(test.from, test.to) + err := t.ConvertTimeZone(test.from, test.to) + c.Assert(err, IsNil) c.Assert(t.Compare(types.NewTime(test.expect, 0, 0)), Equals, 0) } } @@ -2023,7 +2024,10 @@ func (s *testTimeSuite) TestParseWithTimezone(c *C) { func BenchmarkFormat(b *testing.B) { t1 := types.NewTime(types.FromGoTime(time.Now()), mysql.TypeTimestamp, 0) for i := 0; i < b.N; i++ { - t1.DateFormat("%Y-%m-%d %H:%i:%s") + _, err := t1.DateFormat("%Y-%m-%d %H:%i:%s") + if err != nil { + b.Fatal(err) + } } } @@ -2034,7 +2038,10 @@ func BenchmarkTimeAdd(b *testing.B) { arg1, _ := types.ParseTime(sc, "2017-01-18", mysql.TypeDatetime, types.MaxFsp) arg2, _ := types.ParseDuration(sc, "12:30:59", types.MaxFsp) for i := 0; i < b.N; i++ { - arg1.Add(sc, arg2) + _, err := arg1.Add(sc, arg2) + if err != nil { + b.Fatal(err) + } } } @@ -2093,7 +2100,10 @@ func BenchmarkParseDateFormat(b *testing.B) { func benchmarkDatetimeFormat(b *testing.B, name string, sc *stmtctx.StatementContext, str string) { b.Run(name, func(b *testing.B) { for i := 0; i < b.N; i++ { - types.ParseDatetime(sc, str) + _, err := types.ParseDatetime(sc, str) + if err != nil { + b.Fatal(err) + } } }) }