Skip to content

Commit

Permalink
Fix 2-arg defexpect, add clj-kondo config
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Nov 25, 2024
1 parent fcfa6ee commit 586579d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
;; 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/=
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
;; 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/=
}
Expand Down
2 changes: 1 addition & 1 deletion src/clojure/lazytest/extensions/expectations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
(if (and (= (count body) 2)
(not (some contains-expect? body)))
;; treat (defexpect my-name pred (expr)) as a special case
`(lt/defdescribe ~n (expect ~@body))
`(lt/defdescribe ~n (lt/it "" (expect ~@body)))
;; #13 match deftest behavior starting in 2.0.0
`(lt/defdescribe ~n ~@body))
(meta &form)))
Expand Down
23 changes: 16 additions & 7 deletions test/clojure/lazytest/extensions/expectations_test.cljc
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
(ns lazytest.extensions.expectations-test
(:require
[lazytest.core :refer [defdescribe it throws? expect throws-with-msg?]]
[lazytest.extensions.expectations :as sut :refer [in more-> more-of more from-each]]
[clojure.spec.alpha :as s]
[clojure.string :as str])
[clojure.string :as str]
[lazytest.core :refer [expect it throws-with-msg? throws?]]
[lazytest.extensions.expectations :as sut :refer [from-each in more more->
more-of]])
(:import
(clojure.lang ExceptionInfo)
(lazytest ExpectationFailed)))

(s/def ::pos pos?)

(defdescribe expectations-test
(sut/defexpect simple-test 1 1)

(sut/defexpect simple-call-test (+ 1 2) (+ 1 1 1))

(sut/defexpect either-expect-works
(it "handles lazytest" (expect (= 1 1)))
(it "handles expectations" (sut/expect (= 2 2))))

(sut/defexpect expectations-test
(it "value" (sut/expect true))
(it "=" (sut/expect 1 1))
(it "fn?" (let [i 1] (sut/expect pos? i)))
Expand All @@ -19,13 +28,13 @@
(it "catch" (sut/expect ExceptionInfo (throw (ex-info "aw shucks" {}))))
(it "spec" (sut/expect ::pos 1)))

(defdescribe expectations
(sut/defexpect expectations
(it "prints correctly"
(expect (throws-with-msg? ExpectationFailed
#"did not satisfy"
#(sut/expect even? (+ 1 1 1) "It's uneven!")))))

(defdescribe expectations-examples-test
(sut/defexpect expectations-examples-test
(it "handles the fancy stuff too"
(sut/expect (more-> ArithmeticException type #"Divide by zero" ex-message) (/ 12 0))
(sut/expect {:foo 1} (in {:foo 1 :cat 4}))
Expand Down Expand Up @@ -54,7 +63,7 @@
(swap! counter inc))
(expect (= 2 @counter)))))

(defdescribe more-of-test
(sut/defexpect more-of-test
(it "lazytest issue 13: can handle big more-ofs"
(sut/expect
(more-of [_ url site kw nationality {:keys [country state city]} locale]
Expand Down

0 comments on commit 586579d

Please sign in to comment.