mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-24 11:34:21 +01:00
The broken test case does not pass on SQLite so it's wrong. I suspect
the test was written before commit e377e09 ("Fix avg(), total(), count()
default value on empty set") when Limbo showed this behavior.
129 lines
2.9 KiB
Tcl
Executable File
129 lines
2.9 KiB
Tcl
Executable File
#!/usr/bin/env tclsh
|
|
|
|
set sqlite_exec [expr {[info exists env(SQLITE_EXEC)] ? $env(SQLITE_EXEC) : "sqlite3"}]
|
|
|
|
proc evaluate_sql {sqlite_exec sql} {
|
|
set command [list $sqlite_exec testing/testing.db $sql]
|
|
set output [exec {*}$command]
|
|
return $output
|
|
}
|
|
|
|
proc run_test {sqlite_exec sql expected_output} {
|
|
set actual_output [evaluate_sql $sqlite_exec $sql]
|
|
if {$actual_output ne $expected_output} {
|
|
puts "Test FAILED: '$sql'"
|
|
puts "returned '$actual_output'"
|
|
puts "expected '$expected_output'"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
proc do_execsql_test {test_name sql_statements expected_outputs} {
|
|
puts "Running test: $test_name"
|
|
set combined_sql [join $sql_statements " "]
|
|
set combined_expected_output [join $expected_outputs "\n"]
|
|
run_test $::sqlite_exec $combined_sql $combined_expected_output
|
|
}
|
|
|
|
do_execsql_test select-const-1 {
|
|
SELECT 1
|
|
} {1}
|
|
|
|
do_execsql_test select-const-2 {
|
|
SELECT 2
|
|
} {2}
|
|
|
|
do_execsql_test select-avg {
|
|
SELECT avg(age) FROM users;
|
|
} {50.396}
|
|
|
|
do_execsql_test select-sum {
|
|
SELECT sum(age) FROM users;
|
|
} {503960}
|
|
|
|
do_execsql_test select-total {
|
|
SELECT sum(age) FROM users;
|
|
} {503960}
|
|
|
|
do_execsql_test select-limit {
|
|
SELECT id FROM users LIMIT 1;
|
|
} {1}
|
|
|
|
do_execsql_test select-count {
|
|
SELECT count(id) FROM users;
|
|
} {10000}
|
|
|
|
do_execsql_test select-max {
|
|
SELECT max(age) FROM users;
|
|
} {100}
|
|
|
|
do_execsql_test select-min {
|
|
SELECT min(age) FROM users;
|
|
} {1}
|
|
|
|
do_execsql_test select-limit-0 {
|
|
SELECT id FROM users LIMIT 0;
|
|
} {}
|
|
|
|
do_execsql_test pragma-cache-size {
|
|
PRAGMA cache_size
|
|
} {-2000}
|
|
|
|
|
|
do_execsql_test cross-join {
|
|
select * from users, products limit 1;
|
|
} {1|Jamie|Foster|dylan00@example.com|496-522-9493|62375\ Johnson\ Rest\ Suite\ 322|West\ Lauriestad|IL|35865|94|1|hat|79.0}
|
|
|
|
do_execsql_test cross-join-specific-columns {
|
|
select first_name, price from users, products limit 1;
|
|
} {Jamie|79.0}
|
|
|
|
do_execsql_test realify {
|
|
select price from products limit 1;
|
|
} {79.0}
|
|
|
|
do_execsql_test where-clause-eq {
|
|
select last_name from users where id = 2000;
|
|
} {Rodriguez}
|
|
|
|
do_execsql_test where-clause-eq-string {
|
|
select count(1) from users where last_name = 'Rodriguez';
|
|
} {61}
|
|
|
|
do_execsql_test where-clause-ne {
|
|
select count(1) from users where id != 2000;
|
|
} {9999}
|
|
|
|
do_execsql_test where-clause-gt {
|
|
select count(1) from users where id > 2000;
|
|
} {8000}
|
|
|
|
do_execsql_test where-clause-gte {
|
|
select count(1) from users where id >= 2000;
|
|
} {8001}
|
|
|
|
do_execsql_test where-clause-lt {
|
|
select count(1) from users where id < 2000;
|
|
} {1999}
|
|
|
|
do_execsql_test where-clause-lte {
|
|
select count(1) from users where id <= 2000;
|
|
} {2000}
|
|
|
|
do_execsql_test where-clause-unary-true {
|
|
select count(1) from users where 1;
|
|
} {10000}
|
|
|
|
# not correct? should be 0?
|
|
do_execsql_test where-clause-unary-false {
|
|
select count(1) from users where 0;
|
|
} {0}
|
|
|
|
do_execsql_test where-clause-no-table-unary-true {
|
|
select 1 where 1;
|
|
} {1}
|
|
|
|
do_execsql_test where-clause-no-table-unary-false {
|
|
select 1 where 0;
|
|
} {}
|