From 5cf791dff41f0b4ae79efb723ae1813792ff2c2c Mon Sep 17 00:00:00 2001 From: Phil Estival Date: Tue, 26 Nov 2024 13:20:56 +0100 Subject: [PATCH 10/10] test-ob-sql.el: add session tests on sqlite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — additional macro for result equality checks — rename testing functions ob-sql/* → ob-test/*. as they are generic to any babel result check — correct docstrings --- testing/lisp/test-ob-sql.el | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el index ac8a1ccb2..acea431de 100644 --- a/testing/lisp/test-ob-sql.el +++ b/testing/lisp/test-ob-sql.el @@ -31,7 +31,7 @@ ,@body))) (defmacro ob-sql/command-should-contain (regexp sql-block) - "Check that REGEXP is contained in the command executed when evaluating SQL-BLOCK." + "Check that REGEXP matches the value returned by the evaluation of SQL-BLOCK." `(let ((regexps ,(if (listp regexp) regexp `(list ,regexp))) (command (ob-sql/command (org-test-with-temp-text ,sql-block @@ -41,7 +41,7 @@ (should (string-match-p regexp command))))) (defmacro ob-sql/command-should-not-contain (regexp sql-block) - "Check that REGEXP is not contained in the command executed when evaluating SQL-BLOCK." + "Check that REGEXP does ot match the returned value of the evaluation of SQL-BLOCK." `(let ((command (ob-sql/command (org-test-with-temp-text ,sql-block @@ -49,6 +49,16 @@ (org-babel-execute-src-block))))) (should-not (string-match-p ,regexp command)))) +(defmacro ob-sql/command-equals (str sql-block) + "Check the equality of STR with the value returned by the evaluation of SQL-BLOCK." + `(let ((strings ,(if (listp str) str `(list ,str))) + (command (ob-sql/command (org-test-with-temp-text + ,sql-block + (org-babel-next-src-block) + (org-babel-execute-src-block))))) + (dolist (s strings) + (should (string= s command))))) + ;;; dbish (ert-deftest ob-sql/engine-dbi-uses-dbish () (ob-sql/command-should-contain "^dbish " " @@ -371,9 +381,27 @@ select * from dummy; #+end_src")) -(ert-deftest ob-sql/engine-vertica-passes-port-if-provided () - (ob-sql/command-should-contain " -p 12345 " " -#+begin_src sql :engine vertica :dbport 12345 - select * from dummy; +(ert-deftest ob-sql-sesssion-001/engine-sqlite-headers-off () + (ob-sql/command-equals "" " +#+begin_src sql :engine sqlite :session A :results raw +.headers off +#+end_src")) + +(ert-deftest ob-sql-sesssion-002/engine-sqlite-session-continuation () + (ob-sql/command-equals "Emacs\n" " +#+begin_src sql :engine sqlite :session A :results raw +select 'Emacs' as 'your preffered editor' +#+end_src")) + +(ert-deftest ob-sql-sesssion-003/engine-sqlite-headers-on () + (ob-sql/command-equals "" " +#+begin_src sql :engine sqlite :session A :results raw +.headers on +#+end_src")) + +(ert-deftest ob-sql-sesssion-004/engine-sqlite-session-continuation () + (ob-sql/command-equals "your preffered editor\nEmacs\n" " +#+begin_src sql :engine sqlite :session A :results raw +select 'Emacs' as 'your preffered editor' #+end_src")) (provide 'test-ob-sql) -- 2.39.5