Skip to content

Commit 5ed8298

Browse files
committed
align ob-sql & test git with the patch for the repo
1 parent 7b9781b commit 5ed8298

File tree

2 files changed

+431
-382
lines changed

2 files changed

+431
-382
lines changed

ob-sql-session-tests.el

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
;;; Code:
66

77
(load-file "./ob-sql.el")
8+
9+
(require 'org)
10+
(require 'sql)
11+
(require 'ert)
812
(org-version nil t t)
913
;; redefine (or patch...)
1014
(defun sql-comint-sqlite (product &optional options buf-name)
@@ -69,43 +73,70 @@ Compare the result against EXPECT."
6973
(org-babel-next-src-block)
7074
(org-babel-execute-src-block)
7175
(message "=>\n%s" (results-block-contents))
72-
(should (string= expect (results-block-contents)))
76+
(should (equal expect (results-block-contents)))
7377
)))))
7478

75-
(defun sqlite-test (code expect)
76-
"SQL test CODE block, EXPECT 'ing this result."
79+
(defun sqlite-test (code expect &optional header-args)
80+
"Test CODE block with optional HEADER-ARGS, EXPECT ing this result."
81+
(babel-block-test
82+
#'setup (concat "sql :engine sqlite :results raw " header-args)
83+
code expect))
84+
85+
(defun sqlite-test-table (code expect &optional header-args)
86+
"Test CODE block with optional HEADER-ARGS, EXPECT ing this result."
7787
(babel-block-test
78-
#'setup "sql :engine sqlite :session sqlite::tests :results raw"
88+
#'setup (concat "sql :engine sqlite :results table output " header-args)
7989
code expect))
8090

91+
(ert-deftest 000-sqlite:test-select ()
92+
"Basic select."
93+
(sqlite-test "select 1" "1\n" ))
94+
95+
(ert-deftest 000-sqlite:test-session-select ()
96+
"Basic select."
97+
(sqlite-test "select 1,2" "1|2\n" ":session sqlite::tests" ))
98+
99+
(ert-deftest 000-sqlite:test-select-table ()
100+
"Select table."
101+
(sqlite-test-table ".headers on
102+
select 1 as a, 2 as b;" '(("a" "b") (1 2)) nil))
103+
81104
(ert-deftest 000-sqlite:test-header ()
82-
"Create table."
105+
"Hedaers off."
83106
(sqlite-test ".headers off" nil))
84107

85108

86109
(ert-deftest 001-sqlite:test-create ()
87-
"Create table."
110+
"Header off, Create table."
88111
(sqlite-test ".headers off
89112
90-
create table test(one varchar(10), two int);" nil))
113+
create table test(one varchar(10), two int);"
114+
nil
115+
":session sqlite::tests"
116+
))
91117

92118
(ert-deftest 002-sqlite:test-insert ()
93119
"Insert into table."
94-
(sqlite-test "insert into test values(\'hello\',\'world\');" nil))
120+
(sqlite-test "insert into test values(\'hello\',\'world\');"
121+
nil
122+
":session sqlite::tests"))
95123

96124
(ert-deftest 003-sqlite:test-select ()
97125
"Select from table."
98126
(sqlite-test "select * from test;"
99-
"hello|world\n"))
127+
"hello|world\n"
128+
":session sqlite::tests"))
100129

101130
(ert-deftest 004-sqlite:test-filter-tabs ()
102131
"Insert with tabs."
103132
(sqlite-test "
104-
--create table test(x,y);
105-
select * from test;
133+
--create table test(x,y);
134+
select * from test;
106135
107136
"
108-
"hello|world\n"))
137+
"hello|world\n"
138+
":session sqlite::tests"
139+
))
109140

110141
;; gh is on SQLite version 3.37.2 2022-01-06,
111142
;; and its error message is slightly different
@@ -149,20 +180,20 @@ create table test(one varchar(10), two int);" nil))
149180
"one|two
150181
sqlite|3.4
151182
1|2
152-
"))
183+
" ":session sqlite::tests"))
153184

154185
;; additionally, an error after a command can clutter the next shell
155186
;;
156187

157188
(defun pg-test (code expect)
158-
"Test Postgres SQL CODE, with EXPECT 'ed result."
189+
"Test Postgres sql CODE, with EXPECT ed result."
159190
(babel-block-test
160191
#'setup
161192
"sql :engine postgres :dbhost localhost :database pg :dbuser pg :dbpassword pg :results raw :var var=33"
162193
code expect))
163194

164195
(defun pg-test-session (code expect)
165-
"Test Postgres SQL CODE, with EXPECT 'ed result."
196+
"Test Postgres SQL CODE in a session, with EXPECT ed result."
166197
(babel-block-test
167198
#'setup
168199
"sql :engine postgres :dbhost localhost :database pg :dbuser pg :dbpassword pg :results raw \

0 commit comments

Comments
 (0)