This is a cider-nrepl
question, let me know if this is not the right place to ask. Anyway: I am trying to fix a bug/shortcoming in Calva that when running tests for a namespace/file the tests for it’s test ns (same ns with -test
appended) are not run unless that namespace is loaded. For project tests there is a load?
key I can set to true on the message, but there is no such thing for namespace tests. I’ve tried to figure out from the Cider code how it is done there, but I do not quite follow what’s happening. Can I haz some pointers, pretty please? ❤️
There is a key which can load all project namespaces.
Maybe orchard could be updated to minimize how much it loads based on the size of the query?
But generally, loading project namespaces works.
Thanks! I’ll load all namespaces for now. However, Cider has commands for running tests only for loaded namespaces in the project (that’s what happens if you don’t pass that load?
key to the test-all
op). That indicates that Cider does not load all namespaces for running the namespace tests, or I am getting that wrong, maybe?
Oh. Maybe. I wrote this ages ago, so I've forgotten how it works.
Reading the source in orchard is the best bet
I’m trying, believe me! As my competitor, Andrey Lisin, says. 😃
Did you find https://github.com/clojure-emacs/orchard/blob/master/src/orchard/query.clj ?
Cider test just does this: :load-project-ns? load?
Iirc, that's what load did before.
No, didn’t find, thanks again! What I got from the cider-test code was that it only did that for running project tests, not when running tests for some given namespaces. But I could have gotten it wrong.
Those specific things are legacy, use the test-var-query instead
Ah, now we’re talking! Is there somewhere I can read up on these things?
Asking is probably it :D
I'm pretty bad at writing things down :)
I came up with this test var query stuff when I rewrote apropos to be more general
So, I am beginning to understand why you linked me to orchard/query… But I am not quite there yet, what is a var-query? What is an ns-query?
btw. Doing ns-load-all before running tests for a namespaces worked, but it is brutal and makes the first namespace test run take a long time in large projects.
Var-query is best documented on that orchard docstring, it's a data description for filtering vars/nss to be the target of an operation
I’ll read it more carefully this time then. 😃
Only test and apropos support it for now, but if you can think of somewhere to apply it, that would be cool
Looks like I will be able to use this to allow testing of the test under the cursor, right?
Yep!
But you'll need to identify the test using regex, fireplace has one
Maybe refresh would be a cool place to apply this. You could refresh just your test namespaces...
So, now I run the namespace tests using test-var-query instead, that’s cool. But I still fail at finding the -test
tests, because not loaded. Adding a truthful load-project-ns?
to the ns-query doesn’t seem to do anything. This is how my op looks like right now (TypeScript):
op: "test-var-query", ns, id, session: this.sessionId, "var-query": {
"ns-query": {
exactly: [ns],
"load-project-ns?": true
}
}
What does true become over bencode? You might want to use 1 or something
true
works elsewhere. But I did try with 1 as well since that is what replant does. 😃 Looking at the query code, am I correct in reading it as it only considers load-project-ns?
if project?
also is true? https://github.com/clojure-emacs/orchard/blob/master/src/orchard/query.clj#L23
(Not that it works setting that to true as well, but anyway.)
It might be that is a bug :)
Up to us to define behaviour
I personally don't have a problem with that behaviour being changed. I don't think any users of cider would either. It wouldn't be an API change. If you wanted to be really crazy, you could grow the api to hold onto the old behaviour.
I didn't notice this behaviour particularly myself, but I always run with project set to true.
The strange thing is that it doesn’t have an effect for me to set both to true…
Double check how nrepl modified the value
Regardless, it does seem wrong that they should be coupled like that (if that is what they are).
I agree too :)
Yeah, I’ll peek into what happens to the values. But later, now family needs food. 😃 Thanks for the assistance so far!
https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/util/coerce.clj just fyo
So I think you are in the right place. All I can guess is that the code to load project ns isn't working in your context.
It is a bit extra strange that the ns-load-all
op works, which uses the exact same function for loading… I think I am doing something wrong, but we’ll see.