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

Automatically quote result when used with => #5

Closed
lilactown opened this issue Dec 10, 2022 · 2 comments · Fixed by #6
Closed

Automatically quote result when used with => #5

lilactown opened this issue Dec 10, 2022 · 2 comments · Fixed by #6

Comments

@lilactown
Copy link
Contributor

This might be controversial, but I thought I'd throw it out there: I think that when reading the expected result, the form should be automatically quoted. E.g.

^:rct/test
(comment
  (map inc [1 2 3])
  ;;=> (1 2 3)
  )

Today, this would throw with the error

Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.ClassCastException: class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')

Because when we emit the test code, it evaluates the result form as an expression.

My suggested change is to treat the result form as data, so that the above test would pass.

@matthewdowney
Copy link
Owner

Hmm yes this makes sense to me, and I like your solution.

Initially I was thinking it might be an issue for matcho patterns, for example here I'd want it to use int? rather than 'int? as the pattern:

^:rct/test
(comment
  (+ 5 5) ;=>> int?
)

but this still works in your implementation, so no downsides that I can see.

The only thing I can think of that worked before but will not work now is something like

:rct/test
(comment 
  (def expected 10)
  (+ 5 5) ;=> expected
)

But I don't that that is a particularly natural use of a comment anyway, and if anyone wants to do it they can just (+ 5 5) ;=>> expected, making more explicit that it's not an assertion of literal equality.

So, fantastic addition, thank you!

@lilactown
Copy link
Contributor Author

Great! Thanks for taking a look at both my PRs 💙

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 a pull request may close this issue.

2 participants