diff --git a/client/mysqltest.c b/client/mysqltest.c index d733ab58243..a02fdf30601 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -199,6 +199,7 @@ Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG, Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER, Q_WAIT_FOR_SLAVE_TO_STOP, Q_REQUIRE_VERSION, +Q_EXEC, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ Q_COMMENT_WITH_COMMAND @@ -264,6 +265,7 @@ const char *command_names[]= "require_manager", "wait_for_slave_to_stop", "require_version", + "exec", 0 }; @@ -821,6 +823,66 @@ int do_source(struct st_query* q) return open_file(name); } +/* + Execute given command. + + SYNOPSIS + do_exec() + q called command + + DESCRIPTION + If one uses --exec command [args] command in .test file + we will execute the command and record its output. + + RETURN VALUES + 0 ok + 1 error +*/ + +int do_exec(struct st_query* q) +{ + int error= 0; + DYNAMIC_STRING *ds; + DYNAMIC_STRING ds_tmp; + char buf[1024]; + FILE *res_file; + char *cmd= q->first_argument; + + while (*cmd && isspace(*cmd)) + cmd++; + if (!*cmd) + die("Missing argument in exec\n"); + + if (q->record_file[0]) + { + init_dynamic_string(&ds_tmp, "", 16384, 65536); + ds= &ds_tmp; + } + else + ds= &ds_res; + + if (!(res_file= popen(cmd, "r")) && q->abort_on_error) + die("popen() failed\n"); + while (fgets(buf, sizeof(buf), res_file)) + dynstr_append(ds, buf); + pclose(res_file); + if (record) + { + if (!q->record_file[0] && !result_file) + die("At line %u: Missing result file", start_lineno); + if (!result_file) + str_to_file(q->record_file, ds->str, ds->length); + } + else if (q->record_file[0]) + { + error= check_result(ds, q->record_file, q->require_file); + } + if (ds == &ds_tmp) + dynstr_free(&ds_tmp); + + return error; +} + int var_query_set(VAR* v, const char* p, const char** p_end) { char* end = (char*)((p_end && *p_end) ? *p_end : p + strlen(p)); @@ -2469,6 +2531,9 @@ int main(int argc, char** argv) case Q_PING: (void) mysql_ping(&cur_con->mysql); break; + case Q_EXEC: + (void) do_exec(q); + break; default: processed = 0; break; } } diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 1d1293f81d2..a2643e84d9f 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -428,6 +428,11 @@ if [ x$SOURCE_DIST = x1 ] ; then else MYSQL_TEST="$BASEDIR/client/mysqltest" fi + if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then + MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" + else + MYSQL_DUMP="$BASEDIR/client/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" + fi if [ -n "$STRACE_CLIENT" ]; then MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST" fi @@ -449,6 +454,7 @@ else MYSQLD="$VALGRIND $BASEDIR/bin/mysqld" fi MYSQL_TEST="$BASEDIR/bin/mysqltest" + MYSQL_DUMP="$BASEDIR/bin/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" MYSQLADMIN="$BASEDIR/bin/mysqladmin" WAIT_PID="$BASEDIR/bin/mysql_waitpid" MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager" @@ -466,6 +472,8 @@ else fi fi +export MYSQL_DUMP + if [ -z "$MASTER_MYSQLD" ] then MASTER_MYSQLD=$MYSQLD diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result new file mode 100644 index 00000000000..085cf2788f9 --- /dev/null +++ b/mysql-test/r/mysqldump.result @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); + + + + + + 1 + + + 2 + +
+
+
+DROP TABLE t1; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test new file mode 100644 index 00000000000..c98fd4050f2 --- /dev/null +++ b/mysql-test/t/mysqldump.test @@ -0,0 +1,10 @@ +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# XML output + +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); +--exec $MYSQL_DUMP -X test t1 +DROP TABLE t1;