Skip to content

Commit 5fc75ab

Browse files
marke000claude
andcommitted
Style fixes: map key ordering, alphabetical requires, clj-kondo ignores
- Order map keys alphabetically throughout - Sort requires alphabetically - Add clj-kondo ignore for unused namespace and unused private var - Prefix unused parameter with underscore - Fix test map literals with misplaced commas Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b59af7b commit 5fc75ab

4 files changed

Lines changed: 78 additions & 69 deletions

File tree

src/provisdom/test/assertions/cljs.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns provisdom.test.assertions.cljs
22
(:require
3+
#_{:clj-kondo/ignore [:unused-namespace]}
34
[cljs.test :as t]
45
#?(:clj [cljs.analyzer.api :as ana])))
56

src/provisdom/test/core.cljc

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
(ns provisdom.test.core
22
#?(:cljs (:require-macros
3-
[provisdom.test.core]
4-
[provisdom.test.assertions.cljs]))
3+
[provisdom.test.assertions.cljs]
4+
[provisdom.test.core]))
55
(:require
66
[clojure.pprint :as pprint]
77
[clojure.set :as set]
8-
#?(:clj [clojure.test :as t]
9-
:cljs [cljs.test :as t])
10-
[clojure.string :as str]
118
[clojure.spec.alpha :as s]
12-
[clojure.spec.test.alpha :as st]
139
[clojure.spec.gen.alpha :as gen]
14-
#?(:clj [provisdom.test.spec-check :as p.st])
15-
#?(:cljs [orchestra-cljs.spec.test])
16-
17-
;; We require clojure.test for some CLJS code, in order for spec-check to run.
10+
#_{:clj-kondo/ignore [:unused-namespace]}
11+
[clojure.spec.test.alpha :as st]
12+
[clojure.string :as str]
13+
#?(:clj [clojure.test :as t]
14+
:cljs [cljs.test :as t])
1815
#?(:cljs [clojure.test.check])
19-
#?(:cljs [clojure.test.check.properties]))
16+
[clojure.test.check.properties :as prop]
17+
#?(:cljs [orchestra-cljs.spec.test])
18+
#?(:clj [provisdom.test.spec-check :as p.st]))
2019
#?(:clj (:import (clojure.lang ExceptionInfo)
2120
(java.io FileNotFoundException Closeable))))
2221

@@ -64,9 +63,9 @@
6463
CLJS Note: Always returns `true` on ClojureScript because the internal instrumented-vars atom is
6564
private and inaccessible. This means [[with-instrument]] won't unstrument functions on CLJS -
6665
they remain instrumented. This is usually acceptable for test code."
67-
[sym]
66+
[_sym]
6867
#?(:clj (let [instrumented-vars @(var-get #'st/instrumented-vars)]
69-
(contains? instrumented-vars (resolve sym)))
68+
(contains? instrumented-vars (resolve _sym)))
7069
:cljs true))
7170

7271
(defn collectionize
@@ -96,9 +95,9 @@
9695
(defmacro with-instrument*
9796
[instrument-args & body]
9897
`(with-instrument-impl
99-
{:sym-or-syms ~(first instrument-args)
100-
:f (fn [] ~@body)
101-
:opts ~(second instrument-args)}))
98+
{:f (fn [] ~@body)
99+
:opts ~(second instrument-args)
100+
:sym-or-syms ~(first instrument-args)}))
102101

103102
(defmacro with-instrument
104103
"Enables instrumentation for `sym-or-syms` while executing `body`. Once `body` has completed,
@@ -154,13 +153,13 @@
154153
(when-not valid?
155154
(swap! invalid-store assoc og-spec x))
156155
valid?))
157-
{:spec spec
156+
{:form form
158157
:overrides overrides
159158
:path path
160-
:form form}) g 100)
159+
:spec spec}) g 100)
161160
(let [abbr (s/abbrev form)]
162161
(throw (ex-info (str "Unable to construct gen at: " path " for: " abbr)
163-
{::path path ::form form ::failure :no-gen})))))))
162+
{::failure :no-gen, ::form form, ::path path})))))))
164163

165164
(defmacro deftest
166165
"Re-export `clojure.test/deftest` for convenience when using `[provisdom.test.core :as t]`."
@@ -222,24 +221,24 @@
222221
(let [do-report-sym (if (cljs-env? &env) 'cljs.test/do-report 'clojure.test/do-report)]
223222
`(try
224223
~@body
225-
(~do-report-sym {:type :fail
226-
:message "Expected exception to be thrown"
224+
(~do-report-sym {:actual nil
227225
:expected '~expected-data
228-
:actual nil})
226+
:message "Expected exception to be thrown"
227+
:type :fail})
229228
(catch ~(if (cljs-env? &env) :default 'ExceptionInfo) e#
230229
(let [actual-data# (ex-data e#)
231230
matches?# (every? (fn [[k# v#]]
232231
(= v# (get actual-data# k#)))
233232
~expected-data)]
234233
(if matches?#
235-
(~do-report-sym {:type :pass
234+
(~do-report-sym {:actual actual-data#
235+
:expected '~expected-data
236236
:message nil
237+
:type :pass})
238+
(~do-report-sym {:actual actual-data#
237239
:expected '~expected-data
238-
:actual actual-data#})
239-
(~do-report-sym {:type :fail
240240
:message "Exception data did not match expected"
241-
:expected '~expected-data
242-
:actual actual-data#}))
241+
:type :fail}))
243242
matches?#)))))
244243

245244
(defn midje-just
@@ -353,7 +352,10 @@
353352
(= a ::missing) false
354353
(number? e) (apply approx= e a (mapcat identity approx=-opts))
355354
:else (= e a))]
356-
{:path path :expected e :actual a :equal? equal?})))
355+
{:actual a
356+
:equal? equal?
357+
:expected e
358+
:path path})))
357359
(remove :equal?)))))
358360

