From f520840870472f930909d1a50cf7e0069c3fcd65 Mon Sep 17 00:00:00 2001 From: Noah Bogart Date: Mon, 25 Nov 2024 11:19:42 -0500 Subject: [PATCH] Fix 2-arg defexpect, add clj-kondo config --- .../io.github.noahtheduke/lazytest/config.edn | 1 + .../io.github.noahtheduke/lazytest/config.edn | 1 + .../lazytest/extensions/expectations.cljc | 2 +- .../extensions/expectations_test.cljc | 23 +++++++++++++------ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn index aede8c8..407d9c8 100644 --- a/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn +++ b/.clj-kondo/imports/io.github.noahtheduke/lazytest/config.edn @@ -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/= } diff --git a/resources/clj-kondo.exports/io.github.noahtheduke/lazytest/config.edn b/resources/clj-kondo.exports/io.github.noahtheduke/lazytest/config.edn index aede8c8..407d9c8 100644 --- a/resources/clj-kondo.exports/io.github.noahtheduke/lazytest/config.edn +++ b/resources/clj-kondo.exports/io.github.noahtheduke/lazytest/config.edn @@ -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/= } diff --git a/src/clojure/lazytest/extensions/expectations.cljc b/src/clojure/lazytest/extensions/expectations.cljc index da562a8..768c92a 100644 --- a/src/clojure/lazytest/extensions/expectations.cljc +++ b/src/clojure/lazytest/extensions/expectations.cljc @@ -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))) diff --git a/test/clojure/lazytest/extensions/expectations_test.cljc b/test/clojure/lazytest/extensions/expectations_test.cljc index 9cec188..39e9c87 100644 --- a/test/clojure/lazytest/extensions/expectations_test.cljc +++ b/test/clojure/lazytest/extensions/expectations_test.cljc @@ -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))) @@ -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})) @@ -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]