Tests pass at REPL, fail on command line with lein test - clojure

If I run lein test from within my project's directory, I get odd errors like this:
Exception in thread "main" java.lang.ClassNotFoundException: clojure.set
I use clojure.set in one place in my app.
If I try to run just a single test defined in deftest from the command line, then I get that it cannot find the test on the classpath.
If I run (run-tests) from the REPL, everything passes.
I'd like to be able to run from command line if possible. Can anyone advise what is the issue?

It looks like you need to require clojure.set in the namespace(s) where you are using it.
It works without a require in the repl because nrepl requires it in it's own code in this file. But when running lein test that require is not happening.

(run-tests) only runs the tests in the namespace your repl is in. Perhaps the problem is in a test that is outside of that namespace.

Related

configure lein-cloverage from project.clj

I started using cloverage with leiningen. I want to excude calls to assert from the coverage report.
The following command works fine for me:
$ lein cloverage --exclude-call clojure.core/assert
However, when I put :cloverage {:exclude-call ["clojure.core/assert"]} into the project.clj file and I just call $ lein cloverage, then the parameter is ignored.
How should I configure cloverage from my leiningen project file?
EDIT: I understand that I could create an alias easily with the followings, however, I would prefer configuring it a cleaner way:
:aliases {"coverage" ["cloverage" "--exclude-call" "clojure.core/assert"]}
Hopefully you found a solution. For anyone coming across this post now:
I put the cloverage options under my test profile in my project.clj. So, you could try something like this in project.clj:
:profiles {:test {:cloverage {:exclude-call ["clojure.core/assert"]}}}
When I run cloverage from the command line, I have to do $ lein with-profile test cloverage.
Also, here's the post I used when figuring this out: Can I make lein cloverage skip specific tests?

Cursive editor gives classpath exception when trying to run clojure project that uses figwheel

Trying to get a project that uses figwheel running in Cursive. I can get everything running on the command line using run -m clojure.main script/figwheel.clj but when I follow the instructions for running within Cursive I get the following error:
java.io.FileNotFoundException: Could not locate figwheel_sidecar/repl_api__init.class or figwheel_sidecar/repl_api.clj on classpath.
Does anyone know why this works on the command line and not within Cursive? I believe I followed the directions that the project provided. Do I need to set my classpath somewhere in Cursive.

Lein console (like sbt)

Is there some built-in functionality or plugin to lein to get a lein console, so for example one could test without waiting every time for JVM to start up.
$ lein console
>>> test
...
>>> test
...
>>> jar
Note: I'd like to trigger test runs myself, not e.g. by watching source files. That's why I'd like to have a lein console.
Clarification: I'm not looking for lein repl. I'd like to have a console where I could run lein task commands.
Older versions of leiningen used to include lein interactive, which behaved much like the feature you are asking for: it opened a shell into which you could type test and have it run lein test from the already-running lein jvm, and so on. This feature was removed in the transition to lein 2.0, I think, and although I don't know why I suspect there was a good reason. Maybe try asking in #leiningen on freenode?
You might want to have a look at grenchman. While it's not a Leiningen console it at least enables reusing of an existing REPL session. From what I gather, usage is as follows:
Move somewhere that is not inside a project and call:
$ lein repl :headless
Within your project directory, use:
$ grench lein <task> <options>
Tasks will be run inside the already spun up Leiningen JVM and the startup overhead should disappear.
Building grenchman seems to be tedious, though, and it is recommended to use one of the precompiled binaries (BUT they are currently not available).
And finally, that page also states:
Grenchman is still very new and may not be fully reliable.
So, good luck, I guess?
One option is to run a repl from leiningen's own jar file.
$ java -cp ~/.lein/self-installs/leiningen-2.5.0-standalone.jar clojure.main
Clojure 1.6.0
user=> (require '[leiningen.core.project :as project] '[leiningen.test :as test])
nil
user=> (def prj (project/read))
#'user/prj
user=> (test/test prj)
lein test org.noisesmith.orsos.load-test
Ran 3 tests containing 3 assertions.
0 failures, 0 errors.
nil
user=> (require '[leiningen.jar :as jar])
nil
user=> (jar/jar prj 'org.noisesmith.orsos)
Compiling org.noisesmith.orsos
Created /media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar
{[:extension "jar"] "/media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar"}
user=>
As a baseline, this can run lein tasks without having to restart lein every time. If you also use rlwrap or use nrepl it becomes a bit more usable. As far as I know there is no user friendly tooling around this (though there easily could be).
If you wish to use tasks from lein plugins those can be added to the -cp arg.

leiningen - clojurescript equivalent of lein run?

In clojure I can run:
lein run -m my.namespace # run the -main function of a namespace
and this will run my code from the command line.
Is there an equivalent for Clojurescipt to run the generated code in node.js? (In leiningen)
(I have read the doco for starting the Clojurescript REPL, for the running on node.js and the reply integrated into my application. I was just looking for a one-line command line solution.)
Depending on what your goal is, you might find it useful to use 'cljsbuild test'. You can specify a test context on your project.clj that uses node.js/v8/phantomjs.
Example:
:cljsbuild {
:test-commands {
"v8" ["v8"
"target/generated-sources/private/js/client.js"
"tests/v8-test-runner.js"]}}
v8-test-runner.js:
path.to.your.entrypoint.start()
You can also leave 'lein cljsbuild auto' running and start the javascript application directly:
v8 target/generated-sources/private/js/client.js tests/v8-test-wrapper.js
That's probably the best option if you are building a node.js application using clojurescript. You don't need to worry about classpaths in javascript (which is the major thing that lein run provides), you can just run your application directly from the assembled javascript file.

'leiningen' related commands too slow with Mac OS X

I installed and run lein, but it seems to slow on My Mac (10.6.4).
Running 'time lein help' gives me
real 11m8.674s
user 0m54.297s
sys 1m32.621s
I tried once more.
real 15m25.560s
user 1m36.087s
sys 2m52.745s
What's wrong with this? Is anyone experiencing similar problem? Is there anyway to check what's the problem?
Added
When I install, I used 'sudo lein deps', as I got some errors using 'lein deps'. I guess it caused some problem accessing files. When I run 'sudo lein SOMETHING', it works as usual.
One thing to note is that it will put the src directory on the classpath. If you run it from $HOME and have a 54GB ~/src directory like I do, the JVM will slow to a crawl just trying to find the basic things.
It's because of how it looks for hooks. It's explained here: http://groups.google.com/group/clojure/browse_thread/thread/e04ab3f6e17f85c4.
You could give cake a try. It worked out of the box for my simple project.clj without any changes, and is blazing fast because of the persistent JVM it uses.
Found solution
sudo lein uses different CLASSPATH than that with just lein. I guess my CLASSPATH that contains clojure or clojure-contrib conflicted with the lein.
When I added this code at line 126 of lein, the problem is gone.
CLASSPATH="/Users/smcho/.m2/repository/leiningen/leiningen/1.2.0/leiningen-1.2.0-standalone.jar:lib/dev/swank-clojure-1.2.1.jar::src/:"
For uninstalling/installing, I asked and got an answer here.