From 9dea335a0ab8afd762ffaa3b44aa371d6af27328 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Fri, 27 Dec 2024 11:39:02 -0300 Subject: [PATCH 1/2] Add test function with regex --- testing/tester.tcl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/testing/tester.tcl b/testing/tester.tcl index 04a43c3eb..b8cbff17f 100644 --- a/testing/tester.tcl +++ b/testing/tester.tcl @@ -26,6 +26,23 @@ proc do_execsql_test {test_name sql_statements expected_outputs} { } } +proc do_execsql_test_regex {test_name sql_statements expected_regex} { + 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 actual_output [evaluate_sql $::sqlite_exec $db $combined_sql] + + # Validate the actual output against the regular expression + if {![regexp $expected_regex $actual_output]} { + puts "Test FAILED: '$sql_statements'" + puts "returned '$actual_output'" + puts "expected to match regex '$expected_regex'" + exit 1 + } + } +} + + 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] From 2d0c16c428d8de0da8d63df969dd15dd9878f3da Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Fri, 27 Dec 2024 11:39:33 -0300 Subject: [PATCH 2/2] Fix sqlite_version() out of bound --- core/translate/expr.rs | 2 +- testing/scalar-functions.test | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/translate/expr.rs b/core/translate/expr.rs index 734dbb98e..31463f8d6 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -1555,7 +1555,7 @@ pub fn translate_expr( program.emit_insn(Insn::Copy { src_reg: output_register, dst_reg: target_register, - amount: 1, + amount: 0, }); Ok(target_register) } diff --git a/testing/scalar-functions.test b/testing/scalar-functions.test index e7f1c1b10..f04fa1765 100755 --- a/testing/scalar-functions.test +++ b/testing/scalar-functions.test @@ -809,6 +809,10 @@ do_execsql_test cast-small-float-to-numeric { SELECT typeof(CAST('1.23' AS NUMERIC)), CAST('1.23' AS NUMERIC); } {real|1.23} +do_execsql_test_regex sqlite-version-should-return-valid-output { + SELECT sqlite_version(); +} {\d+\.\d+\.\d+} + # TODO COMPAT: sqlite returns 9.22337203685478e+18, do we care...? # do_execsql_test cast-large-text-to-numeric { # SELECT typeof(CAST('9223372036854775808' AS NUMERIC)), CAST('9223372036854775808' AS NUMERIC);