Lein Midje :autotest throwing exception (No namespace found) - clojure

I am trying to setup autotest for midje. Currently, running lein midje works. However running lein midje :autottest gives me the stack trace below.
I run through my different namespaces and they all compile
Compiling 1 source files to /Users/oloo/Documents/work/cmp/target/classes
warning: Supported source version 'RELEASE_6' from annotation processor 'org.sonatype.guice.bean.scanners.index.SisuIndexAPT6' less than -source '1.7'
1 warning
======================================================================
Loading (cmp.models cmp.util cmp.repository.orderdeliveryschedule-repository cmp.repository.facility-repository cmp.repository.facility-cycle-data-repository cmp.views.layout cmp.routes.facility cmp.repository.item-repository cmp.repository.procurement-plan-repository cmp.routes.login cmp.excel-util cmp.repository.district-repository cmp.repository.facility-order-repository cmp.repository.facility-issue-repository cmp.routes.import-data cmp.test-util cmp.routes.item cmp.routes.district cmp.repository.user-repository cmp.routes.reports cmp.repository.category-repository cmp.routes.facility-issue cmp.routes.procurement-plan cmp.routes.facility-order cmp.handler cmp.repl cmp.repository.level-repository)
log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.Exception: No namespace: cmp.routes.item found
at clojure.core$the_ns.invoke(core.clj:3760)
at clojure.core$ns_name.invoke(core.clj:3767)
at midje.repl$on_require_failure.invoke(repl.clj:387)
at midje.data.project_state$require_namespaces_BANG_$broken_source_file_QMARK___5874.invoke(project_state.clj:65)
at midje.data.project_state$require_namespaces_BANG_$shorten_ns_list_by_trying_first__5877.invoke(project_state.clj:69)
at midje.data.project_state$require_namespaces_BANG_.invoke(project_state.clj:75)
at midje.data.project_state$react_to_tracker_BANG_$fn__5889.invoke(project_state.clj:98)
at midje.repl$namespace_stream_checker.invoke(repl.clj:403)
at midje.data.project_state$react_to_tracker_BANG_.invoke(project_state.clj:94)
at midje.data.project_state$mkfn_COLON_scan_and_react$fn__5893$fn__5894.invoke(project_state.clj:109)
at clojure.lang.Atom.swap(Atom.java:37)
at clojure.core$swap_BANG_.invoke(core.clj:2160)
at midje.data.project_state$mkfn_COLON_scan_and_react$fn__5893.invoke(project_state.clj:107)
at midje.data.project_state$load_everything.invoke(project_state.clj:117)
at midje.repl$autotest.doInvoke(repl.clj:511)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at midje.repl$autotest.doInvoke(repl.clj:524)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at user$eval6032.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6619)
at clojure.lang.Compiler.eval(Compiler.java:6609)
at clojure.lang.Compiler.eval(Compiler.java:6582)
at clojure.core$eval.invoke(core.clj:2852)
at clojure.main$eval_opt.invoke(main.clj:308)
at clojure.main$initialize.invoke(main.clj:327)
at clojure.main$null_opt.invoke(main.clj:362)
at clojure.main$main.doInvoke(main.clj:440)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
Subprocess failed

See this: https://github.com/marick/Midje/issues/215
It says:
If a file being loaded by Midje at startup has a parse error (a reference to an unknown
symbol, etc.) that prevents it from being loaded successfully, Midje swallows the original
load error and instead prints the following error, which is much less useful.
I have suffered from this too: any little typo brings up this misleading error message.

I remember having problems with autotest and namespaces that :require or :use other namespaces using the [prefix ns1 ns2 ...] form. So, the following did not work:
(ns abc
(:use [abc def ghi]))
while this was okay:
(ns abc
(:use abc.def
abc.ghi))
Are you using that kind of syntax?

Related

leiningen project: repl-options/init

When I add :repl-options {:init (print "x..")} to ~/.lein/profiles.clj it does what it should on every repl start-up. however, when I add the same to my local project.clj, I receive this error:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: do in this context, compiling:(/tmp/form-init5885833654225579206.clj:1:886)
I'm using leiningen 2.5.3
I've stumbled across this issue as well - I tried to use multiple profiles, each with its own :repl-options.
The issue is that Leiningen doesn't merge `:init: correctly. You can refer to this issue for more details.
Unfortunately, I couldn't find any fix that would work for me. And the issue itself won't be fixed till Leiningen 3.0.

How to reload namespace into repl after error?

