Skip to content

Commit

Permalink
Full Matcho support in Babashka as of HealthSamurai/matcho#7
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdowney committed Dec 21, 2022
1 parent 2888610 commit 2e78e36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 3 additions & 2 deletions bb/test_helpers.bb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
[clojure.string :as str]
[clojure.test :refer [is] :as test]
[com.mjdowney.rich-comment-tests :as rct]
[com.mjdowney.rich-comment-tests.emit-tests :as tests]))
[com.mjdowney.rich-comment-tests.emit-tests :as tests]
[rewrite-clj.zip :as z]))

(defn rct
"Stick a single RCT assertion string into a comment block and run it,
returning any test output."
[s]
(let [rct-data
(->> (rewrite-clj.zip/of-string
(->> (z/of-string
(str "^:rct/test\n (comment\n" s "\n)")
{:track-position? true})
rct/rct-zlocs
Expand Down
23 changes: 15 additions & 8 deletions bb/test_rct_with_bb.bb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
(is (= ns-tests-result {:test 1 :pass 4 :fail 0 :error 0})
"tests passing"))))

(testing "compatible subset of matcho assertions"
(testing "matcho assertions"
(t/passes? "(+ 5 5) ;;=>> int?")
(t/fails? "(+ 5 5) ;;=>> string?" "Matcho pattern mismatch:"))
(t/fails? "(+ 5 5) ;;=>> string?" "Matcho pattern mismatch:")

;; TODO: Figure out how to make these pass :)
#_(testing "(still) incompatible subset of matcho assertions"
(t/passes? "(range 3) ;;=>> '(0 1 2)")
(t/passes? "(assoc {} :foo :bar :bar :baz) ;;=>> {:foo :bar ...}")
(t/passes? "(+ 5 5) ;=>> 10"))
(t/passes? "(range 3) ;;=>> '(0 1 2)")
(t/passes? "(assoc {} :foo :bar :bar :baz) ;;=>> {:foo :bar ...}")
(t/passes? "(+ 5 5) ;=>> 10"))

#_(testing "includes file names and line numbers in assertions"
(is (str/starts-with? (t/rct "(+ 1 1) ;=> 3")
Expand All @@ -51,19 +49,28 @@
(+ 5 5) ;; => 10

;; Pattern matching assertions with =>>
(range 3) ;=>> '(0 1 ...)
(+ 5 5) ;=>> int?

(def response {:status 200 :body "ok"})
response
;=>> {:status #(< % 300)
; :body not-empty}

;; Or with spec
(require '[clojure.spec.alpha :as s])
(into {} (System/getProperties))) ;=>> (s/map-of string? string?)
(into {} (System/getProperties)) ;=>> (s/map-of string? string?)
)

(defn main []
(let [{:keys [fail error] :as results}
(clojure.test/test-ns 'test-rct-with-bb)]
(println results)
(when (pos? (+ fail error))
(System/exit 1))))

(comment
(rct/run-file-tests!
"src/com/mjdowney/rich_comment_tests.cljc"
(find-ns 'com.mjdowney.rich-comment-tests))
)
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/tools.namespace {:mvn/version "1.3.0"}
rewrite-clj/rewrite-clj {:mvn/version "1.1.45"}
healthsamurai/matcho {:mvn/version "0.3.9"}}
healthsamurai/matcho {:mvn/version "0.3.10"}}
:aliases {:test {:extra-paths ["test"]
:extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.0" :git/sha "b3fd0d2"}}
:main-opts ["--report" "stderr"
Expand Down

0 comments on commit 2e78e36

Please sign in to comment.