mysqltest.test 35.6 KB
Newer Older
1 2
# This test should work in embedded server after mysqltest is fixed
-- source include/not_embedded.inc
3 4 5 6 7

# ============================================================================
#
# Test of mysqltest itself
#
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# There are three rules that determines what belong to each command
# 1. A normal command is delimited by the <delimiter> which by default is
#    set to ';'
#
#   ex: | select *
#       |   from t1;
#       |
#   Command: "select * from t1"
#
# 2. Special case is a line that starts with "--", this is a comment
#    ended when the new line character is reached. But the first word
#    in the comment may contain a valid command, which then will be
#    executed. This can be useful when sending commands that
#    contains <delimiter>
#
# 3. Special case is also a line that starts with '#' which is treated
#     as a comment and will be ended by new line character
#
26 27
# ============================================================================

28 29
# ----------------------------------------------------------------------------
# $mysql_errno contains the return code of the last command
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
30
# sent to the server.
31 32 33 34 35 36
# ----------------------------------------------------------------------------
# get $mysql_errno before the first statement
#     $mysql_errno should be -1
eval select $mysql_errno as "before_use_test" ;


37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# ----------------------------------------------------------------------------
# Positive case(statement)
# ----------------------------------------------------------------------------

select otto from (select 1 as otto) as t1;
# expectation = response
--error 0
select otto from (select 1 as otto) as t1;

# expectation <> response
-- // --error 1054
-- // select otto from (select 1 as otto) as t1;


# ----------------------------------------------------------------------------
# Negative case(statement):
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
53
# The derived table t1 does not contain a column named 'friedrich' . 
54 55 56 57 58 59
# --> ERROR 42S22: Unknown column 'friedrich' in 'field list and
# --> 1054: Unknown column 'friedrich' in 'field list'
# ----------------------------------------------------------------------------

# expectation <> response
#--error 0
60 61 62
#select friedrich from (select 1 as otto) as t1
--error 1
--exec echo "select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST  2>&1
63 64 65 66 67 68 69 70

# expectation = response
--error 1054
select friedrich from (select 1 as otto) as t1;

# The following unmasked unsuccessful statement must give
# 1. mysqltest gives a 'failed'
# 2. does not produce a r/<test case>.reject file !!!
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
71
# PLEASE uncomment it and check its effect
72 73 74 75 76 77 78 79
#select friedrich from (select 1 as otto) as t1;


# ----------------------------------------------------------------------------
# Tests for the new feature - SQLSTATE error code matching
# Positive case(statement)
# ----------------------------------------------------------------------------

80
# This syntax not allowed anymore, use --error S00000, see below
81
# expectation = response
82
#!S00000 select otto from (select 1 as otto) as t1;
83 84 85 86 87 88 89 90

--error S00000
select otto from (select 1 as otto) as t1;

# expectation <> response
#!S42S22 select otto from (select 1 as otto) as t1;
#--error S42S22
#select otto from (select 1 as otto) as t1;
91 92 93
--error 1
--exec echo "error S42S22; select otto from (select 1 as otto) as t1;" | $MYSQL_TEST  2>&1

94 95 96 97 98 99


# ----------------------------------------------------------------------------
# Negative case(statement)
# ----------------------------------------------------------------------------

100
# This syntax not allowed anymore, use --error S42S22, see below
101
# expectation = response
102
#!S42S22 select friedrich from (select 1 as otto) as t1;
103 104 105 106 107 108 109
--error S42S22
select friedrich from (select 1 as otto) as t1;

# expectation !=response
#!S00000 select friedrich from (select 1 as otto) as t1;
#--error S00000
#select friedrich from (select 1 as otto) as t1;
110 111
--error 1
--exec echo "error S00000; select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST  2>&1
112 113 114 115 116

# ----------------------------------------------------------------------------
# test cases for $mysql_errno
#
# $mysql_errno is a builtin variable of mysqltest and contains the return code
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
117
# of the last command sent to the server.
118 119 120
#
#      The following test cases often initialize $mysql_errno to 1064 by 
#      a command with wrong syntax.
121
#      Example: --error 1064      To prevent the abort after the error.
122 123 124 125
#               garbage ;
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
126
# check mysql_errno = 0 after successful statement
127 128 129 130 131
# ----------------------------------------------------------------------------
select otto from (select 1 as otto) as t1;
eval select $mysql_errno as "after_successful_stmt_errno" ;