During development, I often require a namespace and then discover that the source file has an error that prevents it from being compiled:
(require '[foo.bar :as fb])
CompilerException java.lang.RuntimeException: ...
After I fix the error, I try to require the namespace again, but I can't:
(require '[foo.bar :as fb])
CompilerException java.lang.Exception: namespace 'foo.bar' not found, compiling: ...
My solution has been to kill the repl and run lein repl again, but that's obviously not ideal.
Is there a way to clean up the effects of the previous failed require?
(And why is the error "namespace ... not found"? That doesn't make sense to me. The source file is still there, and Clojure was able to find it a minute earlier--that's how I knew about the error.)
require takes an optional :reload argument that forces reloading of changes, even if require has already been run.
(require '[foo.bar :as foo] :reload)
This is useful when there was an error upon the initial loading of the namespace, or if you just want to load a newer version of the namespace.
There is also :reload-all for loading all the recursive required code of that namespace as well.

Getting an exception when trying to run lein

I get the following exception when trying to run lein in linux.
Exception in thread "main" java.lang.NoClassDefFoundError: clojure.core.protocols$fn__5393
at java.lang.Class.initializeClass(libgcj.so.10)
at clojure.core.protocols__init.load(Unknown Source:16)
at clojure.core.protocols__init.<clinit>(Unknown Source)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at clojure.lang.RT.loadClassForName(RT.java:1578)
at clojure.lang.RT.load(RT.java:399)
at clojure.lang.RT.load(RT.java:381)
at clojure.core$load$fn__4519.invoke(core.clj:4915)
at clojure.core$load.doInvoke(core.clj:4914)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core__init.load(Unknown Source:5342)
at clojure.core__init.<clinit>(Unknown Source)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at clojure.lang.RT.loadClassForName(RT.java:1578)
at clojure.lang.RT.load(RT.java:399)
at clojure.lang.RT.load(RT.java:381)
at clojure.lang.RT.doInit(RT.java:416)
at clojure.lang.RT.<clinit>(RT.java:302)
at java.lang.Class.initializeClass(libgcj.so.10)
at clojure.main.<clinit>(main.java:20)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.VerifyError: verification failed at PC 214 in
clojure.core.protocols$fn__5393:invoke((Ljava.lang.Object;Ljava.lang.Object;Ljava.lang.Obje ct;)Ljava.lang.Object;): incompatible type on stack
at java.lang.Class.initializeClass(libgcj.so.10)
...25 more
I've followed the instructions on their github page, but no luck. I thought it would be fun to start learning clojure today but instead I've had nothing but problems, I don't even know what leiningen is, other than I apparently have to have it.
sorry about the frusteration,
Leiningen is a build tool to take the pain out of getting hacking on a new clojure project.
Before leiningen existed many people would try to "install" clojure by downloading a jar file out build it from source. Instead of doing any of that you just specify the version you want to use in the leiningen project.clj file and it installs it locally as a dependency for that project.
have you run:
lein new hello_clojure
cd hello_clojure
edit project.clj and set it to use clojure 1.3.0 :dependencies [[org.clojure/clojure "1.3.0"]
lein deps
lein repl
(+ 1 2 3 4)
When things go wrong with leiningen I generally:
lein upgrade
rm lib/*
lein deps
Problems like this are uncommon (for me) and usually fairly specific, so perhaps you would do well to drop into #clojure on irc.freenode.net and ask. It's a very friendly croud dont worry.

clojure.contrib.duck-streams FileNotFoundException, why?

user=> (use '[clojure.contrib.duck-streams])
java.io.FileNotFoundException: Could not locate clojure/contrib/duck_streams__in
it.class or clojure/contrib/duck_streams.clj on classpath: (NO_SOURCE_FILE:0)
Clojure.contrib is in CLASSPATH still it is throwing Exception. Do I need some other Jar?
Use clojure.java.io instead, it's included with 1.2.
I highly recommend using leiningen to sort this out.
try the lein repl command to get a quick repl with a working classpath.
According to this message:
http://osdir.com/ml/clojure/2010-10/msg00834.html
clojure.contrib.duck-streams has been deprecated.

Testing in leiningen

I am writing a small Clojure project using leiningen with the following directory structure:
project
+ src
+ org/example/project/core.clj
+ test
+ org/example/project/core.clj
When I run lein test, it reports that it ran 0 tests with 0 failures, but I purposely put a test designed to fail in the test/.../core.clj file.
I added the line :test-path test to my project.clj file and when I re-ran, got the error:
Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$script_opt.invoke(main.clj:270)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:458)
at clojure.lang.Var.invoke(Var.java:377)
at clojure.lang.AFn.applyToHelper(AFn.java:174)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:471)
at clojure.java.io$fn__7328$G__7323__7333.invoke(io.clj:34)
at clojure.java.io$file.invoke(io.clj:401)
at leiningen.util.ns$namespaces_in_dir.invoke(ns.clj:38)
at leiningen.test$test.doInvoke(test.clj:45)
at clojure.lang.RestFn.invoke(RestFn.java:411)
at clojure.lang.Var.invoke(Var.java:365)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.core$apply.invoke(core.clj:542)
at leiningen.core$apply_task.invoke(core.clj:156)
at leiningen.core$_main.doInvoke(core.clj:212)
at clojure.lang.RestFn.applyTo(RestFn.java:138)
at clojure.core$apply.invoke(core.clj:540)
at leiningen.core$_main.invoke(core.clj:217)
at user$eval167.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:5424)
... 11 more
I am running Clojure 1.2 and the latest lein (1.3.1).
Looks like a problem with either clojure.core or the lein code.
Had the same issue.
After a while I noticed that leins default path to tests are:
test/{project-name}/test/{file-under-test}.clj
^^^^
Note an extra test directory in the path.
As for the source layout. I think you basically shadow your test with the real core.clj file. That's probably why clojure.test doesn't find any tests. Did you try a different namespace and file name? eg. test/example/project/test_core.clj.