diff --git a/CHANGELOG.md b/CHANGELOG.md index f32a0c6..41228e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Only accretive/fixative changes will be made from now on. +* 2.0.157 -- 2022-01-25 + * Fix a small regression in how classes are treated when used as predicates in `expect`. + * 2.0.156 -- 2022-01-19 * Address [#26](https://github.com/clojure-expectations/clojure-test/issues/26) by adding an example combining `more->` and `more-of` around destructuring `ex-info` data. * Fix [#24](https://github.com/clojure-expectations/clojure-test/issues/24) by using a local (gensym) for the actual value in `more` and `more->` so it is only evaluated once. diff --git a/README.md b/README.md index 953ebed..f92cff2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A `clojure.test`-compatible version of the [classic Expectations testing library ## Where? -[![Clojars Project](https://clojars.org/com.github.seancorfield/expectations/latest-version.svg)](https://clojars.org/com.github.seancorfield/expectations) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/expectations?2.0.156)](https://cljdoc.org/d/com.github.seancorfield/expectations/CURRENT) +[![Clojars Project](https://clojars.org/com.github.seancorfield/expectations/latest-version.svg)](https://clojars.org/com.github.seancorfield/expectations) [![cljdoc badge](https://cljdoc.org/badge/com.github.seancorfield/expectations?2.0.157)](https://cljdoc.org/d/com.github.seancorfield/expectations/CURRENT) Try it out: diff --git a/doc/getting-started-cljs.md b/doc/getting-started-cljs.md index 5114534..860ceb1 100644 --- a/doc/getting-started-cljs.md +++ b/doc/getting-started-cljs.md @@ -20,7 +20,7 @@ Your `deps.edn` should include this information: ```clojure {:aliases {:cljs-runner - {:extra-deps {com.github.seancorfield/expectations {:mvn/version "2.0.156"}, + {:extra-deps {com.github.seancorfield/expectations {:mvn/version "2.0.157"}, olical/cljs-test-runner {:mvn/version "3.7.0"}, pjstadig/humane-test-output {:mvn/version "0.10.0"}}, :extra-paths ["src" "test" "cljs-test-runner-out/gen"], diff --git a/doc/getting-started.md b/doc/getting-started.md index a666bf7..dac7262 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -8,15 +8,15 @@ You can add `expectations.clojure.test` to your project with either: ```clojure ;; add this to :extra-deps under a :test alias: -com.github.seancorfield/expectations {:mvn/version "2.0.156"} +com.github.seancorfield/expectations {:mvn/version "2.0.157"} ``` for `deps.edn` or: ```clojure ;; add this to :dev-dependencies (Leiningen) -[com.github.seancorfield/expectations "2.0.156"] +[com.github.seancorfield/expectations "2.0.157"] ;; or add this to :dependencies (Boot) -[com.github.seancorfield/expectations "2.0.156" :scope "test"] +[com.github.seancorfield/expectations "2.0.157" :scope "test"] ``` for `project.clj` or `build.boot`. @@ -186,7 +186,7 @@ Of course, you can also update the `:test` alias to add those new options into ` {:test {:extra-paths ["test"] :extra-deps - {com.github.seancorfield/expectations {:mvn/version "2.0.156"} + {com.github.seancorfield/expectations {:mvn/version "2.0.157"} ;; assumes Clojure CLI 1.10.3.933 or later: io.github.cognitect-labs/test-runner {:git/tag "v0.5.0" :git/sha "48c3c67"}} diff --git a/src/expectations/clojure/test.cljc b/src/expectations/clojure/test.cljc index ee4a29a..55777ea 100644 --- a/src/expectations/clojure/test.cljc +++ b/src/expectations/clojure/test.cljc @@ -178,6 +178,12 @@ #?(:clj java.util.regex.Pattern :cljs (type #"regex"))) (some? (re-find e# a#)) + #?(:clj (and (class? e#) (class? a#)) + :cljs false) ; maybe figure this out later + (isa? a# e#) ; (expect parent child) + #?(:clj (class? e#) + :cljs false) ; maybe figure this out later + (instance? e# a#) ; (expect klazz object) :else (= e# a#)) humane?# (and humane-test-output? (not (fn? e#)) (not ~conform?))] diff --git a/test/expectations/clojure/test_macros.cljc b/test/expectations/clojure/test_macros.cljc index 9e611f3..e9aca99 100644 --- a/test/expectations/clojure/test_macros.cljc +++ b/test/expectations/clojure/test_macros.cljc @@ -47,5 +47,5 @@ (with-redefs [do-report (sut/all-report results#)] ~expectation) (t/is (some (fn [pass#] - (~success (:actual pass#))) - (:pass @results#))))) + (~success (:actual pass#))) + (:pass @results#))))) diff --git a/test/expectations/clojure/test_test.cljc b/test/expectations/clojure/test_test.cljc index 484cec0..1bb6a7e 100644 --- a/test/expectations/clojure/test_test.cljc +++ b/test/expectations/clojure/test_test.cljc @@ -13,9 +13,9 @@ #?(:clj [clojure.test :refer [deftest is do-report testing]] :cljs [cljs.test :include-macros true - :refer [do-report assert-expr] + :refer [do-report assert-expr] :refer-macros [deftest is testing assert-expr - use-fixtures]]) + use-fixtures]]) #?(:cljs [cljs.spec.alpha :as s]) #?(:cljs [expectations.clojure.test-spec]) #?(:clj [expectations.clojure.test :refer @@ -59,13 +59,25 @@ ;; TODO: fails because regexes never compare equal to themselves! #_(is-not' (sut/expect #"fool" "It's foobar!") (not (re-find #"fool" "It's foobar!")))) +#?(:clj (def get-ex-message (or (resolve 'clojure.core/ex-message) + (fn [^Throwable t] (.getMessage t)))) + :cljs (def get-ex-message ex-message)) + #?(:clj (deftest exception-test (passes (sut/expect ArithmeticException (/ 12 0)) (fn [ex] (let [t (Throwable->map ex)] (and (= "Divide by zero" (-> t :cause)) (or (= 'java.lang.ArithmeticException (-> t :via first :type)) - (= java.lang.ArithmeticException (-> t :via first :type)))))))) + (= java.lang.ArithmeticException (-> t :via first :type))))))) + (passes (sut/expect Exception (/ 12 0)) + (fn [ex] + (let [t (Throwable->map ex)] + (and (= "Divide by zero" (-> t :cause)) + (or (= 'java.lang.ArithmeticException (-> t :via first :type)) + (= java.lang.ArithmeticException (-> t :via first :type))))))) + (is (sut/expect (more-> ArithmeticException type #"Divide by zero" get-ex-message) (/ 12 0))) + (is (sut/expect (more-> Exception type #"Divide by zero" get-ex-message) (/ 12 0)))) :cljs (deftest cljs-exception-test (passes (sut/expect js/Error (throw (ex-info "foo" {})))