Skip to content

Commit

Permalink
Run all tcl tests on 2 separate dbs (1. with rowid aliases 2. without…
Browse files Browse the repository at this point in the history
… rowid aliases)
  • Loading branch information
jussisaurio committed Dec 14, 2024
1 parent 949d6fe commit 987a8bf
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
58 changes: 53 additions & 5 deletions testing/cmdlineshell.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_execsql_test schema {
do_execsql_test_on_specific_db testing/testing.db schema {
.schema
} {"CREATE TABLE users (
id INTEGER PRIMARY KEY,
Expand All @@ -24,7 +24,29 @@ CREATE TABLE products (
);
CREATE INDEX age_idx on users (age);"}

do_execsql_test schema-1 {
# FIXME sqlite does something different with .schema than what we are doing
#do_execsql_test_on_specific_db testing/testing_norowidalias.db schema {
# .schema
#} {"CREATE TABLE IF NOT EXISTS users (
# id INT PRIMARY KEY,
# first_name TEXT,
# last_name TEXT,
# email TEXT,
# phone_number TEXT,
# address TEXT,
# city TEXT,
# state TEXT,
# zipcode TEXT,
# age INTEGER
# );
#CREATE TABLE IF NOT EXISTS products (
# id INT PRIMARY KEY,
# name TEXT,
# price REAL
# );
#CREATE INDEX age_idx2 on users (age);"}

do_execsql_test_on_specific_db testing/testing.db schema-1 {
.schema users
} {"CREATE TABLE users (
id INTEGER PRIMARY KEY,
Expand All @@ -40,10 +62,36 @@ do_execsql_test schema-1 {
);
CREATE INDEX age_idx on users (age);"}

do_execsql_test schema-2 {
# FIXME sqlite does something different with .schema than what we are doing
#do_execsql_test_on_specific_db testing/testing_norowidalias.db schema-1 {
# .schema users
#} {"CREATE TABLE IF NOT EXISTS users (
# id INT PRIMARY KEY,
# first_name TEXT,
# last_name TEXT,
# email TEXT,
# phone_number TEXT,
# address TEXT,
# city TEXT,
# state TEXT,
# zipcode TEXT,
# age INTEGER
# );
#CREATE INDEX age_idx2 on users (age);"}

do_execsql_test_on_specific_db testing/testing.db schema-2 {
.schema products
} {{CREATE TABLE products (
} {"CREATE TABLE products (
id INTEGER PRIMARY KEY,
name TEXT,
price REAL
);}}
);"}

# FIXME sqlite does something different with .schema than what we are doing
#do_execsql_test_on_specific_db testing/testing_norowidalias.db schema-2 {
# .schema products
#} {"CREATE TABLE IF NOT EXISTS products (
# id INT PRIMARY KEY,
# name TEXT,
# price REAL
# );"}
22 changes: 16 additions & 6 deletions testing/tester.tcl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
set sqlite_exec [expr {[info exists env(SQLITE_EXEC)] ? $env(SQLITE_EXEC) : "sqlite3"}]
set test_dbs [list "testing/testing.db" "testing/testing_norowidalias.db"]

proc evaluate_sql {sqlite_exec sql} {
set command [list $sqlite_exec testing/testing.db $sql]
proc evaluate_sql {sqlite_exec db_name sql} {
set command [list $sqlite_exec $db_name $sql]
set output [exec {*}$command]
return $output
}

proc run_test {sqlite_exec sql expected_output} {
set actual_output [evaluate_sql $sqlite_exec $sql]
proc run_test {sqlite_exec db_name sql expected_output} {
set actual_output [evaluate_sql $sqlite_exec $db_name $sql]
if {$actual_output ne $expected_output} {
puts "Test FAILED: '$sql'"
puts "returned '$actual_output'"
Expand All @@ -17,8 +18,17 @@ proc run_test {sqlite_exec sql expected_output} {
}

proc do_execsql_test {test_name sql_statements expected_outputs} {
puts "Running test: $test_name"
foreach db $::test_dbs {
puts [format "(%s) %s Running test: %s" $db [string repeat " " [expr {40 - [string length $db]}]] $test_name]
set combined_sql [string trim $sql_statements]
set combined_expected_output [join $expected_outputs "\n"]
run_test $::sqlite_exec $db $combined_sql $combined_expected_output
}
}

proc do_execsql_test_on_specific_db {db_name test_name sql_statements expected_outputs} {
puts [format "(%s) %s Running test: %s" $db_name [string repeat " " [expr {40 - [string length $db_name]}]] $test_name]
set combined_sql [string trim $sql_statements]
set combined_expected_output [join $expected_outputs "\n"]
run_test $::sqlite_exec $combined_sql $combined_expected_output
run_test $::sqlite_exec $db_name $combined_sql $combined_expected_output
}
Binary file added testing/testing_norowidalias.db
Binary file not shown.

0 comments on commit 987a8bf

Please sign in to comment.