Midje icon indicating copy to clipboard operation
Midje copied to clipboard

Autotest doesn't reload files with reader conditionals

Open frerom opened this issue 9 years ago • 5 comments

I use Midje to test a ClojureScript project, this is made possible with reader conditionals. Testing a .cljc file with pure Clojure content works as it should. But as soon as you involve reader conditionals, i.e. #?(..), with the namespace declaration Midje stops watching that file. Note that using reader conditionals further down the file (that doesn't involve ns) works perfectly fine.

; This doesn't work
#?(:cljs (ns foo.bar (:require [foo.baz]))
   :clj  (ns foo.bar))

; This doesn't work either
(ns foo.bar
  #?(:cljs (:require [foo.baz])))

; This works
(ns foo.bar)
#?(:cljs (def foo "bar")
   :clj  (def foo "baz"))

Midje will run the tests successfully at init, the problem is that the source file isn't recompiled when changed. The file isn't listed in the print out "Loading (< namespaces >)" either.

Does anyone know what might be causing this?

frerom avatar Nov 11 '15 15:11 frerom

Thanks for reporting this - just ran into exactly the same issue. +1.

markmandel avatar Nov 21 '15 22:11 markmandel

Apologies for slowness, and also apologies for being ignorant of Clojurescript and conditional readers. I tried the following with Clojure 1.7:

(ns scratch.core2
  (:use midje.sweet)
  (:require [scratch.core])
  (:require [scratch.core :as generic]))


#?(:cljs (def foo "bar")
   :clj  (def foo "baz"))

When I do lein midje, I get this:

Exception in thread "main" java.lang.RuntimeException: Conditional read not allowed, compiling:(scratch/core2.clj:7:3)

What am I doing wrong?

marick avatar Dec 21 '15 23:12 marick

Without the #? form, everything works:

666 $ lein midje
This is from the Midje configuration file in ${HOME}.
= Namespace scratch.t-core
Clojure version  {:major 1, :minor 7, :incremental 0, :qualifier nil}
= Namespace scratch.t-core2
= Namespace scratch.core2
All checks (1) succeeded.

marick avatar Dec 21 '15 23:12 marick

@marick I believe reader conditionals are only allowed in files with the .cljc extension. The exception shows a file with .clj e.g. scratch/core2.clj

Here is a link to more resources https://github.com/clojure/clojurescript/wiki/Using-cljc

arronmabrey avatar Jan 19 '16 10:01 arronmabrey

I'd love to work on this issue. @marick Could you guide me regarding how could I solve this issue?

viebel avatar Feb 18 '17 19:02 viebel