diff options
Diffstat (limited to 'mysql-test/t/mysqltest.test')
-rw-r--r-- | mysql-test/t/mysqltest.test | 279 |
1 files changed, 239 insertions, 40 deletions
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index ca19de75d4b..6f12c6d4d11 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -339,7 +339,7 @@ eval select $mysql_errno as "after_!errno_masked_error" ; --exec illegal_command --cat_file does_not_exist --perl - exit(1); + exit(2); EOF # ---------------------------------------------------------------------------- @@ -862,6 +862,19 @@ let $var2= `failing query`; echo $var2; EOF +create table t1 (a varchar(100)); +insert into t1 values ('`select 42`'); +let $a= `select * from t1`; +# This should output `select 42`, not evaluate it again to 42 +echo $a; +insert into t1 values ('$dollar'); +# These should also output the string without evaluating it. +let $a= query_get_value(select * from t1 order by a, a, 1); +echo $a; +let $a= query_get_value(select * from t1 order by a, a, 2); +echo $a; +drop table t1; + --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1 @@ -1014,16 +1027,13 @@ EOF # ---------------------------------------------------------------------------- # Test inc # ---------------------------------------------------------------------------- -inc $i; -echo $i; +let $i= 0; inc $i; echo $i; let $i=100; inc $i; echo $i; - -let $i=hej; -echo $i; +let $i= -100; inc $i; echo $i; @@ -1032,7 +1042,13 @@ echo $i; --error 1 --exec echo "inc i;" | $MYSQL_TEST 2>&1 --error 1 +--exec echo "inc \$i;" | $MYSQL_TEST 2>&1 +--error 1 --exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "let \$i=text; inc \$i; echo \$i;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "let \$i=10cc; inc \$i; echo \$i;" | $MYSQL_TEST 2>&1 inc $i; inc $i; inc $i; --echo $i echo $i; @@ -1042,25 +1058,25 @@ echo $i; # Test dec # ---------------------------------------------------------------------------- -dec $d; -echo $d; +let $d= 0; 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 +--exec echo "dec \$i;" | $MYSQL_TEST 2>&1 +--error 1 --exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "let \$i=text; dec \$i; echo \$i;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "let \$i=10cc; dec \$i; echo \$i;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- @@ -1139,6 +1155,11 @@ if (!$counter) { echo Counter is not 0, (counter=10); } +if (! $counter) +{ + let $counter=5; +} +echo Counter should still be 10, is $counter; let $counter=0; if($counter) { @@ -1148,6 +1169,10 @@ if (!$counter) { echo Counter is not 0, (counter=0); } +if (! $counter) +{ + echo Not space var works; +} # ---------------------------------------------------------------------------- # Test if with some non-numerics @@ -1168,10 +1193,11 @@ if ($counter) { echo oops, -0 is true; } -if (beta) -{ - echo Beta is true; -} +# This is no longer allowed, as a precaution against mistyped conditionals +# if (beta) +# { +# echo Beta is true; +# } let $counter=gamma; while ($counter) { @@ -1180,6 +1206,196 @@ while ($counter) } # ---------------------------------------------------------------------------- +# Test if with compare conditions +# ---------------------------------------------------------------------------- + +let $ifvar= 5; +let $ifvar2= 6; + +if ($ifvar < 7) +{ + echo 5<7; +} +if ($ifvar< 7) +{ + echo 5<7 again; +} +if ($ifvar<7) +{ + echo 5<7 still; +} +if ($ifvar < $ifvar2) +{ + echo 5<6; +} +if ($ifvar <= 4) +{ + echo 5<=4; +} +if ($ifvar >= 5) +{ + echo 5>=5; +} +if ($ifvar>=5) +{ + echo 5>=5 again; +} +if ($ifvar > 3) +{ + echo 5>3; +} +if ($ifvar == 4) +{ + echo 5==4; +} +if ($ifvar == 5) +{ + echo 5==5; +} +if ($ifvar != 8) +{ + echo 5!=8; +} +# Any number should compare unequal to any string +if ($ifvar != five) +{ + echo 5!=five; +} +if ($ifvar == `SELECT 3+2`) +{ + echo 5==3+2; +} +if ($ifvar == 5) +{ + echo 5 == 5; +} +let $ifvar= hello; +if ($ifvar == hello there) +{ + echo hello == hello there; +} +if ($ifvar == hello) +{ + echo hello == hello; +} +if ($ifvar == hell) +{ + echo hello == hell; +} +if ($ifvar == hello) +{ + echo hello == hello; +} +if ($ifvar != goodbye) +{ + echo hello != goodbye; +} +let $ifvar= 'quoted'; +if ($ifvar == ''quoted'') +{ + echo 'quoted' == ''quoted''; +} +let $ifvar= two words; +if ($ifvar == two words) +{ + echo two words; +} +if ($ifvar == 'two words') +{ + echo 'two words'; +} +if ($ifvar == "two words") +{ + echo "two words"; +} +if ($ifvar == `SELECT 'two words'`) +{ + echo two words are two words; +} +if (42) +{ + echo right answer; +} +if (0) +{ + echo wrong answer; +} +# Non-empty string treated as 'true' +if (`SELECT 'something'`) +{ + echo anything goes; +} +# Make sure 0 and string compare right +let $ifvar= 0; +if ($ifvar == string) +{ + echo 0 == string; +} +if ($ifvar != string) +{ + echo 0 != string; +} +--write_file $MYSQL_TMP_DIR/mysqltest.sql +let $var= 5; +if ($var >= four) +{ + echo 5>=four; +} +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1 +remove_file $MYSQL_TMP_DIR/mysqltest.sql; + +--write_file $MYSQL_TMP_DIR/mysqltest.sql +let $var= 5; +if ($var ~= 6) +{ + echo 5~=6; +} +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1 +remove_file $MYSQL_TMP_DIR/mysqltest.sql; + +--write_file $MYSQL_TMP_DIR/mysqltest.sql +let $var= text; +if (var == text) +{ + echo Oops I forgot the $; +} +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQL_TMP_DIR/mysqltest.sql 2>&1 +remove_file $MYSQL_TMP_DIR/mysqltest.sql; + +--error 1 +--exec echo "if (\$var ==) {" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "if (\$var > ) {" | $MYSQL_TEST 2>&1 + +# ---------------------------------------------------------------------------- +# Test while with compare conditions +# ---------------------------------------------------------------------------- + +let $counter= 2; + +while ($counter < 5) +{ + echo counter is $counter; + inc $counter; +} +let $ifvar=; +while ($ifvar != stop) +{ + if ($counter >= 7) + { + let $ifvar= stop; + } + echo counter is $counter; + inc $counter; +} + +# ---------------------------------------------------------------------------- # Test while, { and } # ---------------------------------------------------------------------------- @@ -1932,6 +2148,7 @@ EOF cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +--replace_regex /my_errno=[0-9]*/(my_errno)/ --error 1 --exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1 @@ -2451,15 +2668,15 @@ let $count= 0; while ($run) { let $Field= query_get_value($show_statement, Field, $rowno); - if (`SELECT '$Field' = 'No such row'`) + if ($Field == No such row) { let $run= 0; } - if (`SELECT '$Field' <> 'No such row'`) + if ($Field != No such row) { let $Type= query_get_value($show_statement, Type, $rowno); let $Null= query_get_value($show_statement, Null, $rowno); - if (`SELECT '$Null' = 'YES'`) + if ($Null == YES) { inc $count; } @@ -2512,6 +2729,8 @@ write_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt; hello EOF +# Verify that --replace_result also work on list_files +--replace_result file REPLACED_FILE list_files $MYSQLTEST_VARDIR/tmp/testdir; # list_files gets the directory list before creating the new file list_files_write_file $MYSQLTEST_VARDIR/tmp/testdir/file2.txt $MYSQLTEST_VARDIR/tmp/testdir *; @@ -2542,26 +2761,6 @@ rmdir $MYSQLTEST_VARDIR/tmp/testdir; --replace_result c:\\a.txt z SELECT 'c:\\a.txt' AS col; -# -# Bug#32307 mysqltest - does not detect illegal if syntax -# - -let $test= 1; -if ($test){ - echo hej; -} - ---write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql -if ($mysql_errno != 1436) -{ - echo ^ Should not be allowed! -} -EOF ---error 1 ---exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 -remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; - - # ---------------------------------------------------------------------------- # Test that -- is not allowed as comment, only as mysqltest builtin command # ---------------------------------------------------------------------------- |