@@ -83,7 +83,7 @@ create table tests
8383);
8484
8585-- -----------------------------------------------------------------------------
86- -- convenience functions for recording test results
86+ -- convenience function for recording test results
8787create function result (_test text , _expected text , _actual text ) returns bool
8888as $func$
8989merge into tests as t
@@ -95,92 +95,121 @@ when not matched then insert (test, actual) values (x.test, x.actual)
9595select passed from tests where test = _test;
9696$func$ language sql;
9797
98- create function result (_test text , _expected int , _actual int ) returns bool
99- return (select result(_test, _expected::text , _actual::text ))
100- ;
101-
102- create function result (_test text , _expected bool, _actual bool) returns bool
103- return (select result(_test, _expected::text , _actual::text ))
104- ;
105-
10698\pset tuples_only on
10799-- -----------------------------------------------------------------------------
108100-- openai tests
109101\getenv enable_openai_tests ENABLE_OPENAI_TESTS
102+ \if :{?enable_openai_tests}
103+ \else
104+ \set enable_openai_tests 0
105+ \endif
110106\if :enable_openai_tests
111107\set ON_ERROR_ROLLBACK on
112108\set ON_ERROR_STOP off
113109\i tests/ openai .sql
114110\set ON_ERROR_ROLLBACK off
115111\set ON_ERROR_STOP on
112+ \else
113+ \echo Skipped OpenAI tests
116114\endif
117115
118116-- -----------------------------------------------------------------------------
119117-- ollama tests
120118\getenv enable_ollama_tests ENABLE_OLLAMA_TESTS
119+ \if :{?enable_ollama_tests}
120+ \else
121+ \set enable_ollama_tests 0
122+ \endif
121123\if :enable_ollama_tests
122124\set ON_ERROR_ROLLBACK on
123125\set ON_ERROR_STOP off
124126\i tests/ ollama .sql
125127\set ON_ERROR_ROLLBACK off
126128\set ON_ERROR_STOP on
129+ \else
130+ \echo Skipped Ollama tests
127131\endif
128132
129133-- -----------------------------------------------------------------------------
130134-- anthropic tests
131135\getenv enable_anthropic_tests ENABLE_ANTHROPIC_TESTS
136+ \if :{?enable_anthropic_tests}
137+ \else
138+ \set enable_anthropic_tests 0
139+ \endif
132140\if :enable_anthropic_tests
133141\set ON_ERROR_ROLLBACK on
134142\set ON_ERROR_STOP off
135143\i tests/ anthropic .sql
136144\set ON_ERROR_ROLLBACK off
137145\set ON_ERROR_STOP on
146+ \else
147+ \echo Skipped Anthropic tests
138148\endif
139149
140150-- -----------------------------------------------------------------------------
141151-- cohere tests
142152\getenv enable_cohere_tests ENABLE_COHERE_TESTS
153+ \if :{?enable_cohere_tests}
154+ \else
155+ \set enable_cohere_tests 0
156+ \endif
143157\if :enable_cohere_tests
144158\set ON_ERROR_ROLLBACK on
145159\set ON_ERROR_STOP off
146160\i tests/ cohere .sql
147161\set ON_ERROR_ROLLBACK off
148162\set ON_ERROR_STOP on
163+ \else
164+ \echo Skipped Cohere tests
149165\endif
150166
151167\pset tuples_only off
152168-- -----------------------------------------------------------------------------
153169-- test results
154170\echo
155171\echo
156- \echo test results
172+ \echo
157173\echo
158174\echo
159175
160176\set ON_ERROR_STOP on
161177\set ON_ERROR_ROLLBACK off
162- \echo test results
163- select test, passed
164- from tests
165- ;
166178
167- \echo failed tests
168- select *
179+ -- we should fail if no tests were run
180+ select count ( * ) > 0 as result
169181from tests
170- where passed is distinct from true
171- ;
182+ \gset
172183
173- \echo test stats
174- select
175- count (* ) as total
176- , count (* ) filter (where passed = true) as passed
177- , count (* ) filter (where passed is distinct from true) as failed
178- from tests
179- ;
184+ \if :result
185+
186+ \echo test results
187+ select test, passed
188+ from tests
189+ ;
190+
191+ \echo failed tests
192+ select *
193+ from tests
194+ where passed is distinct from true
195+ ;
196+
197+ \echo test stats
198+ select
199+ count (* ) as total
200+ , count (* ) filter (where passed = true) as passed
201+ , count (* ) filter (where passed is distinct from true) as failed
202+ from tests
203+ ;
204+
205+ select count (* ) filter (where passed is distinct from true) = 0 as result
206+ from tests
207+ \gset
208+
209+ \else
210+ \warn NO TESTS WERE RUN!
211+ \endif
180212
181- select count (* ) filter (where passed is distinct from true) = 0 as result
182- from tests
183- \gset
184213
185214reset role; -- no longer tester
186215
0 commit comments