Merge pull request #297 from seancorfield/lazytest

migrate test suite to lazytest
This commit is contained in:
Sean Corfield 2025-03-12 18:02:34 -07:00 committed by GitHub
commit e650137f07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 234 additions and 88 deletions

View file

@ -0,0 +1,6 @@
{:linters {:cond-plus/empty-else {:level :error}
:cond-plus/missing-fn {:level :error}
:cond-plus/non-final-else {:level :error}
:cond-plus/sequence {:level :error}
:unresolved-symbol {:exclude [(cond-plus.core/cond+ [=> else])]}}
:hooks {:analyze-call {cond-plus.core/cond+ hooks.cond-plus-hook/cond+}}}

View file

@ -0,0 +1,65 @@
(ns hooks.cond-plus-hook
(:require [clj-kondo.hooks-api :as api]))
(defn analyze-clauses [clauses]
(reduce
(fn [found-else? clause]
;; non-sequence clause
(if (not (or (api/list-node? clause)
(api/vector-node? clause)))
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "must be sequence"
:type :cond-plus/sequence
:row row
:col col})
found-else?)
(let [[sym arrow fn-expr] (api/sexpr clause)]
(cond
;; non-final else
found-else?
(do (api/reg-finding!
(merge
{:message ":else must be in final position"
:type :cond-plus/non-final-else}
found-else?))
(reduced nil))
;; check fn-exprs
(and (or (= :> arrow)
(= '=> arrow))
(nil? fn-expr))
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "fn-expr must have third position symbol"
:type :cond-plus/missing-fn
:row row
:col col})
found-else?)
;; else handling
(or (= :else sym)
(= 'else sym))
(if found-else?
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message "only one :else clause allowed"
:type :cond-plus/empty-else
:row row
:col col})
;; early exit cuz not worth analyzing the rest
(reduced nil))
(do (when-not arrow
(let [{:keys [row col]} (meta clause)]
(api/reg-finding!
{:message ":else must have a body"
:type :cond-plus/empty-else
:row row
:col col})))
;; Store row and col from existing else as we don't throw until
;; we've seen a following clause
(select-keys (meta clause) [:row :col])))))))
nil
clauses))
(defn cond+ [{:keys [node]}]
(analyze-clauses (rest (:children node)))
node)

View file

@ -0,0 +1,23 @@
{:lint-as {lazytest.core/given clojure.core/let
lazytest.core/around clojure.core/fn
lazytest.core/defdescribe clojure.core/def
;; clojure.test interface
lazytest.experimental.interfaces.clojure-test/deftest clojure.test/deftest
lazytest.experimental.interfaces.clojure-test/testing clojure.test/testing
lazytest.experimental.interfaces.clojure-test/is clojure.test/is
lazytest.experimental.interfaces.clojure-test/are clojure.test/are
;; xunit interface
lazytest.experimental.interfaces.xunit/defsuite clojure.core/def
;; Expectations v2
lazytest.extensions.expectations/defexpect clojure.core/def
lazytest.extensions.expectations/from-each clojure.core/for
lazytest.extensions.expectations/=? clojure.core/=
}
:hooks {:analyze-call {;; Expectations v2
lazytest.extensions.expectations/more-> hooks.lazytest.expectations/more->
lazytest.extensions.expectations/more-of hooks.lazytest.expectations/more-of
}}
:linters {:clojure-lsp/unused-public-var
{:exclude-when-defined-by #{lazytest.core/defdescribe
lazytest.experimental.interfaces.xunit/defsuite
lazytest.experimental.interfaces.clojure-test/deftest}}}}

View file

