mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
Bug #32296 mysqltest fails to parse "append_file" inside a "while", it works inside
a "if" Bug #41913 mysqltest cannot source files from if inside while Some commands require additional processing which only works first time Keep content for write_file or append_file with the st_command struct Add tests for those cases to mysqltest.test
This commit is contained in:
parent
d4854d7494
commit
fe3ea31d93
3 changed files with 73 additions and 28 deletions
|
@ -417,6 +417,7 @@ static struct st_expected_errors saved_expected_errors;
|
|||
struct st_command
|
||||
{
|
||||
char *query, *query_buf,*first_argument,*last_argument,*end;
|
||||
DYNAMIC_STRING content;
|
||||
int first_word_len, query_len;
|
||||
my_bool abort_on_error;
|
||||
struct st_expected_errors expected_errors;
|
||||
|
@ -1138,6 +1139,8 @@ void free_used_memory()
|
|||
{
|
||||
struct st_command **q= dynamic_element(&q_lines, i, struct st_command**);
|
||||
my_free((*q)->query_buf,MYF(MY_ALLOW_ZERO_PTR));
|
||||
if ((*q)->content.str)
|
||||
dynstr_free(&(*q)->content);
|
||||
my_free((*q),MYF(0));
|
||||
}
|
||||
for (i= 0; i < 10; i++)
|
||||
|
@ -3283,21 +3286,30 @@ void do_write_file_command(struct st_command *command, my_bool append)
|
|||
sizeof(write_file_args)/sizeof(struct command_arg),
|
||||
' ');
|
||||
|
||||
/* If no delimiter was provided, use EOF */
|
||||
if (ds_delimiter.length == 0)
|
||||
dynstr_set(&ds_delimiter, "EOF");
|
||||
|
||||
if (!append && access(ds_filename.str, F_OK) == 0)
|
||||
{
|
||||
/* The file should not be overwritten */
|
||||
die("File already exist: '%s'", ds_filename.str);
|
||||
}
|
||||
|
||||
init_dynamic_string(&ds_content, "", 1024, 1024);
|
||||
read_until_delimiter(&ds_content, &ds_delimiter);
|
||||
DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str));
|
||||
str_to_file2(ds_filename.str, ds_content.str, ds_content.length, append);
|
||||
dynstr_free(&ds_content);
|
||||
ds_content= command->content;
|
||||
/* If it hasn't been done already by a loop iteration, fill it in */
|
||||
if (! ds_content.str)
|
||||
{
|
||||
/* If no delimiter was provided, use EOF */
|
||||
if (ds_delimiter.length == 0)
|
||||
dynstr_set(&ds_delimiter, "EOF");
|
||||
|
||||
init_dynamic_string(&ds_content, "", 1024, 1024);
|
||||
read_until_delimiter(&ds_content, &ds_delimiter);
|
||||
command->content= ds_content;
|
||||
}
|
||||
/* This function could be called even if "false", so check before printing */
|
||||
if (cur_block->ok)
|
||||
{
|
||||
DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str));
|
||||
str_to_file2(ds_filename.str, ds_content.str, ds_content.length, append);
|
||||
}
|
||||
dynstr_free(&ds_filename);
|
||||
dynstr_free(&ds_delimiter);
|
||||
DBUG_VOID_RETURN;
|
||||
|
@ -7684,7 +7696,31 @@ int main(int argc, char **argv)
|
|||
command->type= Q_COMMENT;
|
||||
}
|
||||
|
||||
if (cur_block->ok)
|
||||
my_bool ok_to_do= cur_block->ok;
|
||||
/*
|
||||
Some commands need to be "done" the first time if they may get
|
||||
re-iterated over in a true context. This can only happen if there's
|
||||
a while loop at some level above the current block.
|
||||
*/
|
||||
if (!ok_to_do)
|
||||
{
|
||||
if (command->type == Q_SOURCE ||
|
||||
command->type == Q_WRITE_FILE ||
|
||||
command->type == Q_APPEND_FILE ||
|
||||
command->type == Q_PERL)
|
||||
{
|
||||
for (struct st_block *stb= cur_block-1; stb >= block_stack; stb--)
|
||||
{
|
||||
if (stb->cmd == cmd_while)
|
||||
{
|
||||
ok_to_do= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ok_to_do)
|
||||
{
|
||||
command->last_argument= command->first_argument;
|
||||
processed = 1;
|
||||
|
|
|
@ -314,21 +314,10 @@ here is the sourced script
|
|||
1 = outer loop variable before dec
|
||||
|
||||
0 = outer loop variable after dec
|
||||
|
||||
2 = outer loop variable after while
|
||||
outer=2 ifval=0
|
||||
outer=1 ifval=1
|
||||
here is the sourced script
|
||||
|
||||
2 = outer loop variable before dec
|
||||
|
||||
1 = outer loop variable after dec
|
||||
|
||||
1 = outer loop variable after while
|
||||
here is the sourced script
|
||||
|
||||
1 = outer loop variable before dec
|
||||
|
||||
0 = outer loop variable after dec
|
||||
|
||||
In loop
|
||||
here is the sourced script
|
||||
|
||||
|
@ -538,6 +527,10 @@ mysqltest: At line 1: Missing required argument 'filename' to command 'write_fil
|
|||
mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found
|
||||
Content for test_file1
|
||||
mysqltest: At line 1: File already exist: 'MYSQLTEST_VARDIR/tmp/test_file1.tmp'
|
||||
These lines should be repeated,
|
||||
if things work as expected
|
||||
These lines should be repeated,
|
||||
if things work as expected
|
||||
Some data
|
||||
for cat_file command
|
||||
of mysqltest
|
||||
|
|
|
@ -853,16 +853,18 @@ while ($outer)
|
|||
eval SELECT '$outer = outer loop variable after dec' AS "";
|
||||
}
|
||||
|
||||
# Test source in an if in a while which is false on 1st iteration
|
||||
let $outer= 2; # Number of outer loops
|
||||
let $ifval= 0; # false 1st time
|
||||
while ($outer)
|
||||
{
|
||||
eval SELECT '$outer = outer loop variable after while' AS "";
|
||||
echo outer=$outer ifval=$ifval;
|
||||
|
||||
echo here is the sourced script;
|
||||
|
||||
eval SELECT '$outer = outer loop variable before dec' AS "";
|
||||
if ($ifval) {
|
||||
--source $MYSQLTEST_VARDIR/tmp/sourced.inc
|
||||
}
|
||||
dec $outer;
|
||||
eval SELECT '$outer = outer loop variable after dec' AS "";
|
||||
inc $ifval;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1663,6 +1665,20 @@ EOF
|
|||
|
||||
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
|
||||
|
||||
# Test append_file within while
|
||||
let $outer= 2; # Number of outer loops
|
||||
while ($outer)
|
||||
{
|
||||
append_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
|
||||
These lines should be repeated,
|
||||
if things work as expected
|
||||
EOF
|
||||
dec $outer;
|
||||
}
|
||||
|
||||
cat_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
|
||||
remove_file $MYSQLTEST_VARDIR/tmp/app_while.tmp;
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# test for cat_file
|
||||
# ----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue