nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
pez 2019-02-09T10:47:59.064900Z

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? ❤️

dominicm 2019-02-09T10:58:23.065700Z

There is a key which can load all project namespaces.

dominicm 2019-02-09T10:58:47.066300Z

Maybe orchard could be updated to minimize how much it loads based on the size of the query?

dominicm 2019-02-09T10:59:08.066800Z

But generally, loading project namespaces works.

pez 2019-02-09T11:47:41.070Z

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?

dominicm 2019-02-09T11:52:34.070500Z

Oh. Maybe. I wrote this ages ago, so I've forgotten how it works.

dominicm 2019-02-09T11:53:02.070900Z

Reading the source in orchard is the best bet

pez 2019-02-09T11:58:21.072Z

I’m trying, believe me! As my competitor, Andrey Lisin, says. 😃

dominicm 2019-02-09T12:03:09.072500Z

Did you find https://github.com/clojure-emacs/orchard/blob/master/src/orchard/query.clj ?

dominicm 2019-02-09T12:05:02.073100Z

Cider test just does this: :load-project-ns? load?

dominicm 2019-02-09T12:05:11.073500Z

Iirc, that's what load did before.

pez 2019-02-09T12:23:15.075800Z

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.

dominicm 2019-02-09T12:52:59.076500Z

Those specific things are legacy, use the test-var-query instead

pez 2019-02-09T12:56:38.077400Z

Ah, now we’re talking! Is there somewhere I can read up on these things?

dominicm 2019-02-09T13:00:40.078Z

Asking is probably it :D

dominicm 2019-02-09T13:06:00.079300Z

I'm pretty bad at writing things down :)

dominicm 2019-02-09T13:06:24.080400Z

I came up with this test var query stuff when I rewrote apropos to be more general

pez 2019-02-09T13:06:46.080800Z

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?

pez 2019-02-09T13:08:31.082Z

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.

dominicm 2019-02-09T13:09:40.083400Z

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

pez 2019-02-09T13:10:14.083800Z

I’ll read it more carefully this time then. 😃

dominicm 2019-02-09T13:13:31.084900Z

Only test and apropos support it for now, but if you can think of somewhere to apply it, that would be cool

pez 2019-02-09T13:13:59.085400Z

Looks like I will be able to use this to allow testing of the test under the cursor, right?

dominicm 2019-02-09T13:17:10.085800Z

Yep!

dominicm 2019-02-09T13:17:59.086600Z

But you'll need to identify the test using regex, fireplace has one

dominicm 2019-02-09T13:22:01.087300Z

Maybe refresh would be a cool place to apply this. You could refresh just your test namespaces...

pez 2019-02-09T13:49:39.090400Z

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
                    }
                }

dominicm 2019-02-09T15:22:52.091300Z

What does true become over bencode? You might want to use 1 or something

pez 2019-02-09T16:37:25.093800Z

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

pez 2019-02-09T16:38:16.094600Z

(Not that it works setting that to true as well, but anyway.)

dominicm 2019-02-09T16:48:27.095Z

It might be that is a bug :)

dominicm 2019-02-09T16:48:35.095300Z

Up to us to define behaviour

dominicm 2019-02-09T16:52:51.097100Z

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.

dominicm 2019-02-09T16:53:17.097900Z

I didn't notice this behaviour particularly myself, but I always run with project set to true.

pez 2019-02-09T17:34:28.098900Z

The strange thing is that it doesn’t have an effect for me to set both to true…

dominicm 2019-02-09T17:35:39.099700Z

Double check how nrepl modified the value

pez 2019-02-09T17:38:16.100300Z

Regardless, it does seem wrong that they should be coupled like that (if that is what they are).

dominicm 2019-02-09T17:39:11.101500Z

I agree too :)

pez 2019-02-09T17:39:51.102400Z

Yeah, I’ll peek into what happens to the values. But later, now family needs food. 😃 Thanks for the assistance so far!

dominicm 2019-02-09T17:43:22.103700Z

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.

pez 2019-02-09T18:21:06.105900Z

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.