私はMavenCli
を使って、ByteArrayOutpurStream
-sをstdout
とstderr
としています。 一部のレコードがこれらのストリームに書き込まれたことを確認するテストがあります。 私は1つのテストを持っている限り、すべてがOKです。 しかし、私が別のテストを導入すると、それは失敗します。何もstdoutに書き込まれないからです。私は"write something"
テスト、"write something else"
パスをコメントアウトした場合MavenCli - stdout、stderr
class MyIT extends SpecWithJUnit {
sequential
trait Ctx extends Scope {
val outStream = new ByteArrayOutpurStream()
val errStream = new ByteArrayOutpurStream()
val pomDir = Files.createTempDirectory("test_pom_").toFile
val mavenCli = new MavenCli()
def haveWrote(str: String): Matcher[Int] = {
contain(str) ^^ { (_: Int) =>
new String(outStream.toByteArray, "UTF-8") aka "written records" }
}
def maven(pom: Elem, goals: String*): Int = {
val pomFile = new File(pomDir, "pom.xml")
XML.save(pomFile.getCanonicalPath, pom)
System.setProperty(
"maven.multiModuleProjectDirectory",
pomDir.getCanonicalPath)
mavenCli.doMain(
goals.toArray,
pomDir.getCanonicalPath,
new PrintStream(outStream),
new PrintStream(errStream))
}
}
"test 1" should {
"write something" in new Ctx {
val pomXml =
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>some-artifact-id</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description>some meaningful description</description>
<name>some catchy name</name>
...
</project>
maven(pomXml, "clean" "validate") must haveWrote("something")
}
"write something else" in new Ctx {
val pomXml =
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>some-artifact-id</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description>some meaningful description</description>
<name>some catchy name</name>
... (different than the "write something" test)
</project>
maven(pomXml, "clean" "validate") must haveWrote("something else")
}
}
}
:ここ
はスニペット(スカラ)です。
私が"write something else"
をコメントアウトして("write something"
をコメント解除する)、"write something"
が合格すると、
両方ともコメントが外されて実行された場合、1つは失敗します("write something else"
、それは順次です)。
Mavenの実行後outStream
のprintln
-sを追加し、原因がoutStream
が空であることのようです...
私は回避する方法を、もっと重要なのはなぜ把握、またはすることはできません。
任意のアイデア?事前に...
おかげで、 オハッド