pingcap / mysql-tester

A Golang implementation of MySQL Test Framework
Apache License 2.0
61 stars 62 forks source link

Fix line numbers of input file #36

Closed dveeden closed 2 years ago

dveeden commented 2 years ago

The line numbers in the error messages were not correct.

Closes #19

This is because loadQueries() was sending []string to ParseQueries(), which would number them and assign line numbers based on this. However as loadQueries() is filtering out lines that start with # and combines multi-line statements into a single query this doesn't match with line numbers.

Solution: Have loadQueries() send []query instead of []string to ParseQueries(), which has the query string in query.Query and the line number in query.Line.

Original behavior:

$ ./mysql-tester --port=4001 --log-level=debug role
INFO[0000] running tests: [role]                        
WARN[0000] Create new db&{0 {root:@tcp(127.0.0.1:4001)/test?strict=true&time_zone=%27Asia%2FShanghai%27 0x1059168} 0 {0 0} [0xc00016c5a0] map[] 0 1 0xc000096120 false map[0xc00016c5a0:map[0xc00016c5a0:true]] map[] 0 0 0 0 <nil> 0 0 0 0 0x49cec0} 
FATA[0000] run test [role] err: sql:CREATE ROLE `ident with space`;: run "CREATE ROLE `ident with space`;" at line 5 err Error 1396: Operation CREATE ROLE failed for 'ident with space'@'%' 
$ sed -n '1,7p' t/role.test | nl
     1  # call mtr.add_suppression(".* Failed to activate default role .*");
     2  --echo # test CREATE ROLE and variations of authorizationID:
     3  --echo # WL988.I-1
     4  --echo # Role is not a reserved keyword
     5  CREATE ROLE `role`;
     6  DROP ROLE `role`;
     7  CREATE ROLE `ident with space`;

So it reports at line 5, while the statement that has the issue is actually on line 7 of the test file.

With this PR:

$ ./mysql-tester --port=4001 --log-level=debug role
INFO[0000] running tests: [role]                        
WARN[0000] Create new db&{0 {root:@tcp(127.0.0.1:4001)/test?strict=true&time_zone=%27Asia%2FShanghai%27 0x1059168} 0 {0 0} [0xc0001b8870] map[] 0 1 0xc0000321e0 false map[0xc0001b8870:map[0xc0001b8870:true]] map[] 0 0 0 0 <nil> 0 0 0 0 0x49cec0} 
FATA[0000] run test [role] err: sql:CREATE ROLE `ident with space`;: run "CREATE ROLE `ident with space`;" at line 7 err Error 1396: Operation CREATE ROLE failed for 'ident with space'@'%' 
[dvaneeden@dve-carbon mysql_test]$ sed -n '7p' t/role.test 
CREATE ROLE `ident with space`;
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

dveeden commented 2 years ago

/cc @morgo @zz-jason

dveeden commented 2 years ago

/cc @bb7133