#----------------------------------------------------------------------------
132
# check mysql_errno = 1064 after statement with wrong syntax
133
# ----------------------------------------------------------------------------
134
--error 1064
135 136 137 138
garbage ;
eval select $mysql_errno as "after_wrong_syntax_errno" ;

# ----------------------------------------------------------------------------
139
# check if let $my_var= 'abc' ; affects $mysql_errno
140
# ----------------------------------------------------------------------------
141
--error 1064
142 143 144 145 146
garbage ;
let $my_var= 'abc' ;
eval select $mysql_errno as "after_let_var_equal_value" ;

# ----------------------------------------------------------------------------
147
# check if set @my_var= 'abc' ; affects $mysql_errno
148
# ----------------------------------------------------------------------------
149
--error 1064
150 151 152 153 154
garbage ;
set @my_var= 'abc' ;
eval select $mysql_errno as "after_set_var_equal_value" ;

# ----------------------------------------------------------------------------
155 156
#  check if the setting of --disable-warnings itself affects $mysql_errno
#  (May be --<whatever> modifies $mysql_errno.)
157
# ----------------------------------------------------------------------------
158
--error 1064
159 160 161 162 163
garbage ;
--disable_warnings
eval select $mysql_errno as "after_disable_warnings_command" ;

# ----------------------------------------------------------------------------
164 165 166
# check if --disable-warnings + command with warning affects the errno
# stored within $mysql_errno
# (May be disabled warnings affect $mysql_errno.)
167 168
# ----------------------------------------------------------------------------
drop table if exists t1 ;
169
--error 1064
170 171 172 173 174 175
garbage ;
drop table if exists t1 ;
eval select $mysql_errno as "after_disable_warnings" ;
--enable_warnings

# ----------------------------------------------------------------------------
176
# check if masked errors affect $mysql_errno
177
# ----------------------------------------------------------------------------
178
--error 1064
179 180 181 182
garbage ;
--error 1146
select 3 from t1 ;
eval select $mysql_errno as "after_minus_masked" ;
183
--error 1064
184
garbage ;
185
--error 1146
186 187 188 189
select 3 from t1 ;
eval select $mysql_errno as "after_!_masked" ;

# ----------------------------------------------------------------------------
190
# Will manipulations of $mysql_errno be possible and visible ?
191
# ----------------------------------------------------------------------------
192
--error 1064
193 194 195 196 197
garbage ;
let $mysql_errno= -1;
eval select $mysql_errno as "after_let_errno_equal_value" ;

# ----------------------------------------------------------------------------
198
# How affect actions on prepared statements $mysql_errno ?
199 200
# ----------------------------------------------------------------------------
# failing prepare
201
--error 1064
202
garbage ;
203
--error 1146
204 205 206 207 208
prepare stmt from "select 3 from t1" ;
eval select $mysql_errno as "after_failing_prepare" ;
create table t1 ( f1 char(10));

# successful prepare
209
--error 1064
210 211 212 213 214
garbage ;
prepare stmt from "select 3 from t1" ;
eval select $mysql_errno as "after_successful_prepare" ;

# successful execute
215
--error 1064
216 217 218 219
garbage ;
execute stmt;
eval select $mysql_errno as "after_successful_execute" ;

paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
220
# failing execute (table has been dropped)
221
drop table t1;
222
--error 1064
223
garbage ;
224
--error 1146
225 226 227 228
execute stmt;
eval select $mysql_errno as "after_failing_execute" ;

# failing execute (unknown statement)
229
--error 1064
230
garbage ;
231
--error 1243
232 233 234 235
execute __stmt_;
eval select $mysql_errno as "after_failing_execute" ;

# successful deallocate
236
--error 1064
237 238 239 240 241
garbage ;
deallocate prepare stmt;
eval select $mysql_errno as "after_successful_deallocate" ;

# failing deallocate ( statement handle does not exist )
242
--error 1064
243
garbage ;
244
--error 1243
245 246 247 248 249 250 251
deallocate prepare __stmt_;
eval select $mysql_errno as "after_failing_deallocate" ;


