Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Babashka support #14

Merged
merged 7 commits into from
Dec 29, 2022
Merged

Add Babashka support #14

merged 7 commits into from
Dec 29, 2022

Conversation

matthewdowney
Copy link
Owner

I'm opening this PR to track progress, but it's not quite ready to merge yet.

So far we have

  • Support for running ;=> assertions from Babashka, albeit without file names / numbers.
  • Support for a subset of ;=>> assertions (mirroring whatever matcho supports out of the box).

@matthewdowney
Copy link
Owner Author

More examples here of what works and what doesnt:

(deftest rct-tests
(testing "simple assertions"
(t/passes? "(range 3) ;=> (0 1 2)")
(t/fails? "(range 3) ;=> (0 2 2)" "actual: (not (= (0 1 2) (0 2 2)))")
(t/passes?
"(+ 5 5)
; => 10")
(t/fails?
"; 5 times 5
(* 5 5) ;=> 35"
"; 5 times 5" ; includes the context
"actual: (not (= 25 35))"))
(testing "reflective tests"
(testing "when evaluating a :rct/test comment form in a .bb file"
(let [ns-tests-result
(binding [test/*report-counters* (atom test/*initial-report-counters*)]
(rct/run-ns-tests! 'test-rct-with-bb))]
(is (= ns-tests-result {:test 1 :pass 4 :fail 0 :error 0})
"tests passing"))))
(testing "compatible subset of matcho assertions"
(t/passes? "(+ 5 5) ;;=>> int?")
(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"))
#_(testing "includes file names and line numbers in assertions"
(is (str/starts-with? (t/rct "(+ 1 1) ;=> 3")
"\nFAIL in () (rct_babashka_test.bb:2)\n"))))

  • Files and line numbers in Babashka are probably possible, I bet I'm doing something wrong with SCI
  • Matcho does not totally run on Babashka as-is, even though it should because spec is supported. I suspect this would be easy to address, but would require forking the project or getting a PR merged.
  • Malli runs on Babashka, and could supplant Matcho, but I like how Matcho allows literal syntax for map comparisons, not just spec.

@matthewdowney
Copy link
Owner Author

Ok turns out missing file and line numbers are due to babashka/babashka#1451

@matthewdowney
Copy link
Owner Author

Now all that's missing is Matcho, described here: HealthSamurai/matcho#7

It's a small enough codebase that I can always just fork it.

@matthewdowney
Copy link
Owner Author

Ok so this is complete, pending file names and line numbers in Babashka, which will work as of the next release, at which time I'll uncomment the following test:

#_(testing "includes file names and line numbers in assertions"
(is (str/starts-with? (t/rct "(+ 1 1) ;=> 3")
"\nFAIL in () (rct_babashka_test.bb:2)\n"))))

@matthewdowney matthewdowney merged commit 6be69fa into main Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant