clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
pez 2020-11-16T11:01:40.233400Z

I get an compile error about java.lang.Symbol not being able to be interpreted as a regex when creating the regex using re-pattern. What am I not understanding?

2020-11-18T21:00:18.263800Z

If you mean, does it need to be a literal, or can it be an expression that evaluates to a regex, I am pretty sure it could be an expression that evaluates to a regex

borkdude 2020-11-18T21:22:35.264200Z

in CLJS it's a macro

pez 2020-11-19T07:54:36.280500Z

I added a not to the clojuredocs page about run-all-tests now. https://clojuredocs.org/clojure.test/run-all-tests Would have helped me a lot to find such a note when this bit me. 😃

pez 2020-11-16T11:02:31.233600Z

I need it for run-all tests.

pez 2020-11-16T11:04:49.233800Z

And the regex works when using it with, say, re-find

pez 2020-11-16T11:13:52.234Z

So, it’s the run-all-tests macro that seems to need a literal regex?

Louis Kottmann 2020-11-16T11:16:43.234500Z

@pez can we see the code please?

pez 2020-11-16T11:45:32.234600Z

(let [rp (re-pattern "foo")] (cljs.test/run-all-tests rp))

thheller 2020-11-16T12:10:35.234800Z

@pez in cljs run-all-tests is a macro so it only takes a literal regexp, not a symbol.

borkdude 2020-11-16T13:18:45.235100Z

user=> (doc clojure.test/run-all-tests)
-------------------------
clojure.test/run-all-tests
([] [re])
  Runs all tests in all namespaces; prints results.
  Optional argument is a regular expression; only namespaces with
  names matching the regular expression (with re-matches) will be
  tested.

pez 2020-11-16T14:16:51.235300Z

Yeah, so that doesn’t really say to me that it needs to be a literal regex.

pez 2020-11-16T14:19:30.235500Z

Thanks. Does it follow from “it is a macro” that “it only takes literals”?. Newbish question, maybe, but I am under the impression that I use macros all the time, passing in symbols.

borkdude 2020-11-16T14:58:41.235700Z

True. CLJS sometimes uses macros for things that are functions in CLJ because CLJS is more restricted

thheller 2020-11-16T15:22:04.235900Z

@pez it kind of follows yes. of course it depends on what the macro does. most macros are happy to use whatever you provide since they don't actually want to eval the argument and just place it somewhere else in their output. the cljs.test macros however evaluate at compile time to filter the available tests/namespaces since that info only exists at compile time and not at runtime (unlike clojure).

pez 2020-11-16T16:09:59.236500Z

Awesome. Thanks for the help understanding this!

thheller 2020-11-16T16:12:40.236700Z

I don't know what you are trying to do exactly but maybe the stuff I have in shadow.test.env/get-test-data is useful for you https://github.com/thheller/shadow-cljs/blob/d80ee477020c91fa441bb205f52967c1100e2526/src/main/shadow/test/env.clj#L7

thheller 2020-11-16T16:12:52.237Z

that instead gives you a map with all the test data in CLJS

thheller 2020-11-16T16:13:35.237200Z

that you can actually filter like any other data. all the shadow-cljs test things use this. makes things much more flexible without the macro hell.

thheller 2020-11-16T16:14:09.237400Z

koacha has something similar

thheller 2020-11-16T16:15:23.237700Z

still has the macro problem in that it can't dynamically discover tests but using an dynamic regexp works just fine ;)

borkdude 2020-11-16T16:16:13.238Z

or just use a test runner? I've heard good things about kaocha but for CLJS I found it problematic a couple of times. I've been using https://github.com/Olical/cljs-test-runner which is much simpler (as in more basic) and I stuck with it since.

pez 2020-11-16T16:31:12.238800Z

Thanks a lot for those pointers. We have our own test-runner and it it giving us grief, so a colleague started to try rewrite parts of it and then we ran into this problem. Getting out of macro hell and into data land is exactly what I want.

pez 2020-11-16T16:35:23.239Z

What I’d really like to do is move the project over to shadow-cljs, but so far it has said no to my attempts. Inching my way there, so our test runner won’t be needed eventually.