# ----------------------------------------------------------------------------
# test cases for "--disable_abort_on_error"
#
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
252 253
# "--disable_abort_on_error" switches off the abort of mysqltest
# after "unmasked" failing statements.
254 255 256 257
#
# The default is "--enable_abort_on_error".
#
# "Maskings" are
258
#   --error <error number>  and  --error <error number>
259 260
# in the line before the failing statement.
#
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
261
# There are some additional test cases for $mysql_errno
262 263 264 265 266
# because "--disable_abort_on_error" enables a new situation.
# Example: "unmasked" statement fails + analysis of $mysql_errno
# ----------------------------------------------------------------------------

# ----------------------------------------------------------------------------
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
267
# Switch off the abort on error and check the effect on $mysql_errno
268
# ----------------------------------------------------------------------------
269
--error 1064
270 271 272 273 274
garbage ;
--disable_abort_on_error
eval select $mysql_errno as "after_--disable_abort_on_error" ;

# ----------------------------------------------------------------------------
275
# "unmasked" failing statement should not cause an abort
276 277 278 279
# ----------------------------------------------------------------------------
select 3 from t1 ;

# ----------------------------------------------------------------------------
280
# masked failing statements
281 282 283 284
# ----------------------------------------------------------------------------
# expected error = response
--error 1146
select 3 from t1 ;
285
--error 1146
286 287 288 289 290
select 3 from t1 ;
eval select $mysql_errno as "after_!errno_masked_error" ;
# expected error <> response
# --error 1000
# select 3 from t1 ;
291
# --error 1000
292
# select 3 from t1 ;
293 294
--error 1
--exec echo "disable_abort_on_error; error 1000; select 3 from t1; error 1000; select 3 from t1;" | $MYSQL_TEST  2>&1
295 296

# ----------------------------------------------------------------------------
297
# Switch the abort on error on and check the effect on $mysql_errno
298
# ----------------------------------------------------------------------------
299
--error 1064
300 301 302 303 304
garbage ;
--enable_abort_on_error
eval select $mysql_errno as "after_--enable_abort_on_error" ;

# ----------------------------------------------------------------------------
305
# masked failing statements
306 307 308 309 310 311
# ----------------------------------------------------------------------------
# expected error = response
--error 1146
select 3 from t1 ;

# ----------------------------------------------------------------------------
312
# check that the old default behaviour is not changed
313 314 315 316 317 318
# Please remove the '#' to get the abort on error
# ----------------------------------------------------------------------------
#--error 1064
#select 3 from t1 ;
#
#select 3 from t1 ;
319

320
# End of 4.1 tests
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
--error 1
--exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST  2>&1


# ----------------------------------------------------------------------------
# Test comments
# ----------------------------------------------------------------------------

# This is a comment
# This is a ;  comment
# This is a -- comment
-- This is also a comment
-- # This is also a comment
-- This is also a ; comment

# ----------------------------------------------------------------------------
# Test comments with embedded command
# ----------------------------------------------------------------------------

--echo hello
--     echo hello
--    echo ;;;;;;;;

--echo # MySQL: -- The

# ----------------------------------------------------------------------------
# Test detect end of line "junk"
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
348
# Most likely caused by a missing delimiter
349 350 351 352 353 354 355 356 357 358 359 360 361 362
# ----------------------------------------------------------------------------

# Too many parameters to function
--error 1
--exec echo "sleep 5 6;" | $MYSQL_TEST 2>&1

# Too many parameters to function
--error 1
--exec echo "--sleep 5 6" | $MYSQL_TEST 2>&1

#
# Missing delimiter
# The comment will be "sucked into" the sleep command since
# delimiter is missing until after "show status"
363 364 365
--system echo "sleep 4" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "# A comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "show status;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
366
--error 1
367
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
368

369 370 371 372
#
# Missing delimiter until eof
# The comment will be "sucked into" the sleep command since
# delimiter is missing 
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
373 374
--system echo "sleep 7" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "# Another comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
375
--error 1
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
376
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
377

378 379 380 381 382
#
# Extra delimiter
#
--error 1
--exec echo "--sleep 4;" | $MYSQL_TEST 2>&1
383 384
--error 1
--exec echo "--disable_query_log;" | $MYSQL_TEST 2>&1
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413


