Skip to content

Commit 4ee6e97

Browse files
author
Pavan Naik
committed
BUG#11766444 : MTR PRINTS WRONG FILE AND LINE NUMBER WHEN TESTS FAIL
Description : ============= When a test case fails, MTR sometimes prints the wrong line number. This happens if a test case fails inside a while loop and it is not the first iteration of the loop. E.g: ---- --let $i = 2 while ($i) { dec $i; if (!$i) { execute this invalid query; } } When executing the above test case, MTR fails with the following message: mysqltest: At line 9: query 'execute this invalid query' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'invalid query' at line 1 Note that the error was on line 7 but the test reports line 9. Issue : ======= The variable 'start_lineno' keeping track of the current line number in a test is not updated after the first iteration and hence printing the line number of the last line of the loop. Fix : ===== Introduced a new variable 'lineno' in 'st_command' structure to keep track of the the line number for each command. During the iteration after the first one, use this variable to update the 'start_lineno' variable to the current line number. Reviewed-by: Deepa Dixit <[email protected]> Reviewed-by: Srikanth B R <[email protected]> RB: 16015
1 parent 34dfb24 commit 4ee6e97

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

client/mysqltest.cc

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ struct st_command
572572
struct st_expected_errors expected_errors;
573573
char output_file[FN_REFLEN];
574574
enum enum_commands type;
575+
// Line number of the command
576+
uint lineno;
575577
};
576578

577579
TYPELIB command_typelib= {array_elements(command_names),"",
@@ -7368,37 +7370,38 @@ static bool is_delimiter(const char* p)
73687370
}
73697371

73707372

7371-
/*
7372-
Create a command from a set of lines
7373-
7374-
SYNOPSIS
7375-
read_command()
7376-
command_ptr pointer where to return the new query
7377-
7378-
DESCRIPTION
7379-
Converts lines returned by read_line into a command, this involves
7380-
parsing the first word in the read line to find the command type.
7381-
7382-
A -- comment may contain a valid query as the first word after the
7383-
comment start. Thus it's always checked to see if that is the case.
7384-
The advantage with this approach is to be able to execute commands
7385-
terminated by new line '\n' regardless how many "delimiter" it contain.
7386-
*/
7387-
7388-
#define MAX_QUERY (256*1024*2) /* 256K -- a test in sp-big is >128K */
7373+
// 256K -- a test in sp-big is >128K
7374+
#define MAX_QUERY (256*1024*2)
73897375
static char read_command_buf[MAX_QUERY];
73907376

7377+
/// Create a command from a set of lines.
7378+
///
7379+
/// Converts lines returned by read_line into a command, this involves
7380+
/// parsing the first word in the read line to find the command type.
7381+
///
7382+
/// A '`--`' comment may contain a valid query as the first word after
7383+
/// the comment start. Thus it's always checked to see if that is the
7384+
/// case. The advantage with this approach is to be able to execute
7385+
/// commands terminated by new line '\n' regardless how many "delimiter"
7386+
/// it contain.
7387+
///
7388+
/// @param [in] command_ptr pointer where to return the new query
7389+
///
7390+
/// @retval 0 on success, else 1
73917391
static int read_command(struct st_command** command_ptr)
73927392
{
73937393
char *p= read_command_buf;
7394-
struct st_command* command;
73957394
DBUG_ENTER("read_command");
73967395

73977396
if (parser.current_line < parser.read_lines)
73987397
{
73997398
*command_ptr= q_lines->at(parser.current_line);
7399+
// Assign the current command line number
7400+
start_lineno= (*command_ptr)->lineno;
74007401
DBUG_RETURN(0);
74017402
}
7403+
7404+
struct st_command* command;
74027405
if (!(*command_ptr= command=
74037406
(struct st_command*) my_malloc(PSI_NOT_INSTRUMENTED,
74047407
sizeof(*command),
@@ -7414,6 +7417,9 @@ static int read_command(struct st_command** command_ptr)
74147417
DBUG_RETURN(1);
74157418
}
74167419

7420+
// Set the line number for the command
7421+
command->lineno= start_lineno;
7422+
74177423
if (opt_result_format_version == 1)
74187424
convert_to_format_v1(read_command_buf);
74197425

@@ -7425,24 +7431,24 @@ static int read_command(struct st_command** command_ptr)
74257431
else if (p[0] == '-' && p[1] == '-')
74267432
{
74277433
command->type= Q_COMMENT_WITH_COMMAND;
7428-
p+= 2; /* Skip past -- */
7434+
// Skip past '--'
7435+
p+= 2;
74297436
}
74307437
else if (*p == '\n')
74317438
{
74327439
command->type= Q_EMPTY_LINE;
74337440
}
74347441

7435-
/* Skip leading spaces */
7442+
// Skip leading spaces
74367443
while (*p && my_isspace(charset_info, *p))
74377444
p++;
74387445

74397446
if (!(command->query_buf= command->query= my_strdup(PSI_NOT_INSTRUMENTED,
74407447
p, MYF(MY_WME))))
74417448
die("Out of memory");
74427449

7443-
/*
7444-
Calculate first word length(the command), terminated
7445-
by 'space' , '(' or 'delimiter' */
7450+
// Calculate first word length(the command), terminated
7451+
// by 'space' , '(' or 'delimiter'
74467452
p= command->query;
74477453
while (*p && !my_isspace(charset_info, *p) && *p != '(' && !is_delimiter(p))
74487454
p++;
@@ -7451,7 +7457,7 @@ static int read_command(struct st_command** command_ptr)
74517457
static_cast<int>(command->first_word_len),
74527458
command->query));
74537459

7454-
/* Skip spaces between command and first argument */
7460+
// Skip spaces between command and first argument
74557461
while (*p && my_isspace(charset_info, *p))
74567462
p++;
74577463
command->first_argument= p;

mysql-test/r/mysqltest.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,3 +1526,7 @@ Hello
15261526
# Outer while condition evalutes to false
15271527
# "Hello" shouldn't be repeated
15281528
Hello
1529+
#
1530+
# BUG#11766444 : MTR PRINTS WRONG FILE AND LINE NUMBER WHEN TESTS FAIL
1531+
#
1532+
mysqltest: At line 7: query 'execute this invalid query' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'invalid query' at line 1

mysql-test/t/mysqltest.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,3 +3874,26 @@ while (0)
38743874

38753875
# Cleanup
38763876
--remove_file $MYSQL_TMP_DIR/bug25840940.inc
3877+
3878+
--echo #
3879+
--echo # BUG#11766444 : MTR PRINTS WRONG FILE AND LINE NUMBER WHEN TESTS FAIL
3880+
--echo #
3881+
3882+
--write_file $MYSQLTEST_VARDIR/tmp/bug11766444.test
3883+
--let $counter= 2
3884+
while ($counter)
3885+
{
3886+
--dec $counter
3887+
if (!$counter)
3888+
{
3889+
execute this invalid query;
3890+
}
3891+
}
3892+
EOF
3893+
3894+
# Invalid query at line 7
3895+
--error 1
3896+
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11766444.test 2>&1
3897+
3898+
# Cleanup
3899+
--remove_file $MYSQLTEST_VARDIR/tmp/bug11766444.test

0 commit comments

Comments
 (0)