From 0d7d58fecea88c230e22c43beae1ca16638ad434 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 7 Mar 2025 17:31:13 -0800 Subject: [PATCH 1/9] migrate test suite to lazytest no longer tests against clojure 1.10 (issue created) Signed-off-by: Sean Corfield --- .../imports/cond_plus/cond_plus/config.edn | 6 ++ .../cond_plus/hooks/cond_plus_hook.clj | 65 +++++++++++++++++++ .../io.github.noahtheduke/lazytest/config.edn | 23 +++++++ .../hooks/lazytest/expectations.clj_kondo | 31 +++++++++ .../nubank/matcher-combinators/config.edn | 4 ++ .../rewrite-clj/rewrite-clj/config.edn | 5 ++ .github/workflows/test-and-release.yml | 2 +- .github/workflows/test-and-snapshot.yml | 2 +- .github/workflows/test.yml | 4 +- .gitignore | 9 +-- README.md | 2 +- build.clj | 6 +- deps.edn | 11 ++-- run-tests.clj | 9 +-- test/next/jdbc/connection_string_test.clj | 5 +- test/next/jdbc/connection_test.clj | 4 +- test/next/jdbc/datafy_test.clj | 7 +- test/next/jdbc/date_time_test.clj | 12 ++-- test/next/jdbc/default_options_test.clj | 5 +- test/next/jdbc/defer_test.clj | 7 +- test/next/jdbc/optional_test.clj | 9 +-- test/next/jdbc/plan_test.clj | 13 ++-- test/next/jdbc/prepare_test.clj | 7 +- test/next/jdbc/protocols_test.clj | 5 +- test/next/jdbc/quoted_test.clj | 4 +- test/next/jdbc/result_set_test.clj | 7 +- test/next/jdbc/specs_test.clj | 5 +- test/next/jdbc/sql/builder_test.clj | 15 +++-- test/next/jdbc/sql_test.clj | 54 +++++++-------- test/next/jdbc/transaction_test.clj | 13 +--- test/next/jdbc/types_test.clj | 4 +- test/next/jdbc_test.clj | 49 ++++++++------ 32 files changed, 276 insertions(+), 128 deletions(-) create mode 100644 .clj-kondo/imports/cond_plus/cond_plus/config.edn create mode 100644 .clj-kondo/imports/cond_plus/cond_plus/hooks/cond_plus_hook.clj create mode 100644 .clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn create mode 100644 .clj-kondo/imports/io.github.noahtheduke/lazytest/hooks/lazytest/expectations.clj_kondo create mode 100644 .clj-kondo/imports/nubank/matcher-combinators/config.edn create mode 100644 .clj-kondo/imports/rewrite-clj/rewrite-clj/config.edn diff --git a/.clj-kondo/imports/cond_plus/cond_plus/config.edn b/.clj-kondo/imports/cond_plus/cond_plus/config.edn new file mode 100644 index 0000000..3315bb5 --- /dev/null +++ b/.clj-kondo/imports/cond_plus/cond_plus/config.edn @@ -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+}}} diff --git a/.clj-kondo/imports/cond_plus/cond_plus/hooks/cond_plus_hook.clj b/.clj-kondo/imports/cond_plus/cond_plus/hooks/cond_plus_hook.clj new file mode 100644 index 0000000..fc9f1a9 --- /dev/null +++ b/.clj-kondo/imports/cond_plus/cond_plus/hooks/cond_plus_hook.clj @@ -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) diff --git a/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn new file mode 100644 index 0000000..407d9c8 --- /dev/null +++ b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn @@ -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}}}} diff --git a/.clj-kondo/imports/io.github.noahtheduke/lazytest/hooks/lazytest/expectations.clj_kondo b/.clj-kondo/imports/io.github.noahtheduke/lazytest/hooks/lazytest/expectations.clj_kondo new file mode 100644 index 0000000..c13dcaf --- /dev/null +++ b/.clj-kondo/imports/io.github.noahtheduke/lazytest/hooks/lazytest/expectations.clj_kondo @@ -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})) diff --git a/.clj-kondo/imports/nubank/matcher-combinators/config.edn b/.clj-kondo/imports/nubank/matcher-combinators/config.edn new file mode 100644 index 0000000..ea4ded7 --- /dev/null +++ b/.clj-kondo/imports/nubank/matcher-combinators/config.edn @@ -0,0 +1,4 @@ +{:linters + {:unresolved-symbol + {:exclude [(cljs.test/is [match? thrown-match?]) + (clojure.test/is [match? thrown-match?])]}}} diff --git a/.clj-kondo/imports/rewrite-clj/rewrite-clj/config.edn b/.clj-kondo/imports/rewrite-clj/rewrite-clj/config.edn new file mode 100644 index 0000000..19ecae9 --- /dev/null +++ b/.clj-kondo/imports/rewrite-clj/rewrite-clj/config.edn @@ -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/->>}} diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 429c2b0..8d71bd3 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -34,7 +34,7 @@ jobs: env: MYSQL_ROOT_PASSWORD: testing - name: Run MariaDB Tests - run: clojure -X:test + run: clojure -M:test:runner:1.11 env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index 88a0194..f2ee425 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -32,7 +32,7 @@ jobs: env: MYSQL_ROOT_PASSWORD: testing - name: Run MariaDB Tests - run: clojure -X:test + run: clojure -M:test:runner:1.11 env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 551cf4e..3fc6b98 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,13 +32,13 @@ jobs: env: MYSQL_ROOT_PASSWORD: testing - name: Run MariaDB Tests - run: clojure -X:test + run: clojure -M:test:runner:1.11 env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MARIADB: yes - name: Run All Tests - run: clojure -X:test + run: clojure -M:test:runner:1.11 env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/.gitignore b/.gitignore index c59da33..79e33cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,8 @@ -*.class -*.jar -*.swp -*~ .calva/output-window/ .calva/repl.calva-repl .classpath .clj-kondo/.cache +.clj-kondo/.lock .cpcache .eastwood .factorypath @@ -23,6 +20,10 @@ .settings .socket-repl-port .sw* +*.class +*.jar +*.swp +*~ /checkouts /classes /clojure_test_* diff --git a/README.md b/README.md index 021827b..e5b7193 100644 --- a/README.md +++ b/README.md @@ -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: * `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 `:/`. 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 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 `:
/`. 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 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`. 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). diff --git a/build.clj b/build.clj index 7029fc2..b9cca79 100644 --- a/build.clj +++ b/build.clj @@ -5,7 +5,7 @@ clojure -T:build deploy Run tests via: - clojure -X:test + clojure -M:test:runner:1.11 For more information, run: @@ -21,13 +21,13 @@ (def class-dir "target/classes") (defn test "Run all the tests." [opts] - (doseq [alias [:1.10 :1.11 :1.12]] + (doseq [alias [#_:1.10 :1.11 :1.12]] (println "\nRunning tests for Clojure" (name alias)) (let [basis (b/create-basis {:aliases [:test alias]}) cmds (b/java-command {:basis basis :main 'clojure.main - :main-args ["-m" "cognitect.test-runner"]}) + :main-args ["-m" "lazytest.main"]}) {:keys [exit]} (b/process cmds)] (when-not (zero? exit) (throw (ex-info "Tests failed" {}))))) opts) diff --git a/deps.edn b/deps.edn index 40f6dff..cc4b722 100644 --- a/deps.edn +++ b/deps.edn @@ -17,10 +17,9 @@ :1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0"}}} ;; running tests/checks of various kinds: - :test {:extra-paths ["test"] ; can also run clojure -X:test - :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} - io.github.cognitect-labs/test-runner - {:git/tag "v0.5.1" :git/sha "dfb30dd"} + :test {:extra-paths ["test"] + :extra-deps {io.github.noahtheduke/lazytest {:mvn/version "1.5.0"} + org.clojure/test.check {:mvn/version "1.1.1"} ;; connection pooling com.zaxxer/HikariCP {:mvn/version "6.2.1"} com.mchange/c3p0 {:mvn/version "0.10.1"} @@ -50,5 +49,5 @@ 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-slf4j-impl {:mvn/version "2.24.2"}} - :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"] - :exec-fn cognitect.test-runner.api/test}}} + :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"]} + :runner {:main-opts ["-m" "lazytest.main"]}}} diff --git a/run-tests.clj b/run-tests.clj index 2e84aa3..8f8f898 100755 --- a/run-tests.clj +++ b/run-tests.clj @@ -5,9 +5,10 @@ (defn- run-tests [env v] (when v (println "\nTesting Clojure" v)) (let [{:keys [exit]} - (p/shell {:extra-env env} "clojure" (str "-X" - (when v (str ":" v)) - ":test"))] + (p/shell {:extra-env env} + "clojure" + (str "-M" (when v (str ":" v)) ":test:runner") + "--output" "dots")] (when-not (zero? exit) (System/exit exit)))) @@ -22,5 +23,5 @@ (assoc "NEXT_JDBC_TEST_MARIADB" "yes") xtdb? (assoc "NEXT_JDBC_TEST_XTDB" "yes"))] - (doseq [v (if all? ["1.10" "1.11" "1.12"] [nil])] + (doseq [v (if all? [#_"1.10" "1.11" "1.12"] [nil])] (run-tests env v))) diff --git a/test/next/jdbc/connection_string_test.clj b/test/next/jdbc/connection_string_test.clj index aa3767b..5dbb3da 100644 --- a/test/next/jdbc/connection_string_test.clj +++ b/test/next/jdbc/connection_string_test.clj @@ -7,7 +7,8 @@ At some point, the datasource/connection tests should probably be extended to accept EDN specs from an external source (environment variables?)." (: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.protocols :as p] [next.jdbc.specs :as specs] @@ -16,7 +17,7 @@ (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) diff --git a/test/next/jdbc/connection_test.clj b/test/next/jdbc/connection_test.clj index af8e9eb..97b5c25 100644 --- a/test/next/jdbc/connection_test.clj +++ b/test/next/jdbc/connection_test.clj @@ -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 "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 to accept EDN specs from an external source (environment variables?)." (: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.protocols :as p]) (:import (com.zaxxer.hikari HikariDataSource) diff --git a/test/next/jdbc/datafy_test.clj b/test/next/jdbc/datafy_test.clj index 4aaf89c..78eb35a 100644 --- a/test/next/jdbc/datafy_test.clj +++ b/test/next/jdbc/datafy_test.clj @@ -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 "Tests for the datafy extensions over JDBC types." (:require [clojure.datafy :as d] [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.datafy] [next.jdbc.result-set :as rs] @@ -15,7 +16,7 @@ (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) diff --git a/test/next/jdbc/date_time_test.clj b/test/next/jdbc/date_time_test.clj index 4bab04e..c0d749f 100644 --- a/test/next/jdbc/date_time_test.clj +++ b/test/next/jdbc/date_time_test.clj @@ -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 "Date/time parameter auto-conversion tests. @@ -6,17 +6,17 @@ These tests contain no assertions. Without requiring `next.jdbc.date-time` several of the `insert` operations would throw exceptions for some databases 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.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?]] - [next.jdbc.specs :as specs]) - (:import (java.sql ResultSet))) + [next.jdbc.specs :as specs])) (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) diff --git a/test/next/jdbc/default_options_test.clj b/test/next/jdbc/default_options_test.clj index 2d2f5e2..65d8592 100644 --- a/test/next/jdbc/default_options_test.clj +++ b/test/next/jdbc/default_options_test.clj @@ -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 "Stub test namespace for default options. Nothing can really be tested at this level tho'..." - (:require [clojure.test :refer [deftest is testing]] - [next.jdbc.default-options :refer :all])) + (:require [next.jdbc.default-options])) (set! *warn-on-reflection* true) diff --git a/test/next/jdbc/defer_test.clj b/test/next/jdbc/defer_test.clj index d4285de..5332b4a 100644 --- a/test/next/jdbc/defer_test.clj +++ b/test/next/jdbc/defer_test.clj @@ -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 "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 are held in a dynamic var, and that can be executed at a 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.defer :as sut] [next.jdbc.test-fixtures @@ -19,7 +20,7 @@ (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (deftest basic-test (when-not (xtdb?) diff --git a/test/next/jdbc/optional_test.clj b/test/next/jdbc/optional_test.clj index 1a71f43..5ba4ca4 100644 --- a/test/next/jdbc/optional_test.clj +++ b/test/next/jdbc/optional_test.clj @@ -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 "Test namespace for the optional builder functions." (: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.protocols :as p] [next.jdbc.test-fixtures :refer [col-kw column default-options ds index @@ -13,7 +14,7 @@ (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 (testing "default row builder" @@ -62,7 +63,7 @@ (is (= "Peach" ((column :FRUIT/name) row)))))) (defn- default-column-reader - [^ResultSet rs ^ResultSetMetaData rsmeta ^Integer i] + [^ResultSet rs ^ResultSetMetaData _ ^Integer i] (.getObject rs i)) (deftest test-map-row-adapter diff --git a/test/next/jdbc/plan_test.clj b/test/next/jdbc/plan_test.clj index c477a8f..bbdb5cb 100644 --- a/test/next/jdbc/plan_test.clj +++ b/test/next/jdbc/plan_test.clj @@ -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 "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.specs :as specs] [next.jdbc.test-fixtures @@ -11,12 +12,10 @@ (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) (deftest select-one!-tests + {:context [(around [f] (with-test-db f))]} (is (= {(col-kw :id) 1} (plan/select-one! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))]))) (is (= 1 @@ -31,6 +30,7 @@ [(str "select * from fruit order by " (index))])))) (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}] (plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))]))) (is (= [1 2 3 4] @@ -45,6 +45,7 @@ [(str "select * from fruit where " (index) " = ?") 2])))) (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}} (plan/select! (ds) [(col-kw :id)] [(str "select * from fruit order by " (index))] {:into #{}}))) @@ -53,11 +54,13 @@ {:into #{}})))) (deftest select-map-tests + {:context [(around [f] (with-test-db f))]} (is (= {1 "Apple", 2 "Banana", 3 "Peach", 4 "Orange"} (plan/select! (ds) (juxt (col-kw :id) :name) [(str "select * from fruit order by " (index))] {:into {}})))) (deftest select-issue-227 + {:context [(around [f] (with-test-db f))]} (is (= ["Apple"] (plan/select! (ds) :name [(str "select * from fruit where " (index) " = ?") 1] {:column-fn #(str/replace % "-" "_")}))) diff --git a/test/next/jdbc/prepare_test.clj b/test/next/jdbc/prepare_test.clj index 675f5ae..ab6136b 100644 --- a/test/next/jdbc/prepare_test.clj +++ b/test/next/jdbc/prepare_test.clj @@ -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 "Stub test namespace for PreparedStatement creation etc. @@ -8,7 +8,8 @@ The tests for the deprecated version of `execute-batch!` are here 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.test-fixtures :refer [with-test-db ds jtds? mssql? sqlite? xtdb?]] @@ -17,7 +18,7 @@ (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) diff --git a/test/next/jdbc/protocols_test.clj b/test/next/jdbc/protocols_test.clj index 541335f..9e38253 100644 --- a/test/next/jdbc/protocols_test.clj +++ b/test/next/jdbc/protocols_test.clj @@ -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 "Stub test namespace for low-level protocols. Nothing can really be tested at this level tho'..." - (:require [clojure.test :refer [deftest is testing]] - [next.jdbc.protocols :refer :all])) + (:require [next.jdbc.protocols])) (set! *warn-on-reflection* true) diff --git a/test/next/jdbc/quoted_test.clj b/test/next/jdbc/quoted_test.clj index 8a1a233..2a0d0cb 100644 --- a/test/next/jdbc/quoted_test.clj +++ b/test/next/jdbc/quoted_test.clj @@ -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 "Basic tests for quoting strategies. These are also tested indirectly 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 schema]])) diff --git a/test/next/jdbc/result_set_test.clj b/test/next/jdbc/result_set_test.clj index 8d893ac..b8e7caa 100644 --- a/test/next/jdbc/result_set_test.clj +++ b/test/next/jdbc/result_set_test.clj @@ -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 "Test namespace for the result set functions. @@ -8,7 +8,8 @@ (:require [clojure.core.protocols :as core-p] [clojure.datafy :as d] [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.result-set :as rs] [next.jdbc.specs :as specs] @@ -19,7 +20,7 @@ (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) diff --git a/test/next/jdbc/specs_test.clj b/test/next/jdbc/specs_test.clj index 20f7d09..e3f1c2a 100644 --- a/test/next/jdbc/specs_test.clj +++ b/test/next/jdbc/specs_test.clj @@ -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 "Stub test namespace for the specs. The specs are used (and 'tested') as part of the tests for the next.jdbc and next.jdbc.sql namespaces." - (:require [clojure.test :refer [deftest is testing]] - [next.jdbc.specs :refer :all])) + (:require [next.jdbc.specs])) (set! *warn-on-reflection* true) diff --git a/test/next/jdbc/sql/builder_test.clj b/test/next/jdbc/sql/builder_test.clj index 1d577bf..e229772 100644 --- a/test/next/jdbc/sql/builder_test.clj +++ b/test/next/jdbc/sql/builder_test.clj @@ -1,8 +1,9 @@ -;; copyright (c) 2019-2024 Sean Corfield, all rights reserved +;; copyright (c) 2019-2025 Sean Corfield, all rights reserved (ns next.jdbc.sql.builder-test "Tests for the SQL string building functions in next.jdbc.sql.builder." - (:require [clojure.test :refer [deftest is testing]] + (:require [lazytest.core :refer [throws?]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] [next.jdbc.quoted :refer [mysql sql-server]] [next.jdbc.sql.builder :as builder])) @@ -158,11 +159,11 @@ (deftest test-for-update (testing "empty example (would be a SQL error)" - (is (thrown? IllegalArgumentException - (builder/for-update :user - {:status 42} - {} - {:table-fn sql-server :column-fn mysql})))) + (is (throws? IllegalArgumentException + #(builder/for-update :user + {:status 42} + {} + {:table-fn sql-server :column-fn mysql})))) (testing "by example" (is (= (builder/for-update :user {:status 42} diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index c5259f6..d89f4f3 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -1,19 +1,21 @@ -;; copyright (c) 2019-2024 Sean Corfield, all rights reserved +;; copyright (c) 2019-2025 Sean Corfield, all rights reserved (ns next.jdbc.sql-test "Tests for the syntactic sugar SQL functions." - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [next.jdbc :as jdbc] - [next.jdbc.specs :as specs] - [next.jdbc.sql :as sql] - [next.jdbc.test-fixtures - :refer [column col-kw default-options derby? ds index - jtds? maria? mssql? mysql? postgres? sqlite? with-test-db xtdb?]] - [next.jdbc.types :refer [as-other as-real as-varchar]])) + (:require + [lazytest.core :refer [around set-ns-context! throws?]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] + [next.jdbc :as jdbc] + [next.jdbc.specs :as specs] + [next.jdbc.sql :as sql] + [next.jdbc.test-fixtures + :refer [col-kw column default-options derby? ds index jtds? + maria? mssql? mysql? postgres? sqlite? with-test-db xtdb?]] + [next.jdbc.types :refer [as-other as-real as-varchar]])) (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) +(set-ns-context! [(around [f] (with-test-db f))]) (specs/instrument) @@ -72,8 +74,8 @@ (when-not (xtdb?) ; XTDB does not support min/max on strings? (let [min-name (sql/aggregate-by-keys ds-opts :fruit "min(name)" :all)] (is (= "Apple" min-name)))) - (is (thrown? IllegalArgumentException - (sql/aggregate-by-keys ds-opts :fruit "count(*)" :all {:columns []}))))) + (is (throws? IllegalArgumentException + #(sql/aggregate-by-keys ds-opts :fruit "count(*)" :all {:columns []}))))) (deftest test-get-by-id (let [ds-opts (jdbc/with-options (ds) (default-options))] @@ -258,26 +260,26 @@ (is (= [] (sql/insert-multi! (ds) :fruit [] [])))))) (deftest no-empty-example-maps - (is (thrown? clojure.lang.ExceptionInfo - (sql/find-by-keys (ds) :fruit {}))) - (is (thrown? clojure.lang.ExceptionInfo - (sql/update! (ds) :fruit {} {}))) - (is (thrown? clojure.lang.ExceptionInfo - (sql/delete! (ds) :fruit {})))) + (is (throws? clojure.lang.ExceptionInfo + #(sql/find-by-keys (ds) :fruit {}))) + (is (throws? clojure.lang.ExceptionInfo + #(sql/update! (ds) :fruit {} {}))) + (is (throws? clojure.lang.ExceptionInfo + #(sql/delete! (ds) :fruit {})))) (deftest no-empty-columns - (is (thrown? clojure.lang.ExceptionInfo - (sql/insert-multi! (ds) :fruit [] [[] [] []])))) + (is (throws? clojure.lang.ExceptionInfo + #(sql/insert-multi! (ds) :fruit [] [[] [] []])))) (deftest no-mismatched-columns - (is (thrown? IllegalArgumentException - (sql/insert-multi! (ds) :fruit [{:name "Apple"} {:cost 1.23}])))) + (is (throws? IllegalArgumentException + #(sql/insert-multi! (ds) :fruit [{:name "Apple"} {:cost 1.23}])))) (deftest no-empty-order-by - (is (thrown? clojure.lang.ExceptionInfo - (sql/find-by-keys (ds) :fruit - {:name "Apple"} - {:order-by []})))) + (is (throws? clojure.lang.ExceptionInfo + #(sql/find-by-keys (ds) :fruit + {:name "Apple"} + {:order-by []})))) (deftest array-in (when (postgres?) diff --git a/test/next/jdbc/transaction_test.clj b/test/next/jdbc/transaction_test.clj index 0bba1d2..7bf02bd 100644 --- a/test/next/jdbc/transaction_test.clj +++ b/test/next/jdbc/transaction_test.clj @@ -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 "Stub test namespace for transaction handling." - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [next.jdbc :as jdbc] - [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])) + (:require [next.jdbc.specs :as specs] + [next.jdbc.transaction])) (set! *warn-on-reflection* true) -(use-fixtures :once with-test-db) - (specs/instrument) diff --git a/test/next/jdbc/types_test.clj b/test/next/jdbc/types_test.clj index 0594ede..3cf8441 100644 --- a/test/next/jdbc/types_test.clj +++ b/test/next/jdbc/types_test.clj @@ -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 "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]])) (set! *warn-on-reflection* true) diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index fbab9ed..4b75ae8 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -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 "Basic tests for the primary API of `next.jdbc`." (:require [clojure.core.reducers :as r] [clojure.string :as str] - [clojure.test :refer [deftest is testing use-fixtures]] + [lazytest.core :refer [around throws?]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] [next.jdbc :as jdbc] [next.jdbc.connection :as c] [next.jdbc.prepare :as prep] @@ -23,12 +24,10 @@ (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) (deftest spec-tests + {:context [(around [f] (with-test-db f))]} (let [db-spec {:dbtype "h2:mem" :dbname "clojure_test"}] ;; some sanity checks on instrumented function calls: (jdbc/get-datasource db-spec) @@ -39,6 +38,7 @@ (jdbc/get-connection db-spec')))) (deftest basic-tests + {:context [(around [f] (with-test-db f))]} ;; use ds-opts instead of (ds) anywhere you want default options applied: (let [ds-opts (jdbc/with-options (ds) (default-options))] (testing "plan" @@ -259,28 +259,28 @@ VALUES ('Pear', 'green', 49, 47) (is (= 4 (count (jdbc/execute! con ["select * from fruit"])))) (is (= ac (.getAutoCommit con)))))) (testing "with-transaction exception" - (is (thrown? Throwable - (jdbc/with-transaction [t (ds)] - (jdbc/execute! t [" + (is (throws? Throwable + #(jdbc/with-transaction [t (ds)] + (jdbc/execute! t [" INSERT INTO fruit (name, appearance, cost, grade) VALUES ('Pear', 'green', 49, 47) "]) - (is (jdbc/active-tx?) "should be in a transaction") - (is (jdbc/active-tx? t) "connection should be in a transaction") - (throw (ex-info "abort" {}))))) + (is (jdbc/active-tx?) "should be in a transaction") + (is (jdbc/active-tx? t) "connection should be in a transaction") + (throw (ex-info "abort" {}))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))) (is (not (jdbc/active-tx?)) "should not be in a transaction") (with-open [con (jdbc/get-connection (ds))] (let [ac (.getAutoCommit con)] - (is (thrown? Throwable - (jdbc/with-transaction [t con] - (jdbc/execute! t [" + (is (throws? Throwable + #(jdbc/with-transaction [t con] + (jdbc/execute! t [" INSERT INTO fruit (name, appearance, cost, grade) VALUES ('Pear', 'green', 49, 47) "]) - (is (jdbc/active-tx?) "should be in a transaction") - (is (jdbc/active-tx? t) "connection should be in a transaction") - (throw (ex-info "abort" {}))))) + (is (jdbc/active-tx?) "should be in a transaction") + (is (jdbc/active-tx? t) "connection should be in a transaction") + (throw (ex-info "abort" {}))))) (is (= 4 (count (jdbc/execute! con ["select * from fruit"])))) (is (= ac (.getAutoCommit con)))))) (testing "with-transaction call rollback" @@ -363,6 +363,7 @@ VALUES ('Pear', 'green', 49, 47) (is (= ac (.getAutoCommit con)))))))) (deftest issue-146 + {:context [(around [f] (with-test-db f))]} ;; since we use an embedded PostgreSQL data source, we skip this: (when-not (or (postgres?) (xtdb?) ;; 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 + {:context [(around [f] (with-test-db f))]} ;; this is primarily a look at exception types/information for #226 (try (jdbc/execute! (ds) [" @@ -501,6 +503,7 @@ VALUES ('Pear', 'green', 49, 47) "\n\t" (ex-message t))))) (deftest bool-tests + {:context [(around [f] (with-test-db f))]} ;; Ensure the test database is used (testing (str "bool-tests for " (:dbtype (db))) (let [lit-t (cond (hsqldb?) "(1=1)" (mssql?) "1" :else "TRUE") 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)))))))) (deftest execute-batch-tests + {:context [(around [f] (with-test-db f))]} (when-not (xtdb?) (testing "simple batch insert" (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"])))))))) (deftest execute-batch-connectable-tests + {:context [(around [f] (with-test-db f))]} (when-not (xtdb?) (testing "simple batch insert" (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"])))))))) (deftest folding-test + {:context [(around [f] (with-test-db f))]} (jdbc/execute-one! (ds) ["delete from fruit"]) (if (xtdb?) (with-open [con (jdbc/get-connection (ds)) @@ -1006,6 +1012,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?) (is (= "Fruit-1000" (last result))))))) (deftest connection-tests + {:context [(around [f] (with-test-db f))]} (testing "datasource via jdbcUrl" (when-not (or (postgres?) (xtdb?)) (let [[url etc] (#'c/spec->url+etc (db)) @@ -1032,6 +1039,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?) (is (instance? java.sql.Connection con))))))) (deftest multi-rs + {:context [(around [f] (with-test-db f))]} (when (mssql?) (testing "script with multiple result sets" (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)))))))) (deftest plan-misuse + {:context [(around [f] (with-test-db f))]} (let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))] (is (re-find #"missing reduction" s))) (let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))] @@ -1097,10 +1106,11 @@ INSERT INTO fruit (name, appearance) VALUES (?,?) (is (every? #(re-find #"(?i)^(#:fruit)?\{.*:_?id.*\}$" %) (into [] (map pr-str) (jdbc/plan (ds) ["select * from fruit"] (default-options))))) - (is (thrown? IllegalArgumentException - (doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) + (is (throws? IllegalArgumentException + #(doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) (deftest issue-204 + {:context [(around [f] (with-test-db f))]} (testing "against a Connection" (is (seq (with-open [con (jdbc/get-connection (ds))] (jdbc/on-connection @@ -1121,6 +1131,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?) (jdbc/execute! x ["select * from fruit"])))))) (deftest issue-256 + {:context [(around [f] (with-test-db f))]} (testing "against a Connection" (is (seq (with-open [con (jdbc/get-connection (ds))] (jdbc/on-connection+options From 2214e06cfa4745b302ea31bbf31a21629fa010e8 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 7 Mar 2025 17:43:44 -0800 Subject: [PATCH 2/9] restore ns require layout Signed-off-by: Sean Corfield --- test/next/jdbc/sql_test.clj | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index d89f4f3..2049a53 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -2,16 +2,15 @@ (ns next.jdbc.sql-test "Tests for the syntactic sugar SQL functions." - (:require - [lazytest.core :refer [around set-ns-context! throws?]] - [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] - [next.jdbc :as jdbc] - [next.jdbc.specs :as specs] - [next.jdbc.sql :as sql] - [next.jdbc.test-fixtures + (:require [lazytest.core :refer [around set-ns-context! throws?]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] + [next.jdbc :as jdbc] + [next.jdbc.specs :as specs] + [next.jdbc.sql :as sql] + [next.jdbc.test-fixtures :refer [col-kw column default-options derby? ds index jtds? 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) From 0d7b3b60edefb3e9902689a4922f8079fdb667c2 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 8 Mar 2025 12:34:28 -0800 Subject: [PATCH 3/9] restore clojure 1.10 testing Signed-off-by: Sean Corfield --- .github/workflows/test-and-release.yml | 2 ++ .github/workflows/test-and-snapshot.yml | 2 ++ .github/workflows/test.yml | 2 ++ build.clj | 2 +- deps.edn | 5 ++++- run-tests.clj | 3 ++- 6 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 8d71bd3..610ab27 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -33,6 +33,8 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing + - name: Prep libs + run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner:1.11 env: diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index f2ee425..bfc984c 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -31,6 +31,8 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing + - name: Prep libs + run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner:1.11 env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3fc6b98..1479e35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,8 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing + - name: Prep libs + run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner:1.11 env: diff --git a/build.clj b/build.clj index b9cca79..2e4dcbe 100644 --- a/build.clj +++ b/build.clj @@ -21,7 +21,7 @@ (def class-dir "target/classes") (defn test "Run all the tests." [opts] - (doseq [alias [#_:1.10 :1.11 :1.12]] + (doseq [alias [:1.10 :1.11 :1.12]] (println "\nRunning tests for Clojure" (name alias)) (let [basis (b/create-basis {:aliases [:test alias]}) cmds (b/java-command diff --git a/deps.edn b/deps.edn index cc4b722..9a3dd12 100644 --- a/deps.edn +++ b/deps.edn @@ -18,7 +18,10 @@ ;; running tests/checks of various kinds: :test {:extra-paths ["test"] - :extra-deps {io.github.noahtheduke/lazytest {:mvn/version "1.5.0"} + :extra-deps {io.github.noahtheduke/lazytest + {:git/url "https://github.com/NoahTheDuke/lazytest/" + :git/sha "4e4a746bed3eb5642b67d63117aef60954fe424f"} + #_{:mvn/version "1.5.0"} org.clojure/test.check {:mvn/version "1.1.1"} ;; connection pooling com.zaxxer/HikariCP {:mvn/version "6.2.1"} diff --git a/run-tests.clj b/run-tests.clj index 8f8f898..595aeaa 100755 --- a/run-tests.clj +++ b/run-tests.clj @@ -23,5 +23,6 @@ (assoc "NEXT_JDBC_TEST_MARIADB" "yes") xtdb? (assoc "NEXT_JDBC_TEST_XTDB" "yes"))] - (doseq [v (if all? [#_"1.10" "1.11" "1.12"] [nil])] + (p/shell "clojure" "-X:deps" "prep" ":aliases" "[:test]") + (doseq [v (if all? ["1.10" "1.11" "1.12"] [nil])] (run-tests env v))) From 78894f8ba4abcdb6f3f56ade8e7a5aa71479bc5c Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 8 Mar 2025 12:38:23 -0800 Subject: [PATCH 4/9] and remove 1.11 override Signed-off-by: Sean Corfield --- .github/workflows/test-and-release.yml | 2 +- .github/workflows/test-and-snapshot.yml | 2 +- .github/workflows/test.yml | 4 ++-- build.clj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 610ab27..3277232 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -36,7 +36,7 @@ jobs: - name: Prep libs run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests - run: clojure -M:test:runner:1.11 + run: clojure -M:test:runner env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index bfc984c..1117dc0 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -34,7 +34,7 @@ jobs: - name: Prep libs run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests - run: clojure -M:test:runner:1.11 + run: clojure -M:test:runner env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1479e35..2cb6321 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,13 +34,13 @@ jobs: - name: Prep libs run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests - run: clojure -M:test:runner:1.11 + run: clojure -M:test:runner env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes NEXT_JDBC_TEST_MARIADB: yes - name: Run All Tests - run: clojure -M:test:runner:1.11 + run: clojure -M:test:runner env: MYSQL_ROOT_PASSWORD: testing NEXT_JDBC_TEST_MYSQL: yes diff --git a/build.clj b/build.clj index 2e4dcbe..2ee2de8 100644 --- a/build.clj +++ b/build.clj @@ -5,7 +5,7 @@ clojure -T:build deploy Run tests via: - clojure -M:test:runner:1.11 + clojure -M:test:runner For more information, run: From 403d156331f47016a32ecadb9b2f7a1044980328 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 8 Mar 2025 12:43:22 -0800 Subject: [PATCH 5/9] don't cache gitlibs avoid prep lib java version issue Signed-off-by: Sean Corfield --- .github/workflows/test-and-release.yml | 1 - .github/workflows/test-and-snapshot.yml | 2 -- .github/workflows/test.yml | 1 - 3 files changed, 4 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 3277232..06aff1f 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -25,7 +25,6 @@ jobs: with: path: | ~/.m2/repository - ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index 1117dc0..e9353b1 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -23,7 +23,6 @@ jobs: with: path: | ~/.m2/repository - ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} @@ -73,7 +72,6 @@ jobs: with: path: | ~/.m2/repository - ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2cb6321..179dd61 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,6 @@ jobs: with: path: | ~/.m2/repository - ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} From ed8ba5402acd497fdabed21d370962723b9d0f99 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 8 Mar 2025 13:41:16 -0800 Subject: [PATCH 6/9] reduce a couple of gratuitous diffs Signed-off-by: Sean Corfield --- deps.edn | 4 ++-- run-tests.clj | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deps.edn b/deps.edn index 9a3dd12..13c4a86 100644 --- a/deps.edn +++ b/deps.edn @@ -18,11 +18,11 @@ ;; running tests/checks of various kinds: :test {:extra-paths ["test"] - :extra-deps {io.github.noahtheduke/lazytest + :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} + io.github.noahtheduke/lazytest {:git/url "https://github.com/NoahTheDuke/lazytest/" :git/sha "4e4a746bed3eb5642b67d63117aef60954fe424f"} #_{:mvn/version "1.5.0"} - org.clojure/test.check {:mvn/version "1.1.1"} ;; connection pooling com.zaxxer/HikariCP {:mvn/version "6.2.1"} com.mchange/c3p0 {:mvn/version "0.10.1"} diff --git a/run-tests.clj b/run-tests.clj index 595aeaa..36037f8 100755 --- a/run-tests.clj +++ b/run-tests.clj @@ -5,9 +5,9 @@ (defn- run-tests [env v] (when v (println "\nTesting Clojure" v)) (let [{:keys [exit]} - (p/shell {:extra-env env} - "clojure" - (str "-M" (when v (str ":" v)) ":test:runner") + (p/shell {:extra-env env} "clojure" (str "-M" + (when v (str ":" v)) + ":test:runner") "--output" "dots")] (when-not (zero? exit) (System/exit exit)))) From 9d1c35b86ce339191cf7710bbc4ece0d7c4ace79 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 8 Mar 2025 14:21:05 -0800 Subject: [PATCH 7/9] fix the slf4j nudge warning Signed-off-by: Sean Corfield --- deps.edn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 13c4a86..9bba423 100644 --- a/deps.edn +++ b/deps.edn @@ -51,6 +51,7 @@ 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-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"} + org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.24.2"}} :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"]} :runner {:main-opts ["-m" "lazytest.main"]}}} From 1642cc04ca39a5c15f6a7c6335d945f84b55eabb Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 10 Mar 2025 10:13:33 -0700 Subject: [PATCH 8/9] update to lazytest 1.6.1 revert throws? back to thrown? Signed-off-by: Sean Corfield --- deps.edn | 5 +---- test/next/jdbc/sql/builder_test.clj | 13 ++++++------ test/next/jdbc/sql_test.clj | 32 ++++++++++++++--------------- test/next/jdbc_test.clj | 32 ++++++++++++++--------------- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/deps.edn b/deps.edn index 9bba423..f4e43d5 100644 --- a/deps.edn +++ b/deps.edn @@ -19,10 +19,7 @@ ;; running tests/checks of various kinds: :test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} - io.github.noahtheduke/lazytest - {:git/url "https://github.com/NoahTheDuke/lazytest/" - :git/sha "4e4a746bed3eb5642b67d63117aef60954fe424f"} - #_{:mvn/version "1.5.0"} + io.github.noahtheduke/lazytest {:mvn/version "1.6.1"} ;; connection pooling com.zaxxer/HikariCP {:mvn/version "6.2.1"} com.mchange/c3p0 {:mvn/version "0.10.1"} diff --git a/test/next/jdbc/sql/builder_test.clj b/test/next/jdbc/sql/builder_test.clj index e229772..0334601 100644 --- a/test/next/jdbc/sql/builder_test.clj +++ b/test/next/jdbc/sql/builder_test.clj @@ -2,8 +2,7 @@ (ns next.jdbc.sql.builder-test "Tests for the SQL string building functions in next.jdbc.sql.builder." - (:require [lazytest.core :refer [throws?]] - [lazytest.experimental.interfaces.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.sql.builder :as builder])) @@ -159,11 +158,11 @@ (deftest test-for-update (testing "empty example (would be a SQL error)" - (is (throws? IllegalArgumentException - #(builder/for-update :user - {:status 42} - {} - {:table-fn sql-server :column-fn mysql})))) + (is (thrown? IllegalArgumentException + (builder/for-update :user + {:status 42} + {} + {:table-fn sql-server :column-fn mysql})))) (testing "by example" (is (= (builder/for-update :user {:status 42} diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index 2049a53..0c5644e 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -2,8 +2,8 @@ (ns next.jdbc.sql-test "Tests for the syntactic sugar SQL functions." - (:require [lazytest.core :refer [around set-ns-context! throws?]] - [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] + (:require [lazytest.core :refer [around set-ns-context!]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing thrown?]] [next.jdbc :as jdbc] [next.jdbc.specs :as specs] [next.jdbc.sql :as sql] @@ -73,8 +73,8 @@ (when-not (xtdb?) ; XTDB does not support min/max on strings? (let [min-name (sql/aggregate-by-keys ds-opts :fruit "min(name)" :all)] (is (= "Apple" min-name)))) - (is (throws? IllegalArgumentException - #(sql/aggregate-by-keys ds-opts :fruit "count(*)" :all {:columns []}))))) + (is (thrown? IllegalArgumentException + (sql/aggregate-by-keys ds-opts :fruit "count(*)" :all {:columns []}))))) (deftest test-get-by-id (let [ds-opts (jdbc/with-options (ds) (default-options))] @@ -259,24 +259,24 @@ (is (= [] (sql/insert-multi! (ds) :fruit [] [])))))) (deftest no-empty-example-maps - (is (throws? clojure.lang.ExceptionInfo - #(sql/find-by-keys (ds) :fruit {}))) - (is (throws? clojure.lang.ExceptionInfo - #(sql/update! (ds) :fruit {} {}))) - (is (throws? clojure.lang.ExceptionInfo - #(sql/delete! (ds) :fruit {})))) + (is (thrown? clojure.lang.ExceptionInfo + (sql/find-by-keys (ds) :fruit {}))) + (is (thrown? clojure.lang.ExceptionInfo + (sql/update! (ds) :fruit {} {}))) + (is (thrown? clojure.lang.ExceptionInfo + (sql/delete! (ds) :fruit {})))) (deftest no-empty-columns - (is (throws? clojure.lang.ExceptionInfo - #(sql/insert-multi! (ds) :fruit [] [[] [] []])))) + (is (thrown? clojure.lang.ExceptionInfo + (sql/insert-multi! (ds) :fruit [] [[] [] []])))) (deftest no-mismatched-columns - (is (throws? IllegalArgumentException - #(sql/insert-multi! (ds) :fruit [{:name "Apple"} {:cost 1.23}])))) + (is (thrown? IllegalArgumentException + (sql/insert-multi! (ds) :fruit [{:name "Apple"} {:cost 1.23}])))) (deftest no-empty-order-by - (is (throws? clojure.lang.ExceptionInfo - #(sql/find-by-keys (ds) :fruit + (is (thrown? clojure.lang.ExceptionInfo + (sql/find-by-keys (ds) :fruit {:name "Apple"} {:order-by []})))) diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 4b75ae8..001ce8b 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -5,8 +5,8 @@ (:require [clojure.core.reducers :as r] [clojure.string :as str] - [lazytest.core :refer [around throws?]] - [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing]] + [lazytest.core :refer [around]] + [lazytest.experimental.interfaces.clojure-test :refer [deftest is testing thrown?]] [next.jdbc :as jdbc] [next.jdbc.connection :as c] [next.jdbc.prepare :as prep] @@ -259,28 +259,28 @@ VALUES ('Pear', 'green', 49, 47) (is (= 4 (count (jdbc/execute! con ["select * from fruit"])))) (is (= ac (.getAutoCommit con)))))) (testing "with-transaction exception" - (is (throws? Throwable - #(jdbc/with-transaction [t (ds)] - (jdbc/execute! t [" + (is (thrown? Throwable + (jdbc/with-transaction [t (ds)] + (jdbc/execute! t [" INSERT INTO fruit (name, appearance, cost, grade) VALUES ('Pear', 'green', 49, 47) "]) - (is (jdbc/active-tx?) "should be in a transaction") - (is (jdbc/active-tx? t) "connection should be in a transaction") - (throw (ex-info "abort" {}))))) + (is (jdbc/active-tx?) "should be in a transaction") + (is (jdbc/active-tx? t) "connection should be in a transaction") + (throw (ex-info "abort" {}))))) (is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))) (is (not (jdbc/active-tx?)) "should not be in a transaction") (with-open [con (jdbc/get-connection (ds))] (let [ac (.getAutoCommit con)] - (is (throws? Throwable - #(jdbc/with-transaction [t con] - (jdbc/execute! t [" + (is (thrown? Throwable + (jdbc/with-transaction [t con] + (jdbc/execute! t [" INSERT INTO fruit (name, appearance, cost, grade) VALUES ('Pear', 'green', 49, 47) "]) - (is (jdbc/active-tx?) "should be in a transaction") - (is (jdbc/active-tx? t) "connection should be in a transaction") - (throw (ex-info "abort" {}))))) + (is (jdbc/active-tx?) "should be in a transaction") + (is (jdbc/active-tx? t) "connection should be in a transaction") + (throw (ex-info "abort" {}))))) (is (= 4 (count (jdbc/execute! con ["select * from fruit"])))) (is (= ac (.getAutoCommit con)))))) (testing "with-transaction call rollback" @@ -1106,8 +1106,8 @@ INSERT INTO fruit (name, appearance) VALUES (?,?) (is (every? #(re-find #"(?i)^(#:fruit)?\{.*:_?id.*\}$" %) (into [] (map pr-str) (jdbc/plan (ds) ["select * from fruit"] (default-options))))) - (is (throws? IllegalArgumentException - #(doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) + (is (thrown? IllegalArgumentException + (doall (take 3 (jdbc/plan (ds) ["select * from fruit"])))))) (deftest issue-204 {:context [(around [f] (with-test-db f))]} From 9fdc24eab75df1d7d2bb3185d370a3d584399a49 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 10 Mar 2025 10:15:42 -0700 Subject: [PATCH 9/9] remove prep lib; restore gitlibs cache Signed-off-by: Sean Corfield --- .github/workflows/test-and-release.yml | 3 +-- .github/workflows/test-and-snapshot.yml | 3 +-- .github/workflows/test.yml | 3 +-- run-tests.clj | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index 06aff1f..42ec8f1 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -25,6 +25,7 @@ jobs: with: path: | ~/.m2/repository + ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} @@ -32,8 +33,6 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing - - name: Prep libs - run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner env: diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index e9353b1..1fb8be7 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -23,6 +23,7 @@ jobs: with: path: | ~/.m2/repository + ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} @@ -30,8 +31,6 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing - - name: Prep libs - run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 179dd61..712c646 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,6 +23,7 @@ jobs: with: path: | ~/.m2/repository + ~/.gitlibs ~/.clojure ~/.cpcache key: ${{ runner.os }}-${{ hashFiles('**/deps.edn') }} @@ -30,8 +31,6 @@ jobs: run: docker compose up -d env: MYSQL_ROOT_PASSWORD: testing - - name: Prep libs - run: clojure -X:deps prep :aliases '[:test]' - name: Run MariaDB Tests run: clojure -M:test:runner env: diff --git a/run-tests.clj b/run-tests.clj index 36037f8..4d37d2c 100755 --- a/run-tests.clj +++ b/run-tests.clj @@ -23,6 +23,5 @@ (assoc "NEXT_JDBC_TEST_MARIADB" "yes") xtdb? (assoc "NEXT_JDBC_TEST_XTDB" "yes"))] - (p/shell "clojure" "-X:deps" "prep" ":aliases" "[:test]") (doseq [v (if all? ["1.10" "1.11" "1.12"] [nil])] (run-tests env v)))