Skip to content

Commit

Permalink
Add tests for cdb2sql ';' delimiter support
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>
  • Loading branch information
morgando committed Jan 2, 2025
1 parent 24629ff commit 227f29b
Show file tree
Hide file tree
Showing 41 changed files with 170 additions and 30 deletions.
63 changes: 33 additions & 30 deletions tests/cdb2sql.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,48 @@ if [[ -z $dbname ]] ; then
exit 1
fi

for testreq in `find . -name 't[0-9][0-9].sql' -exec basename {} \;` ; do
testname=`echo $testreq | cut -d "." -f 1`
cmd="cdb2sql -s -f $testreq ${CDB2_OPTIONS} $dbname default "
echo $cmd "> $testname.output"
$cmd 2>&1 | perl -pe "s/.n_writeops_done=([0-9]+)/rows inserted='\1'/; s/BLOCK2_SEQV2\(824\)/BLOCK_SEQ(800)/; s/OP #2 BLOCK_SEQ/OP #3 BLOCK_SEQ/;" > $testname.output
run_test() {
local test_input_file_name=$1 output_file_extension=$2 extra_cdb2sql_opts=$3

cmd="diff $testname.expected $testname.output"
$cmd > /dev/null
local test_name
test_name=$(echo ${test_input_file_name} | cut -d "." -f 1)

if [[ $? -eq 0 ]]; then
echo "passed $testname"
else
echo "failed $testname"
echo "see diffs here: $HOSTNAME"
echo "> diff -u ${PWD}/{$testname.expected,$testname.output}"
echo
exit 1
fi
done
local exp_output_file_name=${test_name}${output_file_extension}.expected
local output_file_name=${test_name}${output_file_extension}.output

for testreq in `find . -name 't[0-9][0-9].tab.sql' -exec basename {} \;` ; do
testname=`echo $testreq | cut -d "." -f 1`
cmd="cdb2sql -s -f $testreq ${CDB2_OPTIONS} -tabular $dbname default "
echo $cmd "> $testname.tab.output"
$cmd 2>&1 | perl -pe "s/.n_writeops_done=([0-9]+)/rows inserted='\1'/; s/BLOCK2_SEQV2\(824\)/BLOCK_SEQ(800)/; s/OP #2 BLOCK_SEQ/OP #3 BLOCK_SEQ/;" > $testname.tab.output
local cmd="cdb2sql -s -f ${test_input_file_name} ${CDB2_OPTIONS} ${extra_cdb2sql_opts} ${dbname} default "
echo $cmd "> ${output_file_name}"
$cmd 2>&1 | perl -pe "s/.n_writeops_done=([0-9]+)/rows inserted='\1'/; s/BLOCK2_SEQV2\(824\)/BLOCK_SEQ(800)/; s/OP #2 BLOCK_SEQ/OP #3 BLOCK_SEQ/;" > ${output_file_name}

cmd="diff $testname.tab.expected $testname.tab.output"
$cmd > /dev/null
cmd="diff ${exp_output_file_name} ${output_file_name}"
${cmd} > /dev/null

if [[ $? -eq 0 ]]; then
echo "passed $testname"
echo "passed ${test_name}"
else
echo "failed $testname"
echo "see diffs here: $HOSTNAME"
echo "> diff -u ${PWD}/{$testname.tab.expected,$testname.tab.output}"
echo "failed ${test_name}"
echo "see diffs here: ${HOSTNAME}"
echo "> diff -u ${PWD}/{${exp_output_file_name},${output_file_name}}"
echo
exit 1
fi
done
}

main() {
local test_input_file_name

for test_input_file_name in `find . -name 't[0-9][0-9].sql' -exec basename {} \;` ; do
run_test "${test_input_file_name}"
done

for test_input_file_name in `find . -name 't[0-9][0-9].tab.sql' -exec basename {} \;` ; do
run_test "${test_input_file_name}" ".tab" "-tabular"
done

for test_input_file_name in `find . -name 't[0-9][0-9].multiline.sql' -exec basename {} \;` ; do
run_test "${test_input_file_name}" ".multiline" "-l"
done
}

