我想修改cake test
以便它可以使用a different value for *stack-trace-depth*
。修改`蛋糕測試`來控制堆棧跟蹤深度(Clojure)
的built-in definition很簡單:
(deftask test #{compile}
"Run project tests."
"Specify which tests to run as arguments like: namespace, namespace/function, or :tag"
(run-project-tests))
理想情況下,我想指定用命令行參數--depth=n
,東西這個效果值:
(binding [*stack-trace-depth* (if (*opts* :depth)
(read-string (*opts* :depth)))]
(run-project-tests))
什麼代碼,我需要做這個工作?
基於反應:把在tasks.clj
(undeftask test)
(deftask test #{compile}
(.bindRoot #'*stack-trace-depth* 5)
(println "Defining task: *stack-trace-depth* is" *stack-trace-depth* "in" (Thread/currentThread))
(run-project-tests))
下面產生以下輸出:
加載
test/cake_test/core.clj
:Loading tests: *stack-trace-depth* is nil in #<Thread[thread-13,5,main]>
$ cake test
Defining task: *stack-trace-depth* is 5 in #<Thread[Thread-18,5,main]> In test: *stack-trace-depth* is nil in #<Thread[Thread-16,5,main]> Testing cake-testing.core FAIL in (test-stack-trace-depth) (core.clj:8) expected: (= *stack-trace-depth* 5) actual: (not (= nil 5)) Ran 1 tests containing 1 assertions. 1 failures, 0 errors. ---- Finished in 0.011865 seconds.
(測試代碼爲on Gist)
謝謝,但似乎測試仍然沒有看到更新的值。我已經爲該問題添加了一些測試輸出。 – 2010-12-08 16:37:58
上面的新版本(在`test`任務的自定義版本中內嵌'cake.tasks.test/run-project-tests`的`* stack-trace-depth *`設置版本)似乎工作正常爲了我。現在是時候挖掘Cake來學習它爲什麼會這樣做了,因爲我似乎還沒有對代碼庫進行研究。儘管如此,它看起來很酷。感謝讓我感興趣! :-) – 2010-12-13 06:09:30