1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

Bug #57276 mysqltest: add support for simple compares in if/while conditions

Added more parsing in do_block()
      Limitation: left operand must be variable
      Also changed var_set_int from 57036 to var_check_int
      Added tests to mysqltest.test
      Some tests can now be simplified but will take this later
      Updated after comments, now white space around operator not needed
This commit is contained in:
Bjorn Munch
2010-11-10 09:42:14 +01:00
parent b541611cb9
commit 28f60d525a
3 changed files with 343 additions and 36 deletions

View File

@@ -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

View File

@@ -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)
{
@@ -1174,6 +1175,179 @@ while ($counter)
let $counter=000;
}
# ----------------------------------------------------------------------------
# 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
# ----------------------------------------------------------------------------