From 9dea335a0ab8afd762ffaa3b44aa371d6af27328 Mon Sep 17 00:00:00 2001 From: Diego Reis Date: Fri, 27 Dec 2024 11:39:02 -0300 Subject: [PATCH] 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]