Clojure.test cannot resolve the character from `eval`. Works in REPL and lein run

Pay attention to this far-fetched example, but it was the simplest thing I could think of in order to recreate the problem.

(ns something.core)

(defn call-foo [something & args]
  (let [a-foo (:foo (eval (:quux something)))]
    (apply a-foo args)))

(def Something {
  :foo (fn [& args] args)
  :bar (fn [something] (call-foo something))
})

(defn make-something []
  {:quux 'Something})

Performing the following steps in REPL or lein runworks well.

(let [subject (make-something)                      
      actual (call-foo subject "hello" "greetings")]
  (println actual))                                 
;;=> (hello greetings)

The problem only occurs during this test and runs lein test:

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

(deftest a-test
  (let [subject (make-something)
        actual  (call-foo subject "hello" "greetings")]
    (is (= ["hello" "greetings"] actual))))

This causes an error. Output Example:

ERROR in (a-test) (Compiler.java:6464)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: Something in this context, compiling:(/private/var/folders/0n/c7q7860j34xfc2r1x4q51jrh0000gn/T/form-init9215140948330409114.clj:1:6436)

The line "Unable to resolve symbol: something in this context" makes me think that Somethingfor some reason I am not in the context, but I am evalin call-foo. But why does this only happen in the test?

+4
source share
1 answer

, eval . 'Something something.core something.core-test, . , lein test .

'Something

`Something

. ( ), (println nil ).

+3

All Articles