diff options
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/mysqltest.result | 32 | ||||
-rw-r--r-- | mysql-test/t/mysqltest.test | 202 |
2 files changed, 207 insertions, 27 deletions
diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index cff845a2819..c4bf83db31a 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -401,8 +401,36 @@ true-outer Counter is greater than 0, (counter=10) Counter is not 0, (counter=0) Counter is true, (counter=alpha) -Beta is true while with string, only once +5<7 +5<7 again +5<7 still +5<6 +5>=5 +5>=5 again +5>3 +5==5 +5!=8 +5!=five +5==3+2 +5 == 5 +hello == hello +hello == hello +hello != goodbye +two words +two words are two words +right answer +anything goes +0 != string +mysqltest: At line 2: Only == and != are supported for string values +mysqltest: At line 2: Found junk '~= 6' after $variable in condition +mysqltest: At line 2: Expression in if/while must beging with $, ` or a number +counter is 2 +counter is 3 +counter is 4 +counter is 5 +counter is 6 +counter is 7 1 Testing while with not mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest_while.inc": At line 64: Nesting too deeply @@ -807,8 +835,6 @@ dir-list.txt SELECT 'c:\\a.txt' AS col; col z -hej -mysqltest: At line 1: Found junk ' != 143' after $variable in expression select 1; 1 1 diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 8fb05e52cdc..9b8a45d6a87 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1163,10 +1163,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) { @@ -1175,6 +1176,179 @@ 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= 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; + +# ---------------------------------------------------------------------------- +# 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 } # ---------------------------------------------------------------------------- @@ -2529,26 +2703,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 # ---------------------------------------------------------------------------- |