1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
# ==== Purpose ====
#
# Verify that the "escape" function in the mysqltest language works as expected.
#
# ==== Requirements ====
#
# R1. escape(C,S) shall insert a backslash character before every occurrence
# of C in S and return the resulting string.
# R2. escape(C,S) shall preserve leading and trailing whitespace in S.
# R3. escape(C,S) shall work if S is empty.
# R4. escape(C,S) shall work when C or S contains parentheses or commas, and
# when S contains newlines.
# R5. escape(C,S) shall work when C is multi-character.
# R6. escape(C,S) shall fail when C is newline.
# R7. escape shall fail when the parentheses or comma are wrong.
--echo ==== R1: escape inserts backslash before character ====
--let $x = foo bar baz
--let $y = escape(a,$x)
--assert($x == foo bar baz)
--assert($y == foo b\ar b\az)
--let $x = '"\f\o\o"'
--let $y = escape(\,$x)
--let $z = escape(",$y)
--let $w = escape(',$z)
--echo <$y>
--echo <$z>
--echo <$w>
--echo ==== R2: escape preserves leading and trailing whitespace ====
--let $x = escape(a, haha )
--echo <$x>
--let $s = `SELECT ' '`
--let $x = escape( , $s )
--echo <$x>
--echo ==== R3: escape(C,S) shall work if S is empty ====
--let $x = escape(a,)
--echo <$x>
--echo ==== R4.1: escape(C,S) shall work when C or S contains parentheses ====
--let $x = escape(h, hihi (haha))
--echo <$x>
--let $x = escape(), hihi (haha))
--echo <$x>
--let $x = escape((, hihi (haha))
--echo <$x>
--echo ==== R4.2: escape(C,S) shall work when C or S contains comma ====
--let $x = escape(u,,x,)
--echo <$x>
--let $x = escape(,,,x,)
--echo <$x>
--echo ==== R4.3: escape(C,S) shall work when S contains newline ====
--let $nl = `SELECT '\n'`
let $x = escape(h,$nl$nl$sa
hoho
huhu$nl$nl);
--echo <$x>
--echo ==== R5: escape shall work with multiple characters ====
--let $x = escape(lo,Hello, world)
--echo <$x>
--let $x = escape(,o,Hello, world)
--echo <$x>
--echo ==== R6: escape(C,S) shall fail when C is newline ====
--let $test_file = $MYSQL_TMP_DIR/escape_failure.test
--write_file $test_file
let $x = escape(
,
foo
);
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--echo ==== R7.1: escape shall fail when opening parenthesis is wrong ====
--write_file $test_file
--let $x = escape (a,aa)
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape a,aa)
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--echo ==== R7.2: escape shall fail when comma is wrong ====
--write_file $test_file
--let $x = escape(aaa)
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape(,aaa)
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape(,)
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--echo ==== R7.3: escape shall fail when closing parenthesis is wrong ====
--write_file $test_file
--let $x = escape(a,aa
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape(a,aa)a
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--echo ==== R7.4: escape shall fail when parentheses and comma are out of order ====
--write_file $test_file
--let $x = escape,()
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape,)(
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape),(
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape(),
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
--write_file $test_file
--let $x = escape)(,
EOF
--error 1
--exec $MYSQL_TEST < $test_file 2>&1
--remove_file $test_file
|