359361
(defmacro is-data-approx=
@@ -374,18 +376,21 @@
374376
actual# ~x2
375377
result# (~data-approx=-sym expected# actual# ~@opts)]
376378
(if result#
377-
(~do-report-sym {:type :pass :message nil :expected expected# :actual actual#})
379+
(~do-report-sym {:actual actual#
380+
:expected expected#
381+
:message nil
382+
:type :pass})
378383
(let [diffs# (data-diff expected# actual# ~@opts)
379384
diff-str# (with-out-str
380385
(doseq [{:keys [~'path ~'expected ~'actual]} diffs#]
381386
(println " Path:" ~'path)
382387
(println " expected:" ~'expected)
383388
(println " actual: " ~'actual)))]
384-
(~do-report-sym {:type :fail
389+
(~do-report-sym {:actual actual#
390+
:expected expected#
385391
:message (str "Data structures differ at " (count diffs#)
386392
" path(s):\n" diff-str#)
387-
:expected expected#
388-
:actual actual#})))
393+
:type :fail})))
389394
result#))))
390395

391396
#?(:clj (defmethod t/assert-expr 'just
@@ -394,14 +399,14 @@
394399
actual# ~(nth form 2)
395400
result# (midje-just expected# actual#)]
396401
(if result#
397-
(t/do-report {:type :pass
398-
:message ~msg
402+
(t/do-report {:actual actual#
399403
:expected '~form
400-
:actual actual#})
401-
(t/do-report {:type :fail
402404
:message ~msg
405+
:type :pass})
406+
(t/do-report {:actual actual#
403407
:expected '~(nth form 1)
404-
:actual actual#}))
408+
:message ~msg
409+
:type :fail}))
405410
result#)))
406411

407412
(def ^:dynamic *default-spec-check-opts* {})
@@ -414,6 +419,7 @@
414419
(def quick-check-stc-keys
415420
[:num-tests :seed :max-size :reporter-fn])
416421

422+
#_{:clj-kondo/ignore [:unused-private-var]}
417423
(defn- normalize-spec-test-opts
418424
[opts]
419425
(let [base-opts (merge *default-spec-check-opts* opts)]
@@ -477,10 +483,11 @@
477483
shrunk-args (first (:smallest shrunk))
478484
failing-args (or shrunk-args original-args)
479485
spec-error (-> (:result-data test-check-ret)
480-
:clojure.test.check.properties/error)
486+
::prop/error)
481487
timeout? (and (instance? ExceptionInfo (:result test-check-ret))
482488
(contains? (ex-data (:result test-check-ret))
483-
:provisdom.test.spec-check/timeout))
489+
#?(:clj ::p.st/timeout
490+
:cljs :provisdom.test.spec-check/timeout)))
484491
spec-error? (fn [ex]
485492
(and (instance? ExceptionInfo ex)
486493
(::s/failure (ex-data ex))))
@@ -493,25 +500,25 @@
493500
spec-error-map (fn [ex]
494501
(let [spec-error-message (ex-message ex)
495502
explain-data (ex-data ex)]
496-
{:type :fail
503+
{:actual "n/a"
497504
:expected "n/a"
498-
:actual "n/a"
499505
:message (str spec-error-message " (seed: " seed ")\n"
500506
pass-info
501507
shrink-info
502508
"\n"
503509
(with-out-str (s/explain-out explain-data)) "\n"
504510
"Args:\n\n"
505511
(with-out-str (pprint/pprint failing-args))
506-
"---------------")}))]
512+
"---------------")
513+
:type :fail}))]
507514
(swap! failed-args-store assoc fn-sym failing-args)
508515
(cond
509516
;; Timeout
510517
timeout?
511-
{:type :fail
518+
{:actual (:result test-check-ret)
512519
:expected ""
513-
:actual (:result test-check-ret)
514-
:message (str "Spec check timed out.\n" pass-info)}
520+
:message (str "Spec check timed out.\n" pass-info)
521+
:type :fail}
515522

516523
(spec-error? spec-error)
517524
(spec-error-map spec-error)
@@ -522,22 +529,22 @@
522529

523530
;; Generator threw an exception
524531
(instance? #?(:clj Throwable :cljs js/Error) (:failure first-failure))
525-
{:type :fail
532+
{:actual (:failure first-failure)
526533
:expected ""
527-
:actual (:failure first-failure)
528-
:message (str "A generator threw an exception.\n" pass-info)}
534+
:message (str "A generator threw an exception.\n" pass-info)
535+
:type :fail}
529536

530-
:else {:type :fail
537+
:else {:actual spec-error
531538
:expected ""
532-
:actual spec-error
533-
:message (str fn-sym " threw an exception.\n" pass-info)}))
539+
:message (str fn-sym " threw an exception.\n" pass-info)
540+
:type :fail}))
534541
;; all checks passed
535542
(do
536543
(swap! failed-args-store (fn [failed]
537544
(apply dissoc failed (map :sym check-results))))
538-
{:type :pass
539-
:message (str "Generative tests pass for "
540-
(str/join ", " (map :sym check-results)))}))))
545+
{:message (str "Generative tests pass for "
546+
(str/join ", " (map :sym check-results)))
547+
:type :pass}))))
541548

542549
#?(:clj
543550
(defn- fully-qualified-namespace

src/provisdom/test/spec_check.clj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"Wrapper on `clojure.spec.test.alpha` with changes to support the `:throws` keyword in `fdef`
33
specs and many other things.
44
5-
Some original code copied from Spec.
6-
https://github.com/clojure/spec.alpha/blob/eaae63904808a0988f6723d1e9e1ee7db6f07ee5/src/main/clojure/clojure/spec/test/alpha.clj"
5+
Some original code copied from Spec:
6+
https://github.com/clojure/spec.alpha/blob/eaae63904808a0988f6723d1e9e1ee7db6f07ee5/
7+
src/main/clojure/clojure/spec/test/alpha.clj"
78
(:require
89
[clojure.spec.alpha :as s]
910
[clojure.spec.gen.alpha :as gen]
@@ -89,8 +90,8 @@
8990
(defn- make-check-result
9091
"Builds spec result map."
9192
[check-sym spec test-check-ret]
92-
(merge {:spec spec
93-
::stc/ret test-check-ret}
93+
(merge {::stc/ret test-check-ret
94+
:spec spec}
9495
(when check-sym
9596
{:sym check-sym})
9697
(when-let [result (-> test-check-ret :result)]
@@ -108,15 +109,15 @@
108109
(cond
109110
(or (nil? f) (some-> v meta :macro))
110111
{:failure (ex-info "No fn to spec" {::s/failure :no-fn})
111-
:sym s :spec spec}
112+
:spec spec :sym s}
112113

113114
(:args specd)
114115
(let [tc-ret (quick-check f specd throws (assoc opts :timeout timeout))]
115116
(make-check-result s spec tc-ret))
116117

117118
:else
118119
{:failure (ex-info "No :args spec" {::s/failure :no-args-spec})
119-
:sym s :spec spec})
120+
:spec spec :sym s})
120121
(finally
121122
(when re-inst? (st/instrument s))))))
122123

@@ -135,12 +136,12 @@
135136
[s]
136137
(let [v (resolve s)]
137138
{:s s
138-
:v v
139139
:spec (when v (s/get-spec v))
140140
:throws (-> s
141-
get-spec-meta
142-
:throws
143-
normalize-fdef-throws)}))
141+
get-spec-meta
142+
:throws
143+
normalize-fdef-throws)
144+
:v v}))
144145