@ -0,0 +1,31 @@
;; Copied from https://github.com/clojure-expectations/clojure-test/blob/b90ed5b24924238b3b16b0bbaaee4c3b05a1268a
(ns hooks.lazytest.expectations
(:require [clj-kondo.hooks-api :as api]))
(defn more-> [{:keys [node]}]
(let [tail (rest (:children node))
rewritten
(api/list-node
(list*
(api/token-node 'cond->)
(api/token-node 'nil)
tail))]
{:node rewritten}))
(defn more-of [{:keys [node]}]
(let [bindings (fnext (:children node))
pairs (partition 2 (nnext (:children node)))
rewritten
(api/list-node
(list*
(api/token-node 'fn)
(api/vector-node (vector bindings))
(map (fn [[e a]]
(api/list-node
(list
(api/token-node 'lazytest.core/expect)
e
a)))
pairs)))]
{:node rewritten}))

View file

@ -0,0 +1,4 @@
{:linters
{:unresolved-symbol
{:exclude [(cljs.test/is [match? thrown-match?])
(clojure.test/is [match? thrown-match?])]}}}

View file

@ -0,0 +1,5 @@
{:lint-as
{rewrite-clj.zip/subedit-> clojure.core/->
rewrite-clj.zip/subedit->> clojure.core/->>
rewrite-clj.zip/edit-> clojure.core/->
rewrite-clj.zip/edit->> clojure.core/->>}}

View file

@ -34,7 +34,7 @@ jobs:
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
- name: Run MariaDB Tests - name: Run MariaDB Tests
run: clojure -X:test run: clojure -M:test:runner
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MYSQL: yes

View file

@ -32,7 +32,7 @@ jobs:
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
- name: Run MariaDB Tests - name: Run MariaDB Tests
run: clojure -X:test run: clojure -M:test:runner
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MYSQL: yes
@ -71,7 +71,6 @@ jobs:
with: with:
path: | path: |
~/.m2/repository ~/.m2/repository
~/.gitlibs
~/.clojure ~/.clojure
~/.cpcache ~/.cpcache
key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }}

View file

@ -32,13 +32,13 @@ jobs:
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
- name: Run MariaDB Tests - name: Run MariaDB Tests
run: clojure -X:test run: clojure -M:test:runner
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MYSQL: yes
NEXT_JDBC_TEST_MARIADB: yes NEXT_JDBC_TEST_MARIADB: yes
- name: Run All Tests - name: Run All Tests
run: clojure -X:test run: clojure -M:test:runner
env: env:
MYSQL_ROOT_PASSWORD: testing MYSQL_ROOT_PASSWORD: testing
NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MYSQL: yes

9
.gitignore vendored
View file

@ -1,11 +1,8 @@
*.class
*.jar
*.swp
*~
.calva/output-window/ .calva/output-window/
.calva/repl.calva-repl .calva/repl.calva-repl
.classpath .classpath
.clj-kondo/.cache .clj-kondo/.cache
.clj-kondo/.lock
.cpcache .cpcache
.eastwood .eastwood
.factorypath .factorypath
@ -23,6 +20,10 @@
.settings .settings
.socket-repl-port .socket-repl-port
.sw* .sw*
*.class
*.jar
*.swp
*~
/checkouts /checkouts
/classes /classes
/clojure_test_* /clojure_test_*

View file

@ -51,7 +51,7 @@ From a `DataSource`, either you or `next.jdbc` can create a `java.sql.Connection
The primary SQL execution API in `next.jdbc` is: The primary SQL execution API in `next.jdbc` is:
* `plan` -- yields an `IReduceInit` that, when reduced with an initial value, executes the SQL statement and then reduces over the `ResultSet` with as little overhead as possible. * `plan` -- yields an `IReduceInit` that, when reduced with an initial value, executes the SQL statement and then reduces over the `ResultSet` with as little overhead as possible.
* `execute!` -- executes the SQL statement and produces a vector of realized hash maps, that use qualified keywords for the column names, of the form `:<table>/<column>`. If you join across multiple tables, the qualified keywords will reflect the originating tables for each of the columns. If the SQL produces named values that do not come from an associated table, a simple, unqualified keyword will be used. The realized hash maps returned by `execute!` are `Datafiable` and thus `Navigable` (see Clojure 1.10's `datafy` and `nav` functions, and tools like [Portal](https://github.com/djblue/portal), [Reveal](https://github.com/vlaaad/reveal), and Cognitect's REBL). Alternatively, you can specify `{:builder-fn rs/as-arrays}` and produce a vector with column names followed by vectors of row values. `rs/as-maps` is the default for `:builder-fn` but there are also `rs/as-unqualified-maps` and `rs/as-unqualified-arrays` if you want unqualified `:<column>` column names (and there are also lower-case variants of all of these). * `execute!` -- executes the SQL statement and produces a vector of realized hash maps, that use qualified keywords for the column names, of the form `:<table>/<column>`. If you join across multiple tables, the qualified keywords will reflect the originating tables for each of the columns. If the SQL produces named values that do not come from an associated table, a simple, unqualified keyword will be used. The realized hash maps returned by `execute!` are `Datafiable` and thus `Navigable` (see Clojure 1.10's `datafy` and `nav` functions, and tools like [Portal](https://github.com/djblue/portal), [Reveal](https://github.com/vlaaad/reveal), and Nubank's Morse -- formerly Cognitect's REBL). Alternatively, you can specify `{:builder-fn rs/as-arrays}` and produce a vector with column names followed by vectors of row values. `rs/as-maps` is the default for `:builder-fn` but there are also `rs/as-unqualified-maps` and `rs/as-unqualified-arrays` if you want unqualified `:<column>` column names (and there are also lower-case variants of all of these).
* `execute-one!` -- executes the SQL or DDL statement and produces a single realized hash map. The realized hash map returned by `execute-one!` is `Datafiable` and thus `Navigable`. * `execute-one!` -- executes the SQL or DDL statement and produces a single realized hash map. The realized hash map returned by `execute-one!` is `Datafiable` and thus `Navigable`.
In addition, there are API functions to create `PreparedStatement`s (`prepare`) from `Connection`s, which can be passed to `plan`, `execute!`, or `execute-one!`, and to run code inside a transaction (the `transact` function and the `with-transaction` macro). In addition, there are API functions to create `PreparedStatement`s (`prepare`) from `Connection`s, which can be passed to `plan`, `execute!`, or `execute-one!`, and to run code inside a transaction (the `transact` function and the `with-transaction` macro).

View file

@ -5,7 +5,7 @@
clojure -T:build deploy clojure -T:build deploy
Run tests via: Run tests via:
clojure -X:test clojure -M:test:runner
For more information, run: For more information, run:
@ -27,7 +27,7 @@
cmds (b/java-command cmds (b/java-command
{:basis basis {:basis basis
:main 'clojure.main :main 'clojure.main
:main-args ["-m" "cognitect.test-runner"]}) :main-args ["-m" "lazytest.main"]})
{:keys [exit]} (b/process cmds)] {:keys [exit]} (b/process cmds)]
(when-not (zero? exit) (throw (ex-info "Tests failed" {}))))) (when-not (zero? exit) (throw (ex-info "Tests failed" {})))))
opts) opts)

View file

@ -17,10 +17,9 @@
:1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0"}}} :1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0"}}}
;; running tests/checks of various kinds: ;; running tests/checks of various kinds:
:test {:extra-paths ["test"] ; can also run clojure -X:test :test {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
io.github.cognitect-labs/test-runner io.github.noahtheduke/lazytest {:mvn/version "1.6.1"}
{:git/tag "v0.5.1" :git/sha "dfb30dd"}
;; connection pooling ;; connection pooling
com.zaxxer/HikariCP {:mvn/version "6.2.1"} com.zaxxer/HikariCP {:mvn/version "6.2.1"}
com.mchange/c3p0 {:mvn/version "0.10.1"} com.mchange/c3p0 {:mvn/version "0.10.1"}
@ -49,6 +48,7 @@
org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.24.2"} org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.24.2"}
org.apache.logging.log4j/log4j-jcl {:mvn/version "2.24.2"} org.apache.logging.log4j/log4j-jcl {:mvn/version "2.24.2"}
org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.2"} org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.2"}
org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.2"}} org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.2"}
:jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"] org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.24.2"}}
:exec-fn cognitect.test-runner.api/test}}} :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"]}
:runner {:main-opts ["-m" "lazytest.main"]}}}

View file

@ -5,9 +5,10 @@
(defn- run-tests [env v] (defn- run-tests [env v]
(when v (println "\nTesting Clojure" v)) (when v (println "\nTesting Clojure" v))
(let [{:keys [exit]} (let [{:keys [exit]}
(p/shell {:extra-env env} "clojure" (str "-X" (p/shell {:extra-env env} "clojure" (str "-M"
(when v (str ":" v)) (when v (str ":" v))
":test"))] ":test:runner")
"--output" "dots")]
(when-not (zero? exit) (when-not (zero? exit)
(System/exit exit)))) (System/exit exit))))

View file

@ -7,7 +7,8 @@
At some point, the datasource/connection tests should probably be extended At some point, the datasource/connection tests should probably be extended
to accept EDN specs from an external source (environment variables?)." to accept EDN specs from an external source (environment variables?)."
(:require [clojure.string :as str] (:require [clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]] [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc.connection :as c] [next.jdbc.connection :as c]
[next.jdbc.protocols :as p] [next.jdbc.protocols :as p]
[next.jdbc.specs :as specs] [next.jdbc.specs :as specs]
@ -16,7 +17,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,4 +1,4 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.connection-test (ns next.jdbc.connection-test
"Tests for the main hash map spec to JDBC URL logic and the get-datasource "Tests for the main hash map spec to JDBC URL logic and the get-datasource
@ -7,7 +7,7 @@
At some point, the datasource/connection tests should probably be extended At some point, the datasource/connection tests should probably be extended
to accept EDN specs from an external source (environment variables?)." to accept EDN specs from an external source (environment variables?)."
(:require [clojure.string :as str] (:require [clojure.string :as str]
[clojure.test :refer [deftest is testing]] [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc.connection :as c] [next.jdbc.connection :as c]
[next.jdbc.protocols :as p]) [next.jdbc.protocols :as p])
(:import (com.zaxxer.hikari HikariDataSource) (:import (com.zaxxer.hikari HikariDataSource)

View file

@ -1,10 +1,11 @@
;; copyright (c) 2020-2024 Sean Corfield, all rights reserved ;; copyright (c) 2020-2025 Sean Corfield, all rights reserved
(ns next.jdbc.datafy-test (ns next.jdbc.datafy-test
"Tests for the datafy extensions over JDBC types." "Tests for the datafy extensions over JDBC types."
(:require [clojure.datafy :as d] (:require [clojure.datafy :as d]
[clojure.set :as set] [clojure.set :as set]
[clojure.test :refer [deftest is testing use-fixtures]] [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.datafy] [next.jdbc.datafy]
[next.jdbc.result-set :as rs] [next.jdbc.result-set :as rs]
@ -15,7 +16,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,4 +1,4 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.date-time-test (ns next.jdbc.date-time-test
"Date/time parameter auto-conversion tests. "Date/time parameter auto-conversion tests.
@ -6,17 +6,17 @@
These tests contain no assertions. Without requiring `next.jdbc.date-time` These tests contain no assertions. Without requiring `next.jdbc.date-time`
several of the `insert` operations would throw exceptions for some databases several of the `insert` operations would throw exceptions for some databases
so the test here just checks those operations 'succeed'." so the test here just checks those operations 'succeed'."
(:require [clojure.test :refer [deftest is testing use-fixtures]] (:require [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.date-time] ; to extend SettableParameter to date/time [next.jdbc.date-time] ; to extend SettableParameter to date/time
[next.jdbc.test-fixtures :refer [with-test-db db ds [next.jdbc.test-fixtures :refer [with-test-db ds
mssql? xtdb?]] mssql? xtdb?]]
[next.jdbc.specs :as specs]) [next.jdbc.specs :as specs]))
(:import (java.sql ResultSet)))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,9 +1,8 @@
;; copyright (c) 2020-2024 Sean Corfield, all rights reserved ;; copyright (c) 2020-2025 Sean Corfield, all rights reserved
(ns next.jdbc.default-options-test (ns next.jdbc.default-options-test
"Stub test namespace for default options. Nothing can really be tested "Stub test namespace for default options. Nothing can really be tested
at this level tho'..." at this level tho'..."
(:require [clojure.test :refer [deftest is testing]] (:require [next.jdbc.default-options]))
[next.jdbc.default-options :refer :all]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)

View file

@ -1,4 +1,4 @@
;; copyright (c) 2024 Sean Corfield, all rights reserved ;; copyright (c) 2024-2025 Sean Corfield, all rights reserved
(ns next.jdbc.defer-test (ns next.jdbc.defer-test
"The idea behind the next.jdbc.defer namespace is to provide a "The idea behind the next.jdbc.defer namespace is to provide a
@ -11,7 +11,8 @@
describes a series of SQL operations to be performed, that describes a series of SQL operations to be performed, that
are held in a dynamic var, and that can be executed at a are held in a dynamic var, and that can be executed at a
later time, in a transaction." later time, in a transaction."
(:require [clojure.test :refer [deftest is testing use-fixtures]] (:require [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.defer :as sut] [next.jdbc.defer :as sut]
[next.jdbc.test-fixtures [next.jdbc.test-fixtures
@ -19,7 +20,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(deftest basic-test (deftest basic-test
(when-not (xtdb?) (when-not (xtdb?)

View file

@ -1,9 +1,10 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.optional-test (ns next.jdbc.optional-test
"Test namespace for the optional builder functions." "Test namespace for the optional builder functions."
(:require [clojure.string :as str] (:require [clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]] [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc.optional :as opt] [next.jdbc.optional :as opt]
[next.jdbc.protocols :as p] [next.jdbc.protocols :as p]
[next.jdbc.test-fixtures :refer [col-kw column default-options ds index [next.jdbc.test-fixtures :refer [col-kw column default-options ds index
@ -13,7 +14,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(deftest test-map-row-builder (deftest test-map-row-builder
(testing "default row builder" (testing "default row builder"
@ -62,7 +63,7 @@
(is (= "Peach" ((column :FRUIT/name) row)))))) (is (= "Peach" ((column :FRUIT/name) row))))))
(defn- default-column-reader (defn- default-column-reader
[^ResultSet rs ^ResultSetMetaData rsmeta ^Integer i] [^ResultSet rs ^ResultSetMetaData _ ^Integer i]
(.getObject rs i)) (.getObject rs i))
(deftest test-map-row-adapter (deftest test-map-row-adapter

View file

@ -1,8 +1,9 @@
;; copyright (c) 2020-2024 Sean Corfield, all rights reserved ;; copyright (c) 2020-2025 Sean Corfield, all rights reserved
(ns next.jdbc.plan-test (ns next.jdbc.plan-test
"Tests for the plan helpers." "Tests for the plan helpers."
(:require [clojure.test :refer [deftest is use-fixtures]] (:require [lazytest.core :refer [around]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is]]
[next.jdbc.plan :as plan] [next.jdbc.plan :as plan]
[next.jdbc.specs :as specs] [next.jdbc.specs :as specs]
[next.jdbc.test-fixtures [next.jdbc.test-fixtures
@ -11,12 +12,10 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
;; around each test because of the folding tests using 1,000 rows
(use-fixtures :each with-test-db)
(specs/instrument) (specs/instrument)
(deftest select-one!-tests (deftest select-one!-tests
{:context [(around [f] (with-test-db f))]}
(is (= {(col-kw :id) 1} (is (= {(col-kw :id) 1}
(plan/select-one! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))]))) (plan/select-one! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))])))
(is (= 1 (is (= 1
@ -31,6 +30,7 @@
[(str "select * from fruit order by " (index))])))) [(str "select * from fruit order by " (index))]))))
(deftest select-vector-tests (deftest select-vector-tests
{:context [(around [f] (with-test-db f))]}
(is (= [{(col-kw :id) 1} {(col-kw :id) 2} {(col-kw :id) 3} {(col-kw :id) 4}] (is (= [{(col-kw :id) 1} {(col-kw :id) 2} {(col-kw :id) 3} {(col-kw :id) 4}]
(plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))]))) (plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))])))
(is (= [1 2 3 4] (is (= [1 2 3 4]
@ -45,6 +45,7 @@
[(str "select * from fruit where " (index) " = ?") 2])))) [(str "select * from fruit where " (index) " = ?") 2]))))
(deftest select-set-tests (deftest select-set-tests
{:context [(around [f] (with-test-db f))]}
(is (= #{{(col-kw :id) 1} {(col-kw :id) 2} {(col-kw :id) 3} {(col-kw :id) 4}} (is (= #{{(col-kw :id) 1} {(col-kw :id) 2} {(col-kw :id) 3} {(col-kw :id) 4}}
(plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))] (plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))]
{:into #{}}))) {:into #{}})))
@ -53,11 +54,13 @@
{:into #{}})))) {:into #{}}))))
(deftest select-map-tests (deftest select-map-tests
{:context [(around [f] (with-test-db f))]}
(is (= {1 "Apple", 2 "Banana", 3 "Peach", 4 "Orange"} (is (= {1 "Apple", 2 "Banana", 3 "Peach", 4 "Orange"}
(plan/select! (ds) (juxt (col-kw :id) :name) [(str "select * from fruit order by " (index))] (plan/select! (ds) (juxt (col-kw :id) :name) [(str "select * from fruit order by " (index))]
{:into {}})))) {:into {}}))))
(deftest select-issue-227 (deftest select-issue-227
{:context [(around [f] (with-test-db f))]}
(is (= ["Apple"] (is (= ["Apple"]
(plan/select! (ds) :name [(str "select * from fruit where " (index) " = ?") 1] (plan/select! (ds) :name [(str "select * from fruit where " (index) " = ?") 1]
{:column-fn #(str/replace % "-" "_")}))) {:column-fn #(str/replace % "-" "_")})))

View file

@ -1,4 +1,4 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.prepare-test (ns next.jdbc.prepare-test
"Stub test namespace for PreparedStatement creation etc. "Stub test namespace for PreparedStatement creation etc.
@ -8,7 +8,8 @@
The tests for the deprecated version of `execute-batch!` are here The tests for the deprecated version of `execute-batch!` are here
as a guard against regressions." as a guard against regressions."
(:require [clojure.test :refer [deftest is testing use-fixtures]] (:require [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.test-fixtures [next.jdbc.test-fixtures
:refer [with-test-db ds jtds? mssql? sqlite? xtdb?]] :refer [with-test-db ds jtds? mssql? sqlite? xtdb?]]
@ -17,7 +18,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,9 +1,8 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.protocols-test (ns next.jdbc.protocols-test
"Stub test namespace for low-level protocols. Nothing can really be tested "Stub test namespace for low-level protocols. Nothing can really be tested
at this level tho'..." at this level tho'..."
(:require [clojure.test :refer [deftest is testing]] (:require [next.jdbc.protocols]))
[next.jdbc.protocols :refer :all]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)

View file

@ -1,9 +1,9 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.quoted-test (ns next.jdbc.quoted-test
"Basic tests for quoting strategies. These are also tested indirectly "Basic tests for quoting strategies. These are also tested indirectly
via the next.jdbc.sql tests." via the next.jdbc.sql tests."
(:require [clojure.test :refer [deftest are testing]] (:require [lazytest.experimental.interfaces.clojure-test :refer [deftest are testing]]
[next.jdbc.quoted :refer [ansi mysql sql-server oracle postgres [next.jdbc.quoted :refer [ansi mysql sql-server oracle postgres
schema]])) schema]]))

View file

@ -1,4 +1,4 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.result-set-test (ns next.jdbc.result-set-test
"Test namespace for the result set functions. "Test namespace for the result set functions.
@ -8,7 +8,8 @@
(:require [clojure.core.protocols :as core-p] (:require [clojure.core.protocols :as core-p]
[clojure.datafy :as d] [clojure.datafy :as d]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]] [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]]
[next.jdbc.protocols :as p] [next.jdbc.protocols :as p]
[next.jdbc.result-set :as rs] [next.jdbc.result-set :as rs]
[next.jdbc.specs :as specs] [next.jdbc.specs :as specs]
@ -19,7 +20,7 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,11 +1,10 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.specs-test (ns next.jdbc.specs-test
"Stub test namespace for the specs. "Stub test namespace for the specs.
The specs are used (and 'tested') as part of the tests for the The specs are used (and 'tested') as part of the tests for the
next.jdbc and next.jdbc.sql namespaces." next.jdbc and next.jdbc.sql namespaces."
(:require [clojure.test :refer [deftest is testing]] (:require [next.jdbc.specs]))
[next.jdbc.specs :refer :all]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)

View file

@ -1,8 +1,8 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.sql.builder-test (ns next.jdbc.sql.builder-test
"Tests for the SQL string building functions in next.jdbc.sql.builder." "Tests for the SQL string building functions in next.jdbc.sql.builder."
(:require [clojure.test :refer [deftest is testing]] (:require [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing thrown?]]
[next.jdbc.quoted :refer [mysql sql-server]] [next.jdbc.quoted :refer [mysql sql-server]]
[next.jdbc.sql.builder :as builder])) [next.jdbc.sql.builder :as builder]))

View file

@ -1,19 +1,20 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.sql-test (ns next.jdbc.sql-test
"Tests for the syntactic sugar SQL functions." "Tests for the syntactic sugar SQL functions."
(:require [clojure.test :refer [deftest is testing use-fixtures]] (:require [lazytest.core :refer [around set-ns-context!]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing thrown?]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.specs :as specs] [next.jdbc.specs :as specs]
[next.jdbc.sql :as sql] [next.jdbc.sql :as sql]
[next.jdbc.test-fixtures [next.jdbc.test-fixtures
:refer [column col-kw default-options derby? ds index :refer [col-kw column default-options derby? ds index jtds?
jtds? maria? mssql? mysql? postgres? sqlite? with-test-db xtdb?]] maria? mssql? mysql? postgres? sqlite? with-test-db xtdb?]]
[next.jdbc.types :refer [as-other as-real as-varchar]])) [next.jdbc.types :refer [as-other as-real as-varchar]]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db) (set-ns-context! [(around [f] (with-test-db f))])
(specs/instrument) (specs/instrument)

View file

@ -1,17 +1,10 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc.transaction-test (ns next.jdbc.transaction-test
"Stub test namespace for transaction handling." "Stub test namespace for transaction handling."
(:require [clojure.test :refer [deftest is testing use-fixtures]] (:require [next.jdbc.specs :as specs]
[next.jdbc :as jdbc] [next.jdbc.transaction]))
[next.jdbc.specs :as specs]
[next.jdbc.test-fixtures :refer [with-test-db db ds column
default-options
derby? mssql? mysql? postgres?]]
[next.jdbc.transaction :as tx]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(use-fixtures :once with-test-db)
(specs/instrument) (specs/instrument)

View file

@ -1,8 +1,8 @@
;; copyright (c) 2020-2024 Sean Corfield, all rights reserved ;; copyright (c) 2020-2025 Sean Corfield, all rights reserved
(ns next.jdbc.types-test (ns next.jdbc.types-test
"Some tests for the type-assist functions." "Some tests for the type-assist functions."
(:require [clojure.test :refer [deftest is]] (:require [lazytest.experimental.interfaces.clojure-test :refer [deftest is]]
[next.jdbc.types :refer [as-varchar]])) [next.jdbc.types :refer [as-varchar]]))
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)

View file

@ -1,11 +1,12 @@
;; copyright (c) 2019-2024 Sean Corfield, all rights reserved ;; copyright (c) 2019-2025 Sean Corfield, all rights reserved
(ns next.jdbc-test (ns next.jdbc-test
"Basic tests for the primary API of `next.jdbc`." "Basic tests for the primary API of `next.jdbc`."
(:require (:require
[clojure.core.reducers :as r] [clojure.core.reducers :as r]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]] [lazytest.core :refer [around]]
[lazytest.experimental.interfaces.clojure-test :refer [deftest is testing thrown?]]
[next.jdbc :as jdbc] [next.jdbc :as jdbc]
[next.jdbc.connection :as c] [next.jdbc.connection :as c]
[next.jdbc.prepare :as prep] [next.jdbc.prepare :as prep]
@ -23,12 +24,10 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
;; around each test because of the folding tests using 1,000 rows
(use-fixtures :each with-test-db)
(specs/instrument) (specs/instrument)
(deftest spec-tests (deftest spec-tests
{:context [(around [f] (with-test-db f))]}
(let [db-spec {:dbtype "h2:mem" :dbname "clojure_test"}] (let [db-spec {:dbtype "h2:mem" :dbname "clojure_test"}]
;; some sanity checks on instrumented function calls: ;; some sanity checks on instrumented function calls:
(jdbc/get-datasource db-spec) (jdbc/get-datasource db-spec)
@ -39,6 +38,7 @@
(jdbc/get-connection db-spec')))) (jdbc/get-connection db-spec'))))
(deftest basic-tests (deftest basic-tests
{:context [(around [f] (with-test-db f))]}
;; use ds-opts instead of (ds) anywhere you want default options applied: ;; use ds-opts instead of (ds) anywhere you want default options applied:
(let [ds-opts (jdbc/with-options (ds) (default-options))] (let [ds-opts (jdbc/with-options (ds) (default-options))]
(testing "plan" (testing "plan"
@ -363,6 +363,7 @@ VALUES ('Pear', 'green', 49, 47)
(is (= ac (.getAutoCommit con)))))))) (is (= ac (.getAutoCommit con))))))))
(deftest issue-146 (deftest issue-146
{:context [(around [f] (with-test-db f))]}
;; since we use an embedded PostgreSQL data source, we skip this: ;; since we use an embedded PostgreSQL data source, we skip this:
(when-not (or (postgres?) (xtdb?) (when-not (or (postgres?) (xtdb?)
;; and now we skip MS SQL because we can't use the db-spec ;; and now we skip MS SQL because we can't use the db-spec
@ -479,6 +480,7 @@ VALUES ('Pear', 'green', 49, 47)
#_ #_
(deftest duplicate-insert-test (deftest duplicate-insert-test
{:context [(around [f] (with-test-db f))]}
;; this is primarily a look at exception types/information for #226 ;; this is primarily a look at exception types/information for #226
(try (try
(jdbc/execute! (ds) [" (jdbc/execute! (ds) ["
@ -501,6 +503,7 @@ VALUES ('Pear', 'green', 49, 47)
"\n\t" (ex-message t))))) "\n\t" (ex-message t)))))
(deftest bool-tests (deftest bool-tests
{:context [(around [f] (with-test-db f))]} ;; Ensure the test database is used
(testing (str "bool-tests for " (:dbtype (db))) (testing (str "bool-tests for " (:dbtype (db)))
(let [lit-t (cond (hsqldb?) "(1=1)" (mssql?) "1" :else "TRUE") (let [lit-t (cond (hsqldb?) "(1=1)" (mssql?) "1" :else "TRUE")
lit-f (cond (hsqldb?) "(1=0)" (mssql?) "0" :else "FALSE")] lit-f (cond (hsqldb?) "(1=0)" (mssql?) "0" :else "FALSE")]
@ -590,6 +593,7 @@ VALUES ('Pear', 'green', 49, 47)
(is (every? boolean? (map :twiddle data)))))))) (is (every? boolean? (map :twiddle data))))))))
(deftest execute-batch-tests (deftest execute-batch-tests
{:context [(around [f] (with-test-db f))]}
(when-not (xtdb?) (when-not (xtdb?)
(testing "simple batch insert" (testing "simple batch insert"
(is (= [1 1 1 1 1 1 1 1 1 13] (is (= [1 1 1 1 1 1 1 1 1 13]
@ -692,6 +696,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))))
(deftest execute-batch-connectable-tests (deftest execute-batch-connectable-tests
{:context [(around [f] (with-test-db f))]}
(when-not (xtdb?) (when-not (xtdb?)
(testing "simple batch insert" (testing "simple batch insert"
(is (= [1 1 1 1 1 1 1 1 1 13] (is (= [1 1 1 1 1 1 1 1 1 13]
@ -948,6 +953,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))))
(deftest folding-test (deftest folding-test
{:context [(around [f] (with-test-db f))]}
(jdbc/execute-one! (ds) ["delete from fruit"]) (jdbc/execute-one! (ds) ["delete from fruit"])
(if (xtdb?) (if (xtdb?)
(with-open [con (jdbc/get-connection (ds)) (with-open [con (jdbc/get-connection (ds))
@ -1006,6 +1012,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(is (= "Fruit-1000" (last result))))))) (is (= "Fruit-1000" (last result)))))))
(deftest connection-tests (deftest connection-tests
{:context [(around [f] (with-test-db f))]}
(testing "datasource via jdbcUrl" (testing "datasource via jdbcUrl"
(when-not (or (postgres?) (xtdb?)) (when-not (or (postgres?) (xtdb?))
(let [[url etc] (#'c/spec->url+etc (db)) (let [[url etc] (#'c/spec->url+etc (db))
@ -1032,6 +1039,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(is (instance? java.sql.Connection con))))))) (is (instance? java.sql.Connection con)))))))
(deftest multi-rs (deftest multi-rs
{:context [(around [f] (with-test-db f))]}
(when (mssql?) (when (mssql?)
(testing "script with multiple result sets" (testing "script with multiple result sets"
(let [multi-rs (let [multi-rs
@ -1080,6 +1088,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message)))))))) (println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
(deftest plan-misuse (deftest plan-misuse
{:context [(around [f] (with-test-db f))]}
(let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))] (let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))]
(is (re-find #"missing reduction" s))) (is (re-find #"missing reduction" s)))
(let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))] (let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))]
@ -1101,6 +1110,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) (doall (take 3 (jdbc/plan (ds) ["select * from fruit"]))))))
(deftest issue-204 (deftest issue-204
{:context [(around [f] (with-test-db f))]}
(testing "against a Connection" (testing "against a Connection"
(is (seq (with-open [con (jdbc/get-connection (ds))] (is (seq (with-open [con (jdbc/get-connection (ds))]
(jdbc/on-connection (jdbc/on-connection
@ -1121,6 +1131,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(jdbc/execute! x ["select * from fruit"])))))) (jdbc/execute! x ["select * from fruit"]))))))
(deftest issue-256 (deftest issue-256
{:context [(around [f] (with-test-db f))]}
(testing "against a Connection" (testing "against a Connection"
(is (seq (with-open [con (jdbc/get-connection (ds))] (is (seq (with-open [con (jdbc/get-connection (ds))]
(jdbc/on-connection+options (jdbc/on-connection+options