Back
do-report (clj)
(source)function
(do-report m)
Add file and line information to a test result and call report.
If you are writing a custom assert-expr method, call this function
to pass test results to report.
Examples
babashka/babashka
(require '[clojure.test :refer [is deftest] :as t])
(defmethod t/assert-expr 'roughly [msg form]
`(let [op1# ~(nth form 1)
op2# ~(nth form 2)
tolerance# (if (= 4 ~(count form)) ~(last form) 2)
decimals# (/ 1. (Math/pow 10 tolerance#))
result# (< (Math/abs (- op1# op2#)) decimals#)]
(t/do-report
{:type (if result# :pass :fail)
:message ~msg
:expected (format "%s should be roughly %s with %s tolerance"
op1# op2# decimals#)
:actual result#})
result#))
babashka/babashka
(ns datalog.parser.test.util
(:require [#?(:clj clojure.test :cljs cljs.test) :as test]))
#?(:clj
(defmethod test/assert-expr 'thrown-msg? [msg form]
(let [[_ match & body] form]
`(try ~@body
(test/do-report {:type :fail, :message ~msg, :expected '~form, :actual nil})
(catch Throwable e#
(let [m# (.getMessage e#)]
(test/do-report
{:type (if (= ~match m#) :pass :fail)
:message ~msg
:expected '~form
:actual e#}))
e#)))))
thheller/shadow-cljs
(ns shadow.build.npm-test
(:require
[clojure.test :as ct :refer (deftest is)]
[clojure.pprint :refer (pprint)]
[clojure.java.io :as io]
[shadow.build.npm :as npm]
[shadow.build.resolve :refer (find-npm-resource)]
[shadow.cljs.devtools.server.npm-deps :as npm-deps]
[shadow.cljs.util :as util]
[shadow.debug :as dbg]
[clojure.edn :as edn])
(:import [clojure.lang ExceptionInfo]))
(cond
fail-expected
(if (nil? target-rc)
(ct/do-report {:type :pass, :message (pr-str [:OK test])})
(throw
(ex-info "unexpected result, wasn't supposed to find anything but did"
{:test test
:target target-rc})))
(false? expected)
(if (identical? target-rc npm/empty-rc)
(ct/do-report {:type :pass, :message (pr-str [:OK test])})
(throw
(ex-info "unexpected result, disabled/false require expected but got result"
{:test test
:target target-rc})))
(if (= file expected-file)
(ct/do-report {:type :pass, :message (pr-str [:OK test])})
(throw
(ex-info "unexpected result"
{:test test
:file file
:expected-file expected-file}))))
:else
(throw
(ex-info "test with no expected?"
{:test test
:file (:file target-rc)})))
)))))
clojure/core.typed
(ns clojure.core.typed.test.testnew
(:require [clojure.core.typed :as t]
[clojure.test :refer :all]
[clojure.core.typed.test.test-utils :refer :all]
[clojure.core.typed.test.destructure]))
(deftest function?-test
(is-tc-e (function? function?) Boolean
:requires [[clojure.test :refer [function?]]])
(is-tc-err (function? function?) String
:requires [[clojure.test :refer [function?]]]))
(deftest assert-any-test
(is-tc-e (assert-any "Hi" (= 4 (+ 2 2))) Any
:requires [[clojure.test :refer [assert-any]]]))
(deftest do-report-test
(is-tc-e #(do-report 1)
:requires [[clojure.test :refer [do-report]]]))
(deftest run-tests-test
(is-tc-e #(run-tests) [-> (Map Any Any)]
:requires [[clojure.test :refer [run-tests]]])
(is-tc-err #(run-tests) [-> String]
:requires [[clojure.test :refer [run-tests]]]))
(deftest run-all-tests-test
(is-tc-e #(run-all-tests) [-> (Map Any Any)]
:requires [[clojure.test :refer [run-all-tests]]])
(is-tc-e #(run-all-tests #"asdf") [-> (Map Any Any)]
:requires [[clojure.test :refer [run-all-tests]]])
(is-tc-err #(run-all-tests) [:-> String]
:requires [[clojure.test :refer [run-all-tests]]]))
(deftest successful?-test
(is-tc-e #(successful? {}) [-> Boolean]
:requires [[clojure.test :refer [successful?]]]))
(deftest compose-fixtures-test
(is-tc-e (compose-fixtures (fn [a :- [-> Any]] (a))
(fn [b :- [-> Any]] (b)))
[[-> Any] -> Any]
:requires [[clojure.test :refer [compose-fixtures]]]))
(deftest testing-vars-str-test
(is-tc-e #(testing-vars-str {}) [-> String]
:requires [[clojure.test :refer [testing-vars-str]]])
(is-tc-err (testing-vars-str 1) Int
:requires [[clojure.test :refer [testing-vars-str]]]))
(deftest testing-contexts-str-test
(is-tc-e (testing-contexts-str) String
:requires [[clojure.test :refer [testing-contexts-str]]])
(is-tc-err (testing-contexts-str) (Map Any Any)
:requires [[clojure.test :refer [testing-contexts-str]]])
(is-tc-err (testing-contexts-str 1) String
:requires [[clojure.test :refer [testing-contexts-str]]]))
babashka/sci
(ns sci.test-utils.macros
(:require
[sci.test-utils.utils]
#?(:clj [clojure.test :as test])
[cljs.test :as cljs-test]))
#?(:clj
(defmethod test/assert-expr 'thrown-with-data?
[msg [_ msg-re data expr]]
(let [[msg-re expected expr]
(if expr [msg-re data expr]
[nil msg-re data])]
`(let [msg-re# ~msg-re
expected# ~expected
msg# ~msg]
(try
~expr
(test/do-report
{:type :fail
:message msg#
:expected expected#
:actual nil})
(catch Exception ex#
(let [data# (ex-data ex#)
ex-msg# (.getMessage ex#)]
(test/do-report
(if msg-re#
(if (re-find msg-re# ex-msg#)
{:type (if (sci.test-utils.utils/submap? expected# data#)
:pass
:fail)
:message msg#
:expected expected#
:actual data#}
{:type :fail
:message msg#
:expected msg-re#
:actual ex-msg#}))))))))))
(deftime
(defmethod #?(:clj cljs.test/assert-expr
:cljs cljs.test$macros/assert-expr)
'thrown-with-data?
[_menv msg [_ msg-re data expr]]
(let [[msg-re expected expr]
(if expr [msg-re data expr]
[nil msg-re data])]
`(let [msg-re# ~msg-re
expected# ~expected
msg# ~msg]
(cljs.test/do-report
(try
~expr
{:type :fail
:message msg#
:expected expected#
:actual nil}
(catch cljs.core/ExceptionInfo ex#
(let [data# (ex-data ex#)
ex-msg# (.-message ex#)]
(if msg-re#
(if (re-find msg-re# ex-msg#)
{:type (if (sci.test-utils.utils/submap? expected# data#)
:pass
:fail)
:message msg#
:expected expected#
:actual data#}
{:type :fail
:message msg#
:expected msg-re#
:actual ex-msg#}))))))))))