cider

A channel dedicated to the Clojure Interactive Development Environment that Rocks (aka CIDER). :cider:
Jim Newton 2020-09-01T08:37:55.019300Z

I don't understand what happens when I start cider (using cider-jack-in). which files get loaded? it seems to be a function of the current directory. Normally I first open (in emacs) one of the .clj files of my project, then exec cider-jack-in. It seems the clj files under the src directory are loaded, but not the clj files under the test directory. So when I try to call (run-tests) at the cider repl, no tests are found.

Jim Newton 2020-09-01T08:38:02.019600Z

What's the correct working flow for this?

Jim Newton 2020-09-01T08:45:49.020200Z

From the shell if I use "lein test" from the repl in the project directory, then all the tests seem to get run. But when I start cider, and require clojure.test then (run-tests), no tests are found.

practicalli-john 2020-09-01T09:07:36.025800Z

@jimka.issy From my understanding, the Cider test runner only runs those tests that have been evaluated and are therefor in the REPL. When I first start the REPL I will open the test file in a buffer and call Cider run all tests. This will load (evaluate) the code in the current buffer and therefore can run the tests as they are in the REPL.

practicalli-john 2020-09-01T09:09:07.027700Z

If I rename test functions, I will undefine them first and then change their name and evaluate the new function, before running tests again.

practicalli-john 2020-09-01T09:11:11.030600Z

I don’t believe CIDER loads any Clojure code when starting a REPL. However, if the project has a user.clj file on the class path, then that code will be loaded by the REPL itself, as it starts in the user namespace by default.

Jim Newton 2020-09-01T10:57:35.033200Z

@jr0cket That's not the behavior I observe. I don't have a user.clj file, but when I start cider, it apparently loads a file at src/clojure_rte/core.clj and sets the ns to the one defined in that file, so that my prompt at the repl is clojure-rte.core>. It seems it has loaded all the files that core.clj requires as well, probably simply as a result of the :require in that ns definition.

practicalli-john 2020-09-01T11:00:29.035300Z

Sounds like you have that set in Leiningen, it's not something I believe CIDER does, but something it uses

Jim Newton 2020-09-01T11:00:30.035400Z

While I don't have a user.clj file, I do seem to have a project.clj file in the project top level directory. Perhaps this is what cider has loaded? Its content is the following.

(defproject clojure-rte "0.1.0-SNAPSHOT"
  :description "Regular type expressions, for Clojure"
  :url "<https://gitlab.lrde.epita.fr/jnewton/clojure-rte.git>"
  :license {:name "MIT"
            :url "<https://opensource.org/licenses/MIT>"}
  :plugins [      [lein-cloverage "1.1.2"]]
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [lein-cloverage "1.1.2"]
                 [org.clojure/data.json "1.0.0"]
                 [org.clojure/math.combinatorics "0.1.6"]]
  :main ^:skip-aot clojure-rte.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

practicalli-john 2020-09-01T11:00:58.035900Z

Ther you go, it's set in your project file

Jim Newton 2020-09-01T11:03:19.037300Z

So does cider read the project file automatically, or is this something I've told it to do, or something I've told lein to do? I set up the project some time ago. I don't remember how, but probably using lein new

practicalli-john 2020-09-01T11:14:31.042400Z

Cider simply calls Leiningen, which you can see if you use C-u before cider-jack-in. Cider adds a few dependencies to ensure the Leiningen runs the REPL with an nREPL server so Cider can connect to the REPL. Leiningen starts the REPL using the details in project.clj and therefore switches the namespace.

πŸ‘ 1
practicalli-john 2020-09-01T11:16:05.044900Z

As cider connects to the REPL I assume it gets the current state of that REPL over the nREPL connection.

practicalli-john 2020-09-01T11:16:48.046500Z

I am sure @dpsutton or @bozhidar will correct anything I got wrong 😁

practicalli-john 2020-09-01T11:18:15.048900Z

I consider the REPL as a separate process that Cider connects to, once it's established. Cider jack-in automates the who process. Otherwise you would start a repl on a terminal window using lein repl and then use cider connect to establish the nREPL connection

Jim Newton 2020-09-01T11:18:44.050200Z

On a bit more investigation, it seems that cider/lein/clojure indeed HAS loaded the tests. Because if I run (run-all-tests) it runs lots of clojure internal tests, but also runs the tests defined in my project. It seems to be simply that (run-tests) only runs the test in the current namespace. There does not seem to be a concept of run-tests-in-project.

practicalli-john 2020-09-01T11:21:19.053600Z

There are quite a few test functions. If all tests are loaded in the REPL then the all tests command will run them all I believe (I should check this)

practicalli-john 2020-09-01T11:24:53.054Z

cider-test-run-project-tests is the function that gets called when I run tests

practicalli-john 2020-09-01T11:26:47.055800Z

I uses Spacemacs which has a function called spacemacs/cider-test-run-all-tests which first loads the current buffer and then calls cider-test-run-project-tests . This should run all tests in the project (but maybe only so long as those tests have been evaluated)

Jim Newton 2020-09-01T11:27:02.056100Z

Interesting, I've never run the tests using the cider- functions; rather I've always run them either from the shell using lein test or from the repl.

practicalli-john 2020-09-01T11:31:14.060300Z

Test runners run from the command line should always run all tests from the files. Cider seems to mainly run what has been evaluated in the REPL, so I tend to use it for the test namespace I am working on. It can be possible to have CIDER test runner having a slightly different set of tests than are written to files, especially if you rename deftest functions without undefining the old names (or restarting the REPL). However, the cider test runner is very convenient for rapid feedback. Some test runners have a watch mode, so will run when ever you save code to files, this can be quite useful too. An of course I assume you have a test runner working with what ever CI service you are using πŸ™‚

Jim Newton 2020-09-01T11:44:45.063100Z

I do periodically like to run all the tests of my project inside cider because it is easier to debug a failure than when such is reported from the lein command line. Furthermore, I like to run all the tests of my project, rather than just what has changed, because I have lots of functions with subtle dependences. For example I have a logic-reasoning-engine which has certain set of capabilities. From time to time I improve it to make it smarter, and this causes certain tests to fail which were assuming a less intelligent engine. Of course I prefer to find this out before pushing to gitlab

πŸ‘ 1