尝试使用clojurescript.test时出现空指针异常/引用错误

时间:2015-01-28 17:25:19

标签: emacs clojure clojurescript

我在使用slimerJS进行cider-REPL运行时尝试使用clojurescript.test(https://github.com/cemerick/clojurescript.test)时遇到NullPointerException。

cemerick.cljs.test.example> (ns cemerick.cljs.test.example
  (:require-macros [cemerick.cljs.test
                    :refer (is deftest with-test run-tests testing test-var)])
  (:require [cemerick.cljs.test :as t]))

java.lang.NullPointerException
nil

或者,当我尝试通过emacs,cider和austin加载部分示例测试文件(取自https://github.com/cemerick/clojurescript.test)时,我收到“未找到引用”错误。

(ns cemerick.cljs.test.example
  (:require-macros [cemerick.cljs.test
                    :refer (is deftest with-test run-tests testing test-var)])
  (:require [cemerick.cljs.test :as t]))

(deftest javascript-allows-div0
  (is (= js/Infinity (/ 1 0) (/ (int 1) (int 0)))))

用C-c加载上述内容,C-k产生上述结果:

"Error evaluating:" (deftest javascript-allows-div0 (is (= js/Infinity (/ 1 0) (/ (int 1) (int 0))))) :as "cemerick.cljs.test.example.javascript_allows_div0 = (function javascript_allows_div0(){\r\nreturn cemerick.cljs.test.test_function.call(null,cemerick.cljs.test.init_test_environment.call(null),cemerick.cljs.test.example.javascript_allows_div0);\r\n});\r\n\r\ncemerick.cljs.test.example.javascript_allows_div0 = cljs.core.with_meta.call(null,cemerick.cljs.test.example.javascript_allows_div0,cljs.core.merge.call(null,new cljs.core.PersistentArrayMap(null, 5, [new cljs.core.Keyword(null,\"end-column\",\"end-column\",1425389514),33,new cljs.core.Keyword(null,\"end-line\",\"end-line\",1837326455),9,new cljs.core.Keyword(null,\"column\",\"column\",2078222095),10,new cljs.core.Keyword(null,\"line\",\"line\",212345235),9,new cljs.core.Keyword(null,\"file\",\"file\",-1269645878),\"c:/Users/Vincent/hello-browser/test/hello_browser/example.cljs\"], null),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keywor
d(null,\"name\",\"name\",1843675177),cljs.core.with_meta.call(null,new cljs.core.Symbol(\"cemerick.cljs.test.example\",\"javascript-allows-div0\",\"cemerick.cljs.test.example/javascript-allows-div0\",254759648,null),new cljs.core.PersistentArrayMap(null, 5, [new cljs.core.Keyword(null,\"end-column\",\"end-column\",1425389514),33,new cljs.core.Keyword(null,\"end-line\",\"end-line\",1837326455),9,new cljs.core.Keyword(null,\"column\",\"column\",2078222095),10,new cljs.core.Keyword(null,\"line\",\"line\",212345235),9,new cljs.core.Keyword(null,\"file\",\"file\",-1269645878),\"c:/Users/Vincent/hello-browser/test/hello_browser/example.cljs\"], null)),new cljs.core.Keyword(null,\"test\",\"test\",577538877),(function javascript_allows_div0_test(test_ctx__15319__auto__){\r\nvar _test_ctx = test_ctx__15319__auto__;\r\nvar async_QMARK___15234__auto__ = new cljs.core.Keyword(null,\"async\",\"async\",1050769601).cljs$core$IFn$_invoke$arity$1(cljs.core.meta.call(null,new cljs.core.Keyword(null,\"test-name\",\"test-name\",
-675595913).cljs$core$IFn$_invoke$arity$1(_test_ctx)));\r\nvar _STAR_test_ctx_STAR_15568 = cemerick.cljs.test._STAR_test_ctx_STAR_;\r\ntry{cemerick.cljs.test._STAR_test_ctx_STAR_ = (cljs.core.truth_(async_QMARK___15234__auto__)?null:_test_ctx);\r\n\r\ntry{var _test_ctx__$1 = _test_ctx;\r\nvar async_QMARK___15234__auto____$1 = new cljs.core.Keyword(null,\"async\",\"async\",1050769601).cljs$core$IFn$_invoke$arity$1(cljs.core.meta.call(null,new cljs.core.Keyword(null,\"test-name\",\"test-name\",-675595913).cljs$core$IFn$_invoke$arity$1(_test_ctx__$1)));\r\nvar _STAR_test_ctx_STAR_15570 = cemerick.cljs.test._STAR_test_ctx_STAR_;\r\ntry{cemerick.cljs.test._STAR_test_ctx_STAR_ = (cljs.core.truth_(async_QMARK___15234__auto____$1)?null:_test_ctx__$1);\r\n\r\ntry{try{var values__15254__auto__ = cljs.core._conj.call(null,cljs.core._conj.call(null,cljs.core._conj.call(null,cljs.core.List.EMPTY,(((1) | (0)) / ((0) | (0)))),((1) / (0))),Infinity);\r\nvar result__15255__auto__ = cljs.core.apply.call(null,cljs.core._EQ_,val
ues__15254__auto__);\r\nif((result__15255__auto__ instanceof cemerick.cljs.test.TestContext)){\r\nthrow (new Error(\"TestContext provided as [form] in `is` assertion. If using `is` with an explicit test context, use the 3-arg arity.\"));\r\n} else {\r\n}\r\n\r\nif(cljs.core.truth_(result__15255__auto__)){\r\ncemerick.cljs.test.do_report.call(null,_test_ctx__$1,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,\"type\",\"type\",1174270348),new cljs.core.Keyword(null,\"pass\",\"pass\",1574159993),new cljs.core.Keyword(null,\"expected\",\"expected\",1583670997),cljs.core.list(new cljs.core.Symbol(null,\"=\",\"=\",-1501502141,null),new cljs.core.Symbol(\"js\",\"Infinity\",\"js/Infinity\",2039810812,null),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null),(1),(0)),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null),cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885395,null),(1)),cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885
395,null),(0)))),new cljs.core.Keyword(null,\"actual\",\"actual\",107306363),cljs.core.cons.call(null,cljs.core._EQ_,values__15254__auto__),new cljs.core.Keyword(null,\"message\",\"message\",-406056002),null], null));\r\n} else {\r\ncemerick.cljs.test.do_report.call(null,_test_ctx__$1,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,\"type\",\"type\",1174270348),new cljs.core.Keyword(null,\"fail\",\"fail\",1706214930),new cljs.core.Keyword(null,\"expected\",\"expected\",1583670997),cljs.core.list(new cljs.core.Symbol(null,\"=\",\"=\",-1501502141,null),new cljs.core.Symbol(\"js\",\"Infinity\",\"js/Infinity\",2039810812,null),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null),(1),(0)),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null),cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885395,null),(1)),cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885395,null),(0)))),new cljs.core.Keyword(null,\"actual\",\"actual\",107306363),
cljs.core._conj.call(null,cljs.core._conj.call(null,cljs.core.List.EMPTY,cljs.core.cons.call(null,new cljs.core.Symbol(null,\"=\",\"=\",-1501502141,null),values__15254__auto__)),new cljs.core.Symbol(null,\"not\",\"not\",1044554643,null)),new cljs.core.Keyword(null,\"message\",\"message\",-406056002),null], null));\r\n}\r\n\r\nreturn result__15255__auto__;\r\n}catch (e15572){if((e15572 instanceof Error)){\r\nvar t__15291__auto__ = e15572;\r\nreturn cemerick.cljs.test.do_report.call(null,_test_ctx__$1,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,\"type\",\"type\",1174270348),new cljs.core.Keyword(null,\"error\",\"error\",-978969032),new cljs.core.Keyword(null,\"expected\",\"expected\",1583670997),cljs.core.list(new cljs.core.Symbol(null,\"=\",\"=\",-1501502141,null),new cljs.core.Symbol(\"js\",\"Infinity\",\"js/Infinity\",2039810812,null),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null),(1),(0)),cljs.core.list(new cljs.core.Symbol(null,\"/\",\"/\",-1371932971,null)
,cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885395,null),(1)),cljs.core.list(new cljs.core.Symbol(null,\"int\",\"int\",-100885395,null),(0)))),new cljs.core.Keyword(null,\"actual\",\"actual\",107306363),t__15291__auto__,new cljs.core.Keyword(null,\"message\",\"message\",-406056002),null], null));\r\n} else {\r\nthrow e15572;\r\n\r\n}\r\n}}catch (e15571){if((e15571 instanceof Error)){\r\nvar e__15235__auto__ = e15571;\r\nif(cljs.core.truth_(async_QMARK___15234__auto____$1)){\r\nreturn cemerick.cljs.test.done_STAR_.call(null,_test_ctx__$1,e__15235__auto__);\r\n} else {\r\nthrow e__15235__auto__;\r\n}\r\n} else {\r\nthrow e15571;\r\n\r\n}\r\n}}finally {cemerick.cljs.test._STAR_test_ctx_STAR_ = _STAR_test_ctx_STAR_15570;\r\n}}catch (e15569){if((e15569 instanceof Error)){\r\nvar e__15235__auto__ = e15569;\r\nif(cljs.core.truth_(async_QMARK___15234__auto__)){\r\nreturn cemerick.cljs.test.done_STAR_.call(null,_test_ctx,e__15235__auto__);\r\n} else {\r\nthrow e__15235__auto__;\r\n}\r\n} else {\r\nth
row e15569;\r\n\r\n}\r\n}}finally {cemerick.cljs.test._STAR_test_ctx_STAR_ = _STAR_test_ctx_STAR_15568;\r\n}})], null)));\r\n\r\ncemerick.cljs.test.register_test_BANG_.call(null,new cljs.core.Symbol(null,\"cemerick.cljs.test.example\",\"cemerick.cljs.test.example\",-1897716079,null),new cljs.core.Symbol(\"cemerick.cljs.test.example\",\"javascript-allows-div0\",\"cemerick.cljs.test.example/javascript-allows-div0\",254759648,null),cemerick.cljs.test.example.javascript_allows_div0);\r\n\r\n"

#<ReferenceError: cemerick is not defined>

@http://localhost:52963/2397/repl/start line 1944 > eval:1:1
clojure.browser.repl.evaluate_javascript/c<@http://localhost:52963/2397/repl/start:1944:313
clojure.browser.repl.evaluate_javascript@http://localhost:52963/2397/repl/start:1944:62
clojure.browser.repl.connect/<@http://localhost:52963/2397/repl/start:1953:1
goog.messaging.AbstractChannel.prototype.deliver@http://localhost:52963/2397/repl/start:1761:268
goog.net.xpc.CrossPageChannel.prototype.xpcDeliver@http://localhost:52963/2397/repl/start:1914:354
goog.net.xpc.NativeMessagingTransport.messageReceived_@http://localhost:52963/2397/repl/start:1870:396
goog.events.fireListener@http://localhost:52963/2397/repl/start:1454:124
goog.events.handleBrowserEvent_@http://localhost:52963/2397/repl/start:1457:174
goog.events.getProxy/b<@http://localhost:52963/2397/repl/start:1446:395

我的project.clj文件如下:

(defproject hello-browser "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/clojurescript "0.0-2665"]]
  :plugins [[lein-cljsbuild "1.0.4"]            
            [cider/cider-nrepl "0.9.0-SNAPSHOT" ]
            [com.cemerick/clojurescript.test "0.3.3"]]
  :source-paths ["src" "src/cljs"]
  :test-paths ["test" "test/hello_browser"]
  :cljsbuild { :builds [{:source-paths ["src/cljs"]                         
                         :compiler {:output-to "resources/public/core.js"}}]}
  :profiles {:dev {:plugins [[com.cemerick/austin "0.1.6"]]}})

我做错了什么?

1 个答案:

答案 0 :(得分:0)

更新clojurescript版本似乎解决了我的问题。所以改变之后

[org.clojure/clojurescript "0.0-2665"] 

[org.clojure/clojurescript "0.0-2740"]

将上面的测试文件加载到带有C-c,C-k的REPL中

(cemerick.cljs.test/test-ns 'cemerick.cljs.test.example) 

产生了

的预期输出
{:test 1, :pass 1, :fail 0, :error 0}