# Allow trailing # comment
--sleep 1 # Wait for insert delayed to be executed.
--sleep 1 	 # Wait for insert delayed to be executed.


# ----------------------------------------------------------------------------
# Test echo command
# ----------------------------------------------------------------------------

echo MySQL;
echo "MySQL";
echo MySQL: The world''s most popular open source database;
echo "MySQL: The world's most popular open source database";

echo MySQL: The world''s
     most popular open
     source database;

echo # MySQL: The world''s
# most popular open
# source database;

echo - MySQL: The world''s
- most popular open
- source database;

echo - MySQL: The world''s
414 415
-- most popular
-- open source database;
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433

echo # MySQL: The
--world''s
# most popular
-- open
- source database;

echo "MySQL: The world's most popular; open source database";
echo "MySQL: The world's most popular ; open source database";
echo "MySQL: The world's most popular ;open source database";
echo echo message echo message;


echo ;

# Illegal use of echo

--error 1
434
--exec echo "echo \$;" | $MYSQL_TEST 2>&1
435 436 437 438 439 440 441


# ----------------------------------------------------------------------------
# Test exec command
# ----------------------------------------------------------------------------

# Illegal use of exec
442 443
--error 1
--exec echo "--exec false" | $MYSQL_TEST 2>&1
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

--error 1
--exec echo "--exec " | $MYSQL_TEST 2>&1

# ----------------------------------------------------------------------------
# Test let command
# ----------------------------------------------------------------------------

let $message=MySQL;
echo $message;

let $message="MySQL";
echo $message;

let $message= MySQL: The
 world''s most
 popular open
 source database;
echo $message;

let $message= # MySQL: The
# world''s most
# popular open
# source database;
echo $message;

let $message=  -- MySQL: The
-- world''s most
472 473
-- popular
-- open source database;
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
echo $message;

let $message=  # MySQL: The
- world''s most
-- popular open
# source database;
echo $message;

echo '$message';
echo "$message";

let $1=hej;
echo $1;

let   $1   =hej ;
echo $1;

let $1 = hej;
echo $1;

494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
let $1=1;
let $2=$1;
echo $2;
let $5=$6;
echo $5;
echo $6;

let $where=a long variable content;
echo $where;

let $where2= $where;
echo $where2;

let $where3=a long $where variable content;
echo $where3;

510 511 512
let $where3=a long \\\$where variable content;
echo $where3;

513 514 515
let $novar1= $novar2;
echo $novar1;

516 517 518 519 520 521 522 523 524
let $cat=na;
let $cat=ba$cat$cat;
echo banana = $cat;

# ba\$cat\$cat should have been sufficient.
# ba\\\$cat\\\$cat -> ba\$cat\$cat -> ba$cat$cat -> banana
# Magnus' upcoming patch will fix the missing second interpretation.
let $cat=ba\\\$cat\\\$cat;
echo Not a banana: $cat;
525

526 527 528 529 530 531 532

# Test illegal uses of let

--error 1
--exec echo "let ;" | $MYSQL_TEST 2>&1

--error 1
533
--exec echo "let \$=hi;" | $MYSQL_TEST  2>&1
534 535

--error 1
536
--exec echo "let \$1 hi;" | $MYSQL_TEST  2>&1
537 538

--error 1
539
--exec echo "let \$m hi;" | $MYSQL_TEST  2>&1
540 541

--error 1
542
--exec echo "let \$hi;" | $MYSQL_TEST  2>&1
543 544

--error 1
545
--exec echo "let \$ hi;" | $MYSQL_TEST  2>&1
546 547 548 549 550 551 552

--error 1
--exec echo "let =hi;" | $MYSQL_TEST  2>&1

--error 1
--exec echo "let hi;" | $MYSQL_TEST  2>&1

553 554 555 556 557 558 559 560 561 562 563 564 565
# More advanced test for bug#17280
let $success= 1;
--echo # Execute: --echo # <whatever> success: \$success
--echo # <whatever> success: $success
--echo # Execute: echo # <whatever> success: \$success ;
echo # <whatever> success: $success ;

--echo # The next two variants work fine and expand the content of \$success
--echo # Execute: --echo \$success
--echo $success
--echo # Execute: echo \$success ;
echo $success ;

