Unicode Clojure单元测试输出

Wil*_*Roe 6 unicode unit-testing clojure leiningen

当单元测试一些将ascii序列转换为unicode字符的代码时,我发现Clojure测试的输出存在问题.

我已经测试过我的终端可以输出unicode字符(通过捕获测试文件)并且工作正常,所以这个问题似乎与leiningen,Clojure或者clojure.test有关.

这是一个示例测试(使用unicode的希腊语部分 - 我也将使用希腊语扩展,但我认为同样的问题将适用):

(deftest bc-string-w-comma
  (is (= "???, ???" (parse "abg,*a*b*g"))))
Run Code Online (Sandbox Code Playgroud)

它意味着由于输入中缺少空间而失败.输出lein test如下:

Testing parse_perseus.test.betacode
FAIL in (bc-string-w-comma) (betacode.clj:15)
expected: (= "???, ???" (parse "abg,*a*b*g"))
  actual: (not (= "???, ???" "???,???"))
Testing parse_perseus.test.core
Testing parse_perseus.test.pluralise
Ran 10 tests containing 59 assertions.
1 failures, 0 errors.
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?这是终端仿真问题还是与clojure相关的问题?我在使用Slime/swank/emacs在REPL中运行代码时遇到同样的问题.emacs中的REPL仅输出unicode输出的问号(尽管emacs非常能够理解unicode).

我尝试在终端和iTerm(OS X)中运行此操作具有相同的结果.

Wil*_*Roe 6

事实证明,您可以将选项传递给java以强制输出编码,*out*以便unicode工作,如下所示:

java -Dfile.encoding=utf-8 -cp lib/clojure-1.2.0.jar:lib/clojure-contrib-1.2.0.jar clojure.main -i src/whatever.clj
Run Code Online (Sandbox Code Playgroud)

当我使用Leiningen时,我将此属性添加到我的project.clj文件中:

(defproject project_name "1.0.0-SNAPSHOT"
  :description "A Clojure Project"
  :dependencies [[org.clojure/clojure "1.2.0"]
                 [org.clojure/clojure-contrib "1.2.0"]]
  :dev-dependencies [[swank-clojure "1.2.0"]]
  :jvm-opts ["-Dfile.encoding=utf-8"])
Run Code Online (Sandbox Code Playgroud)