clojure-expectations / lein-autoexpect

Run expecations when source or test files change
103 stars 12 forks source link

Problem with reader literals and tools.namespace #11

Open mmower opened 10 years ago

mmower commented 10 years ago

Hi Jake.

So a problem has popped up that appears to be related to the use of tools.namespace for reloading (I'm reporting some detective work by llasram in #clojure here):

Ok, so usually namespaces are created on-demand and never removed When clojure.core is first loaded and initialized data-readers, it creates namespaces and vars for all the referenced reader functions, which will be at that point unbound Normally, when you then load a namespace, if the namespace object already exists, it just creates/updates the bindings for vars in the namespace But the tools.namespace reload code is destroying the namespace itself, and creating a new one to then load code into The data-readers map is left holding a var in a namespace object which no-one else can see, and never gets new code loaded into it

The net result is that if you try and use a reader literal in your test code you get an exception, see: https://www.refheap.com/85727 which you don't get in normal use or from the REPL.

Any thoughts?

m/

jakemcc commented 10 years ago

Will have to look into it. Seems like either might need to do something different with tools.namespace or try to figure out if tools.namespace can be patched.

jakemcc commented 10 years ago

This is hacky and not actually a solution but you may be able to stop a specific namespace from being reloaded.

https://github.com/clojure/tools.namespace#managing-reloads

I haven't tried this but it seems like you may be able to do what it suggests to force certain namespaces to not be reloaded.

mmower commented 10 years ago

Hi Jake. I'm not sure how I'd apply this workaround as the namespace I'd need to stop reloading contains the namespace I'm testing which is, I assume, what is getting reloaded for each test run?