566 567 568 569
# ----------------------------------------------------------------------------
# Test to assign let from query
# let $<var_name>=`<query>`;
# ----------------------------------------------------------------------------
570
--disable_parsing
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
echo var1;
let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`;
echo $var1;
echo $var1_Col;
echo $var1_Column1;
echo $var1_Col3;

echo var2;
let $var2= `select 2 as "Column num 2"`;
echo $var2;
echo $var2_Column num 2;
echo $var2_Column;

echo var2 again;
let $var2= `select 2 as "Column num 2"`;
echo $var2;
echo $var2_Column num 2;
echo $var2_Column_num_2;
echo $var2_Column;

echo var3 two columns with same name;
let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`;
echo $var3;
echo $var3_Col;
echo $var3_Col;
echo $var3_var3;

#echo failing query in let;
#--error 1
#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1
601
--enable_parsing
602 603 604 605 606 607 608 609 610
# ----------------------------------------------------------------------------
# Test source command
# ----------------------------------------------------------------------------

# Test illegal uses of source

--error 1
--exec echo "source ;" | $MYSQL_TEST 2>&1

msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
611 612
# Fix win paths
--replace_result \\ /
613 614 615 616
--error 1
--exec echo "source non_existingFile;" | $MYSQL_TEST 2>&1

# Too many source
617 618
--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" > $MYSQLTEST_VARDIR/tmp/recursive.sql
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
619
--error 1
620
--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1
621 622

# Source a file with error
623 624
--exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
625
--error 1
626
--exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1
627 628


629 630 631 632 633 634 635
# Test execution of source in a while loop
--disable_query_log
let $outer= 2; # Number of outer loops
while ($outer)
{
  eval SELECT '$outer = outer loop variable after while' AS "";

636
  --source include/sourced.inc
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663

  eval SELECT '$outer = outer loop variable before dec' AS "";
  dec $outer;
  eval SELECT '$outer = outer loop variable after dec' AS "";
}

let $outer= 2; # Number of outer loops
while ($outer)
{
  eval SELECT '$outer = outer loop variable after while' AS "";

  echo here is the sourced script;

  eval SELECT '$outer = outer loop variable before dec' AS "";
  dec $outer;
  eval SELECT '$outer = outer loop variable after dec' AS "";
}


# Test execution of source in a while loop
--disable_abort_on_error
# Sourcing of a file within while loop, sourced file will
# source other file
let $num= 9;
while ($num)
{
   SELECT 'In loop' AS "";
664
   --source include/sourced1.inc
665 666
   dec $num;
}
667
--enable_abort_on_error
668 669
--enable_query_log

670 671 672 673 674 675 676 677 678 679 680
# ----------------------------------------------------------------------------
# Test sleep command
# ----------------------------------------------------------------------------

sleep 0.5;
sleep 1;
real_sleep 1;

# Missing parameter
--error 1
--exec echo "sleep ;" | $MYSQL_TEST 2>&1
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
681 682
--error 1
--exec echo "real_sleep ;" | $MYSQL_TEST 2>&1
683 684 685 686

# Illegal parameter
--error 1
--exec echo "sleep abc;" | $MYSQL_TEST 2>&1
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
687 688
--error 1
--exec echo "real_sleep abc;" | $MYSQL_TEST 2>&1
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710

# ----------------------------------------------------------------------------
# Test inc
# ----------------------------------------------------------------------------
inc $i;
echo $i;
inc $i;
echo $i;
let $i=100;
inc $i;
echo $i;

let $i=hej;
echo $i;
inc $i;
echo $i;

--error 1
--exec echo "inc;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "inc i;" | $MYSQL_TEST 2>&1
--error 1
711
--exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738

inc $i; inc $i; inc $i; --echo $i
echo $i;


# ----------------------------------------------------------------------------
# Test dec
# ----------------------------------------------------------------------------

dec $d;
echo $d;
dec $d;
echo $d;
let $d=100;
dec $d;
echo $d;

let $d=hej;
echo $d;
dec $d;
echo $d;

--error 1
--exec echo "dec;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "dec i;" | $MYSQL_TEST 2>&1
--error 1
739
--exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
740 741 742 743 744 745 746 747 748 749 750 751 752 753


# ----------------------------------------------------------------------------
# Test system
# ----------------------------------------------------------------------------
system ls > /dev/null;
system echo "hej" > /dev/null;
--system ls > /dev/null
--system echo "hej" > /dev/null;

