Commit fe3ea31d authored by Bjorn Munch's avatar Bjorn Munch

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
parent d4854d74
...@@ -417,6 +417,7 @@ static struct st_expected_errors saved_expected_errors; ...@@ -417,6 +417,7 @@ static struct st_expected_errors saved_expected_errors;
struct st_command struct st_command
{ {
char *query, *query_buf,*first_argument,*last_argument,*end; char *query, *query_buf,*first_argument,*last_argument,*end;
DYNAMIC_STRING content;
int first_word_len, query_len; int first_word_len, query_len;
my_bool abort_on_error; my_bool abort_on_error;
struct st_expected_errors expected_errors; struct st_expected_errors expected_errors;
...@@ -1138,6 +1139,8 @@ void free_used_memory() ...@@ -1138,6 +1139,8 @@ void free_used_memory()
{ {
struct st_command **q= dynamic_element(&q_lines, i, struct st_command**); struct st_command **q= dynamic_element(&q_lines, i, struct st_command**);
my_free((*q)->query_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free((*q)->query_buf,MYF(MY_ALLOW_ZERO_PTR));
if ((*q)->content.str)
dynstr_free(&(*q)->content);
my_free((*q),MYF(0)); my_free((*q),MYF(0));
} }
for (i= 0; i < 10; i++) for (i= 0; i < 10; i++)
...@@ -3283,21 +3286,30 @@ void do_write_file_command(struct st_command *command, my_bool append) ...@@ -3283,21 +3286,30 @@ void do_write_file_command(struct st_command *command, my_bool append)
sizeof(write_file_args)/sizeof(struct command_arg), 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) if (!append && access(ds_filename.str, F_OK) == 0)
{ {
/* The file should not be overwritten */ /* The file should not be overwritten */
die("File already exist: '%s'", ds_filename.str); die("File already exist: '%s'", ds_filename.str);
} }
init_dynamic_string(&ds_content, "", 1024, 1024); ds_content= command->content;
read_until_delimiter(&ds_content, &ds_delimiter); /* If it hasn't been done already by a loop iteration, fill it in */
DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str)); if (! ds_content.str)
str_to_file2(ds_filename.str, ds_content.str, ds_content.length, append); {
dynstr_free(&ds_content); /* 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_filename);
dynstr_free(&ds_delimiter); dynstr_free(&ds_delimiter);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -7684,7 +7696,31 @@ int main(int argc, char **argv) ...@@ -7684,7 +7696,31 @@ int main(int argc, char **argv)
command->type= Q_COMMENT; 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; command->last_argument= command->first_argument;
processed = 1; processed = 1;
......
...@@ -314,21 +314,10 @@ here is the sourced script ...@@ -314,21 +314,10 @@ here is the sourced script
1 = outer loop variable before dec 1 = outer loop variable before dec
0 = outer loop variable after dec 0 = outer loop variable after dec
outer=2 ifval=0
2 = outer loop variable after while outer=1 ifval=1
here is the sourced script 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 In loop
here is the sourced script here is the sourced script
...@@ -538,6 +527,10 @@ mysqltest: At line 1: Missing required argument 'filename' to command 'write_fil ...@@ -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 mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found
Content for test_file1 Content for test_file1
mysqltest: At line 1: File already exist: 'MYSQLTEST_VARDIR/tmp/test_file1.tmp' 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 Some data
for cat_file command for cat_file command
of mysqltest of mysqltest
......
...@@ -853,16 +853,18 @@ while ($outer) ...@@ -853,16 +853,18 @@ while ($outer)
eval SELECT '$outer = outer loop variable after dec' AS ""; 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 $outer= 2; # Number of outer loops
let $ifval= 0; # false 1st time
while ($outer) 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; dec $outer;
eval SELECT '$outer = outer loop variable after dec' AS ""; inc $ifval;
} }
...@@ -1663,6 +1665,20 @@ EOF ...@@ -1663,6 +1665,20 @@ EOF
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; 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 # test for cat_file
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment