3
votes

Dumb newbie question here. I created a brand new lein project and I am trying to run the sample test in the "core_test.clj" file. I am using emacs and "nrepl-jack-in". But when I run "(run-all-tests)" from the repl, I get:

Unable to resolve symbol: deftest in this context, compiling:(NO_SOURCE_PATH:1:1)

Interestingly, the test works from these two scenarios:
1) "lein test" from the commandline
- or -
2) If I put the following line in the repl beforehand:

(ns my-prog.core-test (:require [clojure.test :refer :all] [my-prog.core :refer :all]))

Interestingly, this line is in the "core_test.clj" file itself, but I guess it's not evaluating for some reason. I am evaluating the buffer using Ctrl-x Ctrl-e in emacs but it does not seem to read the namespace specs.

2

2 Answers

2
votes

You'll want to use C-c C-k to evaluate your whole buffer. It loads the file in one go. Alternatively, you can require the namespace you need at the REPL, possibly passing in :reload or :reload-all to cause previously loaded namespaces to be loaded again. (You can also require your namespace at first giving it an alias -- (require '[foo.core :as foo]) -- then use the chord to reload.)

C-x C-e is only really useful for evaluating single expressions for their values. The nice thing about it is that those expressions need not live at top level. (For example, you might put a (comment ...) section with some useful test expressions in your file, then use C-x C-e to check their values given the current state of the JVM.)

1
votes

I'm not sure if you've solved this or not, but I ran into this issue recently when upgrading an old library that had Clojure 1.2 as a dependency. After a little bit of time, I realized the :refer :all syntax was added in Clojure 1.4. There are two solutions to this issue:

  • Upgrade to Clojure 1.4+:

    In the project.clj update the dependency, e.g. [org.clojure/clojure "1.4.0"] to switch to Clojure 1.4.

  • Use use instead; in this case the namespace declaration would be:

    (ns my-prog.core-test 
      (:use [[clojure.test] 
             [my-prog.core]))
    

Hope that helps!