--error 1
--exec echo "system;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "system $NONEXISTSINFVAREABLI;" | $MYSQL_TEST 2>&1
754 755
--error 1
--exec echo "system false;" | $MYSQL_TEST 2>&1
756 757

--disable_abort_on_error
758
system NonExistsinfComamdn 2> /dev/null;
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
--enable_abort_on_error


# ----------------------------------------------------------------------------
# Test delimiter
# ----------------------------------------------------------------------------

delimiter stop;
echo teststop
delimiter ;stop
echo test2;
--delimiter stop
echo test3stop
--delimiter ;
echo test4;

775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798

# ----------------------------------------------------------------------------
# Test if
# ----------------------------------------------------------------------------

let $counter=10;
if ($counter)
{
  echo Counter is greater than 0, (counter=10);
}
if (!$counter)
{
  echo Counter is not 0, (counter=10);
}
let $counter=0;
if ($counter)
{
  echo Counter is greater than 0, (counter=0);
}
if (!$counter)
{
  echo Counter is not 0, (counter=0);
}

799 800 801 802 803 804 805 806 807 808 809 810 811
# ----------------------------------------------------------------------------
# Test while, { and }
# ----------------------------------------------------------------------------

let $i=1;
while ($i)
{
  echo $i;
  dec $i;
}
# One liner
#let $i=1;while ($i){echo $i;dec $i;}

812 813 814 815 816 817
let $i=0;
while (!$i)
{
  echo Testing while with not;
  inc $i;
}
818 819

# Exceed max nesting level
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
820 821
# Fix win path
--replace_result \\ /
822 823 824
--error 1
--exec echo "source include/mysqltest_while.inc;" | $MYSQL_TEST 2>&1
--error 1
825
--exec echo "while \$i;" | $MYSQL_TEST 2>&1
826
--error 1
827
--exec echo "while (\$i;" | $MYSQL_TEST 2>&1
828
--error 1
829
--exec echo "let \$i=1; while (\$i) dec \$i;" | $MYSQL_TEST 2>&1
830 831 832 833 834 835
--error 1
--exec echo "};" | $MYSQL_TEST 2>&1
--error 1
--exec echo "end;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "{;" | $MYSQL_TEST 2>&1
836

837 838
--system echo "while (0)" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
839
--error 1
840
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
841

842 843
--system echo "while (0)" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "{echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
844
--error 1
845
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
846

847 848
--system echo "while (0){" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "echo hej;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
849
--error 1
850
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
851

852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
# ----------------------------------------------------------------------------
# Test error messages returned from comments starting with a command
# ----------------------------------------------------------------------------
--error 1
--exec echo "--if the other server is down" | $MYSQL_TEST 2>&1

--error 1
--exec echo "-- end when ..." | $MYSQL_TEST 2>&1

# ----------------------------------------------------------------------------
# Test replace
# ----------------------------------------------------------------------------
--replace_result a b
select "a" as col1, "c" as col2;

--replace_result a b c d
select "a" as col1, "c" as col2;

--error 1
--exec echo "--replace_result a" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_result a;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_result a;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_result a ;" | $MYSQL_TEST 2>&1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
878
--exec echo "replace_result a b; echo OK;" | $MYSQL_TEST 2>&1
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
--error 1
--exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_result a b c ;" | $MYSQL_TEST 2>&1


--replace_column 1 b
select "a" as col1, "c" as col2;

--replace_column 1 b 2 d
select "a" as col1, "c" as col2;

--error 1
--exec echo "--replace_column a" | $MYSQL_TEST 2>&1

--error 1
--exec echo "--replace_column 1" | $MYSQL_TEST 2>&1

--error 1
--exec echo "--replace_column a b" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_column a 1" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1


# ----------------------------------------------------------------------------
# Test sync_with_master
# ----------------------------------------------------------------------------
--error 1
--exec echo "save_master_pos; sync_with_master 10!;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "save_master_pos; sync_with_master 10 !;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "save_master_pos; sync_with_master a;" | $MYSQL_TEST 2>&1

915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
# ----------------------------------------------------------------------------
# Test connect
# ----------------------------------------------------------------------------

--error 1
--exec echo "connect;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect ();" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2,);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2,localhost);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2, localhost, root);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2,  localhost, root,);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con2,localhost,root,,illegal_db);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con1,localhost,root,,,illegal_port,);" | $MYSQL_TEST 2>&1
--error 1
--exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1

