2019-02-22 23:48:37 +01:00
|
|
|
package example.test
|
|
|
|
|
|
|
|
|
|
import minitest._
|
|
|
|
|
import scala.sys.process._
|
|
|
|
|
import java.io.File
|
|
|
|
|
|
|
|
|
|
object SbtRunnerTest extends SimpleTestSuite with PowerAssertions {
|
2019-09-23 07:25:35 +02:00
|
|
|
// 1.3.0, 1.3.0-M4
|
|
|
|
|
private val versionRegEx = "\\d(\\.\\d+){2}(-\\w+)?"
|
|
|
|
|
|
2019-07-16 01:23:58 +02:00
|
|
|
lazy val isWindows: Boolean = sys.props("os.name").toLowerCase(java.util.Locale.ENGLISH).contains("windows")
|
|
|
|
|
lazy val sbtScript =
|
|
|
|
|
if (isWindows) new File("target/universal/stage/bin/sbt.bat")
|
|
|
|
|
else new File("target/universal/stage/bin/sbt")
|
2019-09-23 07:25:35 +02:00
|
|
|
|
2019-12-28 08:36:53 +01:00
|
|
|
def sbtProcess(args: String*) = sbtProcessWithOpts(args: _*)("", "")
|
|
|
|
|
def sbtProcessWithOpts(args: String*)(javaOpts: String, sbtOpts: String) =
|
|
|
|
|
sbt.internal.Process(Seq(sbtScript.getAbsolutePath) ++ args, new File("citest"),
|
2019-05-09 06:28:14 +02:00
|
|
|
"JAVA_OPTS" -> javaOpts,
|
|
|
|
|
"SBT_OPTS" -> sbtOpts)
|
2019-02-22 23:48:37 +01:00
|
|
|
|
|
|
|
|
test("sbt runs") {
|
|
|
|
|
assert(sbtScript.exists)
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "-v").!
|
2019-02-22 23:48:37 +01:00
|
|
|
assert(out == 0)
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt -no-colors") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "-no-colors", "-v").!!.linesIterator.toList
|
2019-02-22 23:48:37 +01:00
|
|
|
assert(out.contains[String]("-Dsbt.log.noformat=true"))
|
|
|
|
|
()
|
|
|
|
|
}
|
2019-02-23 04:31:58 +01:00
|
|
|
|
2019-04-05 16:20:52 +02:00
|
|
|
test("sbt --no-colors") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "--no-colors", "-v").!!.linesIterator.toList
|
2019-04-05 16:20:52 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.log.noformat=true"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 17:30:59 +02:00
|
|
|
test("sbt --color=false") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "--color=false", "-v").!!.linesIterator.toList
|
2019-04-05 17:30:59 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.color=false"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 19:42:17 +02:00
|
|
|
test("sbt --debug-inc") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "--debug-inc", "-v").!!.linesIterator.toList
|
2019-10-10 19:42:17 +02:00
|
|
|
assert(out.contains[String]("-Dxsbt.inc.debug=true"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 17:30:59 +02:00
|
|
|
test("sbt --supershell=never") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "--supershell=never", "-v").!!.linesIterator.toList
|
2019-04-05 17:30:59 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.supershell=never"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt --timings") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "--timings", "-v").!!.linesIterator.toList
|
2019-04-05 17:30:59 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.task.timings=true"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-16 15:23:30 +02:00
|
|
|
test("sbt -D arguments") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("-Dsbt.supershell=false", "compile", "-v").!!.linesIterator.toList
|
2019-10-16 15:23:30 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.supershell=false"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-14 07:36:30 +02:00
|
|
|
test("sbt --sbt-version") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("--sbt-version", "1.3.0", "compile", "-v").!!.linesIterator.toList
|
2019-09-14 07:36:30 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.version=1.3.0"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 04:31:58 +01:00
|
|
|
test("sbt -mem 503") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "-mem", "503", "-v").!!.linesIterator.toList
|
2019-02-23 04:31:58 +01:00
|
|
|
assert(out.contains[String]("-Xmx503m"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 07:25:35 +02:00
|
|
|
test("sbt with -mem 503, -Xmx in JAVA_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("-Xmx1024m", "").!!.linesIterator.toList
|
2019-02-23 04:31:58 +01:00
|
|
|
assert(out.contains[String]("-Xmx503m"))
|
2019-09-23 07:25:35 +02:00
|
|
|
assert(!out.contains[String]("-Xmx1024m"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt with -mem 503, -Xmx in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-mem", "503", "-v")("", "-Xmx1024m").!!.linesIterator.toList
|
2019-09-23 07:25:35 +02:00
|
|
|
assert(out.contains[String]("-Xmx503m"))
|
|
|
|
|
assert(!out.contains[String]("-Xmx1024m"))
|
2019-02-23 04:31:58 +01:00
|
|
|
()
|
|
|
|
|
}
|
2019-05-09 06:28:14 +02:00
|
|
|
|
|
|
|
|
test("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "-Xms2048M -Xmx2048M -Xss6M").!!.linesIterator.toList
|
2019-05-09 06:28:14 +02:00
|
|
|
assert(out.contains[String]("-Xss6M"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 15:44:13 +01:00
|
|
|
test("sbt with -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080").!!.linesIterator.toList
|
2019-11-09 15:44:13 +01:00
|
|
|
assert(out.contains[String]("-Dhttp.proxyHost=proxy"))
|
|
|
|
|
assert(out.contains[String]("-Dhttp.proxyPort=8080"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt with -XX:ParallelGCThreads=16 -XX:PermSize=128M in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "-XX:ParallelGCThreads=16 -XX:PermSize=128M").!!.linesIterator.toList
|
2019-11-09 15:44:13 +01:00
|
|
|
assert(out.contains[String]("-XX:ParallelGCThreads=16"))
|
|
|
|
|
assert(out.contains[String]("-XX:PermSize=128M"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 03:56:10 +01:00
|
|
|
test("sbt with -XX:+UseG1GC -XX:+PrintGC in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "-XX:+UseG1GC -XX:+PrintGC").!!.linesIterator.toList
|
2019-11-11 03:56:10 +01:00
|
|
|
assert(out.contains[String]("-XX:+UseG1GC"))
|
|
|
|
|
assert(out.contains[String]("-XX:+PrintGC"))
|
|
|
|
|
assert(!out.contains[String]("-XX:+UseG1GC=-XX:+PrintGC"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt with -XX:-UseG1GC -XX:-PrintGC in SBT_OPTS") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "-XX:-UseG1GC -XX:-PrintGC").!!.linesIterator.toList
|
2019-11-11 03:56:10 +01:00
|
|
|
assert(out.contains[String]("-XX:-UseG1GC"))
|
|
|
|
|
assert(out.contains[String]("-XX:-PrintGC"))
|
|
|
|
|
assert(!out.contains[String]("-XX:-UseG1GC=-XX:-PrintGC"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-09 06:28:14 +02:00
|
|
|
test("sbt with --no-colors in SBT_OPTS") {
|
2019-09-23 07:25:35 +02:00
|
|
|
if (isWindows) cancel("Test not supported on windows")
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcessWithOpts("compile", "-v")("", "--no-colors").!!.linesIterator.toList
|
2019-05-09 06:28:14 +02:00
|
|
|
assert(out.contains[String]("-Dsbt.log.noformat=true"))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 19:23:48 +02:00
|
|
|
test("sbt -V|-version|--version should print sbtVersion") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("-version").!!.trim
|
2019-09-23 19:23:48 +02:00
|
|
|
val expectedVersion =
|
2019-10-20 06:01:03 +02:00
|
|
|
s"""|(?m)^sbt version in this project: $versionRegEx(\\r)?
|
2019-09-23 07:25:35 +02:00
|
|
|
|sbt script version: $versionRegEx$$
|
|
|
|
|
|""".stripMargin.trim.replace("\n", "\\n")
|
2019-07-19 01:32:41 +02:00
|
|
|
assert(out.matches(expectedVersion))
|
|
|
|
|
|
2019-12-28 08:36:53 +01:00
|
|
|
val out2 = sbtProcess("--version").!!.trim
|
2019-07-19 01:32:41 +02:00
|
|
|
assert(out2.matches(expectedVersion))
|
2019-09-23 19:23:48 +02:00
|
|
|
|
2019-12-28 08:36:53 +01:00
|
|
|
val out3 = sbtProcess("-V").!!.trim
|
2019-09-23 19:23:48 +02:00
|
|
|
assert(out3.matches(expectedVersion))
|
2019-07-19 01:32:41 +02:00
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 19:23:48 +02:00
|
|
|
test("sbt --numeric-version should print sbt script version") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("--numeric-version").!!.trim
|
2019-09-23 19:23:48 +02:00
|
|
|
val expectedVersion = "^"+versionRegEx+"$"
|
|
|
|
|
assert(out.matches(expectedVersion))
|
|
|
|
|
()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test("sbt --script-version should print sbtVersion") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("--script-version").!!.trim
|
2019-09-23 19:23:48 +02:00
|
|
|
val expectedVersion = "^"+versionRegEx+"$"
|
|
|
|
|
assert(out.matches(expectedVersion))
|
|
|
|
|
()
|
|
|
|
|
}
|
2019-10-20 04:05:06 +02:00
|
|
|
|
|
|
|
|
test("sbt --sbt-jar should run") {
|
2019-12-28 08:36:53 +01:00
|
|
|
val out = sbtProcess("compile", "-v", "--sbt-jar", "../target/universal/stage/bin/sbt-launch.jar").!!.linesIterator.toList
|
2019-10-20 04:05:06 +02:00
|
|
|
assert(out.contains[String]("../target/universal/stage/bin/sbt-launch.jar") ||
|
|
|
|
|
out.contains[String]("\"../target/universal/stage/bin/sbt-launch.jar\"")
|
|
|
|
|
)
|
|
|
|
|
()
|
|
|
|
|
}
|
2019-12-28 08:37:14 +01:00
|
|
|
|
|
|
|
|
test("sbt \"testOnly *\"") {
|
|
|
|
|
val out = sbtProcess("testOnly *", "--no-colors", "-v").!!.linesIterator.toList
|
|
|
|
|
assert(out.contains[String]("[info] HelloTest"))
|
|
|
|
|
()
|
|
|
|
|
}
|
2019-02-22 23:48:37 +01:00
|
|
|
}
|