Skip to content

Commit

Permalink
print seed on generation error
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Feb 23, 2024
1 parent 97e97b5 commit d9fccfb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
9 changes: 7 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.3" :scope "provided"]
[org.clojure/clojurescript "1.10.879" :scope "provided"]
[org.clojure/test.check "1.1.0"]
;;https://github.com/frenchy64/test.check/pull/1
[org.clojure/test.check "cf08a57a2a6bfa3eb685ad31c4b61f53dde9d98c"]
[clj-time "0.15.2"]
[com.andrewmcveigh/cljs-time "0.5.2"]
[instaparse "1.4.10"]]
:deploy-repositories [["releases" :clojars]]
:profiles {:ci {:jvm-opts ["-Xmx1g" "-server"]}}
:plugins [[lein-cljsbuild "1.1.8"]
[lein-doo "0.1.11"]
[com.gfredericks/lein-all-my-files-should-end-with-exactly-one-newline-character "0.1.0"]]
[com.gfredericks/lein-all-my-files-should-end-with-exactly-one-newline-character "0.1.0"]
[reifyhealth/lein-git-down "0.3.5"]]
:middleware [lein-git-down.plugin/inject-properties]
:repositories [["public-github" {:url "git://github.com"}]]
:git-down {org.clojure/test.check {:coordinates frenchy64/test.check}}

:cljsbuild
{:builds
Expand Down
34 changes: 33 additions & 1 deletion test/com/gfredericks/test/chuck/clojure_test_output_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@
(get-in tc-report path))))
(is (= [{'i 0}] (get-in tc-report [:shrunk :smallest]))))))

;; https://github.com/gfredericks/test.chuck/issues/78
(deftest an-error-during-gen-test
(checking "preamble" {:seed 123456}
[i gen/small-integer
:let [x (/ 1 i)]]
(is (pos? x))))

(deftest checking-prints-seed-on-gen-error-test
(let [[test-results all-out] (capture-report-counters-and-out #'an-error-during-gen-test)
;; skip test preamble
[_ out] (str/split all-out
#".*preamble\n"
2)
_ (assert out (pr-str all-out))
;; report is printed after `testing`
tc-report (edn/read-string
{:readers (assoc default-data-readers
'error #(-> %
(assoc ::error-tag true)))}
out)
error-map-msg-key #?(:clj :cause :cljs :message)]
(testing "clojure.test reporting"
(is (= test-results {:test 1, :pass 0, :fail 1, :error 0})))
(testing "thrown exception"
(is (false? (:pass? tc-report))
(pr-str tc-report))
(is (get-in tc-report [:result ::error-tag]))
(is (get-in tc-report [:result-data :clojure.test.check.properties/error ::error-tag]))
(is (= 123456 (:seed tc-report)))
(is (not (contains? tc-report :shrunk))))))

(defn test-ns-hook []
(test-vars [#'failure-output-test
#'error-output-test]))
#'error-output-test
#'checking-prints-seed-on-gen-error-test]))

0 comments on commit d9fccfb

Please sign in to comment.