# Repeat connect/disconnect
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
941 942 943 944 945 946 947 948
--system echo "let \$i=100;"                              > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "while (\$i)"                              >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "{"                                        >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " connect (test_con1,localhost,root,,); "  >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " disconnect test_con1; "                  >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " dec \$i;                               " >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "}"                                        >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql; echo OK;" | $MYSQL_TEST 2>&1
949 950

# Repeat connect/disconnect, exceed max number of connections
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
951 952 953 954 955 956 957
--system echo "let \$i=200;"                              > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "while (\$i)"                              >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "{"                                        >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " connect (test_con1,localhost,root,,); "  >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " disconnect test_con1; "                  >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo " dec \$i;                               " >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "}"                                        >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
958
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
959
--error 1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
960
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
961 962

# Select disconnected connection
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
963 964 965
--system echo "connect (test_con1,localhost,root,,);"    > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "disconnect test_con1; "                  >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "connection test_con1;"                   >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
966
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
967
--error 1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
968
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
969 970

# Connection name already used
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
971 972
--system echo "connect (test_con1,localhost,root,,);"    > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "connect (test_con1,localhost,root,,);"   >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
973
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
974
--error 1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
975
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
976

977 978 979 980 981 982 983
# connect when "disable_abort_on_error" caused "connection not found"
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--disable_abort_on_error
connect (con1,localhost,root,,);
connection default;
connection con1;
--enable_abort_on_error
984 985 986 987 988 989

# ----------------------------------------------------------------------------
# Test mysqltest arguments
# ----------------------------------------------------------------------------

# -x <file_name>, use the file specified after -x as the test file
990 991 992
--exec $MYSQL_TEST < $MYSQL_TEST_DIR/include/mysqltest-x.inc
--exec $MYSQL_TEST -x $MYSQL_TEST_DIR/include/mysqltest-x.inc
--exec $MYSQL_TEST --test_file=$MYSQL_TEST_DIR/include/mysqltest-x.inc
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
993 994
# Fix Win paths
--replace_result \\ /
995 996
--error 1
--exec $MYSQL_TEST -x non_existing_file.inc 2>&1
997 998


999 1000 1001 1002 1003
# ----------------------------------------------------------------------------
# TODO Test queries, especially their errormessages... so it's easy to debug 
# new scripts and diagnose errors
# ----------------------------------------------------------------------------

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
# ----------------------------------------------------------------------------
# Test bug#12386
# ----------------------------------------------------------------------------
let $num= 2;
while ($num)
{
   --error 1064
   failing_statement;

   dec $num;
}

SELECT 1 as a;
1017 1018 1019 1020 1021 1022 1023 1024 1025


#
# Bug #10251: Identifiers containing quotes not handled correctly
#
select 1 as `a'b`, 2 as `a"b`;

# Test escaping of quotes
select 'aaa\\','aa''a',"aa""a";
1026 1027

#
1028
# Check of include/show_msg.inc and include/show_msg80.inc
1029 1030 1031
#

# The message contains in most cases a string with the default character set
1032
let $message= Here comes a message;
1033 1034 1035
--source include/show_msg.inc

# The message could also contain a string with character set utf8
1036
let $message= `SELECT USER()`;
1037 1038 1039
--source include/show_msg.inc

# The message contains more then 80 characters on multiple lines
mleich@mysql.com's avatar
mleich@mysql.com committed
1040
# and is kept between double quotes.
1041 1042 1043 1044
let $message= 
"Here comes a very very long message that
    - is longer then 80 characters    and
    - consists of several lines";
1045 1046
--source include/show_msg80.inc

mleich@mysql.com's avatar
mleich@mysql.com committed
1047 1048 1049 1050 1051 1052 1053
# The message contains more then 80 characters on multiple lines
# and uses the auxiliary character "." at the beginning of the message lines.
let $message= . Here comes a very very long message that
              .      - is longer then 80 characters    and
              .      - consists of several lines;
--source include/show_msg80.inc