echo
main
exit 0
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t02.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[;] failed with rc -3 no statement
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t02.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t03.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(';'=';')
4 changes: 4 additions & 0 deletions tests/cdb2sql.test/t03.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- test complete statment spanning multiple lines that contains
-- a non-terminating semicolon
select ';'
;
19 changes: 19 additions & 0 deletions tests/cdb2sql.test/t04.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
('
hello
i
am
a
long
multi
line
statement
'='
hello
i
am
a
long
multi
line
statement
')
13 changes: 13 additions & 0 deletions tests/cdb2sql.test/t04.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- test a longer multi-line statement
select
'
hello
i
am
a
long
multi
line
statement
'
;
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t05.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(1=1)
(1=1)
(1=1)
7 changes: 7 additions & 0 deletions tests/cdb2sql.test/t05.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- test that we can run back-to-back multi-line statements
select 1
;
select 1
;
select 1
;
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t06.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1=1)
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t06.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- test that a non-multiline statement works in multi-line mode
select 1;
4 changes: 4 additions & 0 deletions tests/cdb2sql.test/t07.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(1=1)
(1=1)
(1=1)
(1=1)
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t07.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Test that multiple non-multi-line statements work in multi-line mode
select 1; select 1;
select 1; select 1;
5 changes: 5 additions & 0 deletions tests/cdb2sql.test/t08.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(1=1)
(1=1)
(1=1)
(1=1)
(1=1)
7 changes: 7 additions & 0 deletions tests/cdb2sql.test/t08.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- test that a combination of multi-line and non-multi-line statments work
-- in multi-line mode
select 1; select
1; select 1;
select 1;
select
1;
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t09.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select] failed: Not a complete statement
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t09.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- test that an incomplete statement is handled properly
select
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t10.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(1=1)
[select] failed: Not a complete statement
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t10.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- test that an incomplete statement following a complete
-- statement is handled properly
select 1; select
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t11.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[select
1] failed: Not a complete statement
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t11.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- test that an incomplete multi-line statement is handled properly
select
1
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t12.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[select ';'] failed: Not a complete statement
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t12.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- test incomplete statment with a semicolon
select ';'
5 changes: 5 additions & 0 deletions tests/cdb2sql.test/t13.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
('
-- fake comment
'='
-- fake comment
')
4 changes: 4 additions & 0 deletions tests/cdb2sql.test/t13.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- test a line that looks like a comment but isn't a comment
select '
-- fake comment
';
Empty file.
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t14.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t15.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- test comment containing ';'
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t16.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(1=1)
(1=1)
2 changes: 2 additions & 0 deletions tests/cdb2sql.test/t16.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select 1; -- test
select 1; -- inline comments
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t17.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1=1)
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t17.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1; -- test inline comments with ';'s
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t18.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(';
'=';
')
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t18.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- test non-terminating semicolon placed at the end of line
select ';
';
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t19.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
('see me'='see me')
[oompa] failed with rc -3 near "oompa": syntax error
('see me, too'='see me, too')
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t19.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- test that line is skipped after a syntax error is encountered
select 'see me'; oompa loompa; select 'dont see me';
select 'see me, too';
8 changes: 8 additions & 0 deletions tests/cdb2sql.test/t20.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(1=1)
[select 1 ] failed with rc -3 unrecognized token: "#"
('
#'='
#')
[/] failed with rc -3 near "/": syntax error
(1=1)
[/* . */] failed: Not a complete statement
9 changes: 9 additions & 0 deletions tests/cdb2sql.test/t20.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# test
select 1; # other
select 1 # ;
select '
#';
// kinds
select 1; // of
/* comments */
select 1; /* . */
1 change: 1 addition & 0 deletions tests/cdb2sql.test/t21.multiline.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1=1)
3 changes: 3 additions & 0 deletions tests/cdb2sql.test/t21.multiline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- test complete statment that spans multiple lines
select
1;

0 comments on commit 227f29b

Please sign in to comment.