diff options
author | Jan Lindström <jan.lindstrom@mariadb.com> | 2017-05-02 16:31:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 16:31:24 +0300 |
commit | 63e4be267b7b788e24cb564e5e2b8a7f8e0a8284 (patch) | |
tree | 0ba35636cefd0828b2f159921fda8125942f0d3f | |
parent | 2d457843d6331a9faaf13d7948880c503863c57f (diff) | |
parent | bbef7455749e8e02ecbd006326b7fea99a99a5ad (diff) | |
download | mariadb-git-63e4be267b7b788e24cb564e5e2b8a7f8e0a8284.tar.gz |
Merge pull request #362 from grooverdan/10.1-MDEV-XXXX-mysqltest-replace-regex-vars
MDEV-12522: mysqltest replace regex + sys_vars.sysvars_wsrep test to be version independent
-rw-r--r-- | client/mysqltest.cc | 74 | ||||
-rw-r--r-- | mysql-test/r/mysqltest.result | 4 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/r/sysvars_wsrep.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/t/sysvars_wsrep.test | 2 | ||||
-rw-r--r-- | mysql-test/t/mysqltest.test | 4 |
5 files changed, 57 insertions, 29 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 6a92ed0dbc7..7fbe6c3e09b 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -9994,25 +9994,39 @@ bool parse_re_part(char *start_re, char *end_re, Returns: st_replace_regex struct with pairs of substitutions */ +void append_replace_regex(char*, char*, struct st_replace_regex*, char**); struct st_replace_regex* init_replace_regex(char* expr) { + char *expr_end, *buf_p; struct st_replace_regex* res; - char* buf,*expr_end; - char* p, start_re, end_re= 1; - char* buf_p; uint expr_len= strlen(expr); - struct st_regex reg; /* my_malloc() will die on fail with MY_FAE */ res=(struct st_replace_regex*)my_malloc( - sizeof(*res)+expr_len ,MYF(MY_FAE+MY_WME)); + sizeof(*res)+8192 ,MYF(MY_FAE+MY_WME)); my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex), 128, 128, MYF(0)); - buf= (char*)res + sizeof(*res); expr_end= expr + expr_len; + buf_p= (char*)res + sizeof(*res); + append_replace_regex(expr, expr_end, res, &buf_p); + + res->odd_buf_len= res->even_buf_len= 8192; + res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE)); + res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE)); + res->buf= res->even_buf; + + return res; +} + + +void append_replace_regex(char* expr, char *expr_end, struct st_replace_regex* res, + char **buf_p) +{ + char* p, start_re, end_re= 1; + struct st_regex reg; + p= expr; - buf_p= buf; /* for each regexp substitution statement */ while (p < expr_end) @@ -10031,13 +10045,34 @@ struct st_replace_regex* init_replace_regex(char* expr) } start_re= 0; - reg.pattern= buf_p; - if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p)) - goto err; + reg.pattern= *buf_p; + + /* Allow variable for the *entire* list of replacements */ + if (*p == '$') + { + const char *v_end; + VAR *val= var_get(p, &v_end, 0, 1); + + if (val) + { + char *expr, *expr_end; + expr= val->str_val; + expr_end= expr + val->str_val_len; + append_replace_regex(expr, expr_end, res, buf_p); + } + + p= (char *) v_end + 1; + continue; + } + else + { + if (parse_re_part(&start_re, &end_re, &p, expr_end, buf_p)) + goto err; - reg.replace= buf_p; - if (parse_re_part(&start_re, &end_re, &p, expr_end, &buf_p)) - goto err; + reg.replace= *buf_p; + if (parse_re_part(&start_re, &end_re, &p, expr_end, buf_p)) + goto err; + } /* Check if we should do matching case insensitive */ if (p < expr_end && *p == 'i') @@ -10050,17 +10085,12 @@ struct st_replace_regex* init_replace_regex(char* expr) if (insert_dynamic(&res->regex_arr,(uchar*) ®)) die("Out of memory"); } - res->odd_buf_len= res->even_buf_len= 8192; - res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE)); - res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE)); - res->buf= res->even_buf; - return res; + return; err: my_free(res); die("Error parsing replace_regex \"%s\"", expr); - return 0; } /* @@ -10140,12 +10170,6 @@ void do_get_replace_regex(struct st_command *command) { char *expr= command->first_argument; free_replace_regex(); - /* Allow variable for the *entire* list of replacements */ - if (*expr == '$') - { - VAR *val= var_get(expr, NULL, 0, 1); - expr= val ? val->str_val : NULL; - } if (expr && *expr && !(glob_replace_regex=init_replace_regex(expr))) die("Could not init replace_regex"); command->last_argument= command->end; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index fa054d457f9..dcb28baa18d 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -672,7 +672,9 @@ drop table t1; y txt b is b and more is more -txt +txt2 +b is b or more is more +txt3 a is a and less is more sflfdt 'ABCDfF bbddff h' bs txt; txt diff --git a/mysql-test/suite/sys_vars/r/sysvars_wsrep.result b/mysql-test/suite/sys_vars/r/sysvars_wsrep.result index 802ee3b1c6d..68ab8bd27a0 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_wsrep.result +++ b/mysql-test/suite/sys_vars/r/sysvars_wsrep.result @@ -367,7 +367,7 @@ READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME WSREP_PATCH_VERSION SESSION_VALUE NULL -GLOBAL_VALUE wsrep_25.19 +GLOBAL_VALUE wsrep_MAJVER.MINVER GLOBAL_VALUE_ORIGIN COMPILE-TIME DEFAULT_VALUE NULL VARIABLE_SCOPE GLOBAL diff --git a/mysql-test/suite/sys_vars/t/sysvars_wsrep.test b/mysql-test/suite/sys_vars/t/sysvars_wsrep.test index 700b129fd62..c127115efe1 100644 --- a/mysql-test/suite/sys_vars/t/sysvars_wsrep.test +++ b/mysql-test/suite/sys_vars/t/sysvars_wsrep.test @@ -5,7 +5,7 @@ --replace_result $datadir DATADIR --let $hostname_regex=/^$hostname\$/HOSTNAME/ ---replace_regex $hostname_regex +--replace_regex $hostname_regex /wsrep_[0-9]{2}\.[0-9]{1,2}/wsrep_MAJVER.MINVER/ --vertical_results select * from information_schema.system_variables where variable_name like 'wsrep%' diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 1e7d8a6a8ca..d1851836893 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -2082,9 +2082,11 @@ drop table t1; --let $patt= /a /b / /less/more/ --replace_regex $patt select "a is a and less is more" as txt; +--replace_regex $patt /and /or / +select "a is a and less is more" as txt2; --let $patt= --replace_regex $patt -select "a is a and less is more" as txt; +select "a is a and less is more" as txt3; --enable_query_log # |