1054
#
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
1055
# Test --enable_parsing / disable_parsing
1056 1057 1058 1059 1060 1061 1062 1063 1064
#
--disable_query_log
--disable_parsing
# The following will not enable query logging
--enable_query_log
select "this will not be executed";
--enable_parsing
select "this will be executed";
--enable_query_log
1065

msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1066 1067 1068
#
# Test zero length result file. Should not pass
#
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
1069 1070
--exec touch $MYSQLTEST_VARDIR/tmp/zero_length_file.result
--exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1071
--error 1
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
1072
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result  2>&1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1073 1074 1075
#
# Test that a test file that does not generate any output fails.
#
1076
--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1077
--error 1
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
1078
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql  2>&1
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1079 1080 1081

#
# Test that mysqltest fails when there are no queries executed
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
1082
# but a result file exists
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1083
# NOTE! This will never happen as long as it's not allowed to have
paul@snake-hub.snake.net's avatar
paul@snake-hub.snake.net committed
1084
# test files that produce no output
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
1085 1086
#--exec echo "something" > $MYSQLTEST_VARDIR/tmp/result_file.result
#--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
msvensson@neptunus.(none)'s avatar
msvensson@neptunus.(none) committed
1087
#--error 1
msvensson@neptunus.(none)'s avatar
Merge  
msvensson@neptunus.(none) committed
1088
#--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/result_file.result 2>&1
1089 1090 1091 1092 1093 1094

#
# Bug #11731 mysqltest in multi-statement queries ignores errors in
#            non-1st queries
#

1095
echo Failing multi statement query;
1096
# PS does not support multi statement
1097 1098 1099 1100 1101 1102 1103
--exec echo "--disable_ps_protocol"                    > $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "delimiter ||||;"                         >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "create table t1 (a int primary key);"    >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "insert into t1 values (1);"              >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "select 'select-me';"                     >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "insertz 'error query'||||"               >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "delimiter ;||||"                         >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1104 1105

--error 1
1106
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
1107 1108 1109
drop table t1;

--error 1
1110
--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
1111
# The .out file should be non existent
1112
--exec test ! -s $MYSQLTEST_VARDIR/tmp/bug11731.out
1113 1114 1115
drop table t1;


1116
echo Multi statement using expected error;
1117
# PS does not support multi statement
1118 1119 1120 1121 1122 1123 1124 1125
--exec echo "--disable_ps_protocol"                    > $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "delimiter ||||;"                         >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "--error 1064"                            >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "create table t1 (a int primary key);"    >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "insert into t1 values (1);"              >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "select 'select-me';"                     >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "insertz "error query"||||"               >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
--exec echo "delimiter ;||||"                         >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1126 1127

# These two should work since the error is expected
1128
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql  2>&1
1129 1130
drop table t1;

1131
--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
1132
# The .out file should exist
1133
--exec test -s $MYSQLTEST_VARDIR/tmp/bug11731.out
1134 1135
drop table t1;

1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
#
# Bug#19890  	mysqltest: "query" command is broken
#

# It should be possible to use the command "query" to force mysqltest to
# send the command to the server although it's a builtin mysqltest command.
--error 1064
query sleep;

--error 1064
--query sleep

# Just an empty query command
--error 1065
query ;
1151 1152

--echo End of 5.0 tests
1153

1154 1155 1156
# test for replace_regex
--replace_regex /at/b/
select "at" as col1, "c" as col2;
1157

1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
--replace_regex /at/b/i
select "at" as col1, "AT" as col2, "c" as col3;

--replace_regex /a/b/ /ct/d/
select "a" as col1, "ct" as col2; 

--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
select "strawberry","blueberry","potato";

--error 1
--exec echo "--replace_regex a" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_regex a;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_regex a;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_regex a ;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_regex a b; echo OK;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "--replace_regex /a b c" | $MYSQL_TEST 2>&1
--error 1
--exec echo "replace_regex /a /b c ;" | $MYSQL_TEST 2>&1 
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190

# REQUIREMENT
#   replace_regex should replace substitutions from left to right in output

create table t1 (a int, b int);
insert into t1 values (1,3);
insert into t1 values (2,4);
--replace_regex /A/C/ /B/D/i /3/2/ /2/1/
select * from t1;
drop table t1;
1191 1192

--echo End of 5.1 tests