-
Notifications
You must be signed in to change notification settings - Fork 12
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
Idea: use any comment block as test #49
Comments
Having But their usability as tests is limited that you have to run them one by one.
|
A similar idea here: https://github.com/lread/test-doc-blocks/blob/main/doc/01-user-guide.adoc#introduction It takes your code sections from markdown and interprets:
as a test assertion. |
I might do a little prototype of such a test runner using rewrite-clj. |
Thank you for sharing your idea! Parsing
There is also the question of is it moral, what are the risks, is it worth it? What would RH do? |
Whether if it is moral, I think the question should be: should it be explicit? I think yes. That is why I put an explicit I just posted this idea for a lack of "Github Discussions", I think that is a much better fit, as this idea isn't really actionable. |
Ah, thank you for pointing out that you tag the comment for RCF evaluation, I missed that! |
Thank you @ieugen for the feedback! You can still separate your RCF tests into a |
@dustingetz Maybe going a bit off-topic here, but how does the infix notation play well with the REPL? E.g.: |
(tests 1 := 2) |
:-) But that's not how you normally work with rich comment forms? |
put your cursor on the 1 and send form to repl? I am confused |
For RCF to use any comment block as test, without having to add special syntax or a dependency, I assume we would have to hook onto the clojure reader. I’m not sure how, but if it’s possible it would be big. If changing
It saves a |
@ggeoffrey I think you would have to go with an approach using rewrite-clj, or perhaps edamame or clojure.tools.reader, to read top level comments and process them differently. See here for such an approach: #49 (comment) |
Using data readers would still require you to register a data reader using a dependency (or no-op). |
Thank you for the link. It seems these approaches are unfortunately not compatible with a live REPL. As far as I can tell, the Clojure LispReader can’t be extended or overloaded. So it would force us into a completely different workflow (parsing files vs live coding). |
The idea is, in both of these forms what’s on right is like an annotation. We usually evaluate the left hand side at the REPL. (comment
1 ;; => 1
) (tests
1 := 1) IMO infix vs prefix should not be a constraint. Infix should just be sugar, meaning prefix could work too. |
Makes sense now, thanks. |
I think Stuart Halloway's transcriptor is a nice alternative approach: https://github.com/cognitect-labs/transcriptor
These appear in successive order and can be evaluated separately (to check if the assertion is valid during dev time for example). |
Thanks for pointing that out – I don't think we considered that style. What do you think of (require '[hyperfiddle.rcf :as rcf :refer [=> tests]])
(tests
(map inc [1 2 3])
(=> '(2 3 4)))
(tests (map inc [1 2 3]) (=> '(2 3 4))) clojure.core/=> |
Seems like an improvement to me! |
It seems https://github.com/matthewdowney/rich-comment-tests ran with this idea! :) |
It also worth noting that neither of these two brilliant libs (RCF nor RCT) eliminate the problem with dangling regular (uninstrumented) |
It would be great if RCF could use any comment block as test, without having to add special syntax or a dependency for a library.
This might require a different approach though and I could see that this would not be within RCF's scope. Just wanted to share the idea and see what you think of it. Feel free to migrate this issue to "Github Discussions" once you activate that in this repo, or close this issue.
The text was updated successfully, but these errors were encountered: