sbt 测试编码 hickup [英] sbt test encoding hickup

查看:57
本文介绍了sbt 测试编码 hickup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个用于处理地理坐标的 Java 库,测试是在 Scala 中使用 specs2 实现的.我有许多测试对包含度数符号 °(非 ASCII 字符)的字符串进行字符串比较.

I am writing a Java library for the work with geo-coordinates and the tests are implemented with specs2 in Scala. I have many tests that do String comparisons against Strings that include the degree symbol ° (which is a non-ASCII character).

如果我在 IntelliJ 中运行这些测试,它们都会通过.他们还传递了 Travis CI.但是,如果我从我的 Power Shell (Windows x64) 运行 sbt test (sbt 11.3),所有这些测试都会失败,并且控制台会显示格式错误的字符串,如屏幕截图所示:

If I run these tests from within IntelliJ, they all pass. They also pass on Travis CI. But if I run sbt test (sbt 11.3) from my Power Shell (Windows x64), all those tests fail and the console shows malformed Strings like shown in the screen shot:

可能是什么问题,我该如何解决?我检查了这些文件是否是 UTF8 编码的.另请注意,更改我的 Java 配置不会有太大帮助,因为如果其他人克隆了存储库,则只需要运行测试(因此,仅在我的系统上解决问题的任何解决方案都无济于事).但我完全不知道这里出了什么问题...

What could be the issue, and how can I fix it? I checked that the files are UTF8-encoded. Also note that changing my Java configuration would not help much, since the tests just have to run if someone else clones the repository (so any solution that solves the problem only on my system isn't going to help). But I have absolutely no clue what is going wrong here...

推荐答案

你的度数符号是直接在源文件中编码的吗?

Are your degree symbols encoded directly in the source file?

如果是这样,我怀疑您可能有一些编码问题(可能源文件在 IntelliJ 和 CP1252 中被 SBT 编译时被解释为 UTF-8).

If so, I suspect you may have some encoding issues (possibly source files are being interpreted as UTF-8 in IntelliJ and CP1252 when compiled by SBT).

您可以尝试将度数符号更改为 '\u00B0' 并重新编译,或者您可以尝试使用 javacOptions ++= Seq("-编码", "UTF-8").

You could either try changing the degree symbols to '\u00B0' and recompiling, or alternatively you could try setting the source file encoding in SBT with javacOptions ++= Seq("-encoding", "UTF-8").

FWIW,编译器(和运行时)使用源(和其他)文件 I/O 的默认编码,除非另有说明.Windows 的默认编码是 CP1252.

FWIW, the compiler (and runtime) uses the default encoding for source (and other) file I/O, unless told otherwise. The default encoding for Windows is CP1252.

您可以告诉 javac 编译器使用带有 -encoding UTF-8 选项的替代编码,以及带有 -Dfile.encoding=UTF 的运行时-8.

You can tell the javac compiler to use an alternative encoding with the -encoding UTF-8 option, and the runtime with -Dfile.encoding=UTF-8.

通过 Google,我还找到了一些有关如何在系统范围内执行此操作的信息 此处(未经我测试).

Through Google, I also found some information on how to do this on a system-wide basis here (untested by me).

这篇关于sbt 测试编码 hickup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