From f77222069cb5f098be2e1e19290337b3f2b2bcde Mon Sep 17 00:00:00 2001 From: Phil Estival Date: Tue, 7 Jan 2025 04:29:05 +0100 Subject: [PATCH 5/5] testing/lisp/test-ob-sql.el: adds 4 tests for sessions on sqlite * test-ob-sql.el: test sessions. Also adds a macro for testing equality of a string with the result of a given block. Note : This is not proper to SQL and should move upwards. --- testing/lisp/test-ob-sql.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el index ac8a1ccb2..6afffc1e9 100644 --- a/testing/lisp/test-ob-sql.el +++ b/testing/lisp/test-ob-sql.el @@ -49,6 +49,18 @@ (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 " " @@ -377,5 +389,29 @@ select * from dummy; #+end_src")) +(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) ;;; test-ob-sql.el ends here -- 2.39.5