无法获取宏的价值

时间:2014-11-25 08:37:59

标签: clojure leiningen

我使用lein命令创建了一个项目。 这是我的源文件:

(ns database.core)
(defn movies[na rent qty]
  (spit "e.txt" (.toString [{:na na :rent rent :qty qty}]))
  (read-string (slurp "e.txt")))

这是我的项目文件:

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

(deftest movies-test
  testing "movies"
  (let [jun (movies "Dark-knight" 12 6)]
    (is (= (get-in jun [0 :na]) "Dark-knight"))
    (is (= (get-in jun [0 :rent]) 12))
    (is (= (get-in jun [0 :qty]) 6))))

但是当我尝试运行它时,我不断收到此错误。 clojure.lang.Compiler $ CompilerException:java.lang.RuntimeException:无法获取宏的值:#'clojure.test / testing,compiling:(C:\ Users \ A \ database \ test \ database \ core_test.clj :5:1)

出现此错误的可能原因是什么?

1 个答案:

答案 0 :(得分:4)

必须将

testing宏括在其自己的括号中,以便调用它

(deftest movies-test
  (testing "movies"
    (let [jun (movies "Dark-knight" 12 6)]
      (is (= (get-in jun [0 :na]) "Dark-knight"))
      (is (= (get-in jun [0 :rent]) 12))
      (is (= (get-in jun [0 :qty]) 6)))))