Fork me on GitHub
Jim Newton08:09:55

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 Newton08:09:02

What's the correct working flow for this?

Jim Newton08:09:49

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.


@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.


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


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 Newton10:09:35

@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.


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

Jim Newton11:09:30

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 ""
  :license {:name "MIT"
            :url ""}
  :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}})


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

Jim Newton11:09:19

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


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.

πŸ‘ 3

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


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


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 Newton11:09:44

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.


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)


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


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 Newton11:09:02

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.


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 Newton11:09:45

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

πŸ‘ 3