diff --git a/expression/integration_test.go b/expression/integration_test.go index 8a22f8a8945cc..52330581451ca 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -1457,7 +1457,7 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { for _, errPeriod := range []string{ "period_add(0, 20)", "period_add(0, 0)", "period_add(-1, 1)", "period_add(200013, 1)", "period_add(-200012, 1)", "period_add('', '')", } { - _, err := tk.Exec(fmt.Sprintf("SELECT %v;", errPeriod)) + err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod)) c.Assert(err.Error(), Equals, "[expression:1210]Incorrect arguments to period_add") } diff --git a/util/testkit/testkit.go b/util/testkit/testkit.go index ca12e8a83cd3f..551a5da76d69d 100644 --- a/util/testkit/testkit.go +++ b/util/testkit/testkit.go @@ -180,6 +180,17 @@ func (tk *TestKit) MustQuery(sql string, args ...interface{}) *Result { return tk.ResultSetToResult(rs, comment) } +// QueryToErr executes a sql statement and discard results. +func (tk *TestKit) QueryToErr(sql string, args ...interface{}) error { + comment := check.Commentf("sql:%s, args:%v", sql, args) + res, err := tk.Exec(sql, args...) + tk.c.Assert(errors.ErrorStack(err), check.Equals, "", comment) + tk.c.Assert(res, check.NotNil, comment) + _, resErr := session.GetRows4Test(context.Background(), tk.Se, res) + tk.c.Assert(res.Close(), check.IsNil) + return resErr +} + // ResultSetToResult converts sqlexec.RecordSet to testkit.Result. // It is used to check results of execute statement in binary mode. func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment check.CommentInterface) *Result {