145146
(defn- validate-check-opts
146147
[opts]

test/provisdom/test/core_test.cljc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
(t/is (= `(clojure.test/is (~'= 1 1) nil) (macroexpand-1 `(t/is= 1 1 nil))))
2121
;; is-not expands correctly
2222
(t/is (= `(clojure.test/is (~'not false) "some message")
23-
(macroexpand-1 `(t/is-not false "some message"))))))
23+
(macroexpand-1 `(t/is-not false "some message"))))))
2424

2525
(t/deftest t-midje-just
2626
;; matching cases
2727
(t/is (t/midje-just [1 1 1] [1 1 1]))
2828
(t/is (t/midje-just [1 1 #(and (number? %) (not (== % %)))]
29-
[1 1 #?(:clj Double/NaN :cljs js/NaN)]))
29+
[1 1 #?(:clj Double/NaN :cljs js/NaN)]))
3030
;; non-matching case
3131
(t/is-not (t/midje-just [1 1 1] [1 1 2])))
3232

@@ -187,10 +187,10 @@
187187
(t/deftest is-thrown-with-data-test
188188
;; matches when all expected keys present with correct values
189189
(t/is (t/is-thrown-with-data {:type :test-error}
190-
(throw (ex-info "test" {:type :test-error :extra :data}))))
190+
(throw (ex-info "test" {:extra :data, :type :test-error}))))
191191
;; matches with multiple keys
192-
(t/is (t/is-thrown-with-data {:type :test-error :code 42}
193-
(throw (ex-info "test" {:type :test-error :code 42 :extra :data}))))
192+
(t/is (t/is-thrown-with-data {:code 42 :type :test-error}
193+
(throw (ex-info "test" {:code 42 :extra :data :type :test-error}))))
194194
;; empty expected-data matches any ex-info
195195
(t/is (t/is-thrown-with-data {}
196196
(throw (ex-info "test" {:anything :here}))))))

0 commit comments

Comments
 (0)