Use singleton env

This commit is contained in:
Timo Westkämper 2014-12-20 00:03:06 +02:00
parent fdee4f940f
commit ac9bcd64fb

View File

@ -6,9 +6,18 @@ import scala.tools.nsc._
import scala.tools.nsc.interpreter.IR.Success
import scala.io.Source.fromFile
import java.io.File
import java.io.File.pathSeparator
trait CompileTestUtils {
private object env extends Settings {
val currentLibraries = (this.getClass.getClassLoader).asInstanceOf[java.net.URLClassLoader].getURLs().toList
val cp = jarPathOfClass("scala.tools.nsc.Interpreter") :: jarPathOfClass("scala.ScalaObject") :: currentLibraries
classpath.value = cp.mkString(pathSeparator)
usejavacp.value = true
}
private def jarPathOfClass(className: String) = {
Class.forName(className).getProtectionDomain.getCodeSource.getLocation
}
@ -19,24 +28,11 @@ trait CompileTestUtils {
mkString ("\n"))
}
private lazy val env = {
import java.io.File.pathSeparator
val env = new Settings
val currentLibraries = (this.getClass.getClassLoader).asInstanceOf[java.net.URLClassLoader].getURLs().toList
val cp = jarPathOfClass("scala.tools.nsc.Interpreter") :: jarPathOfClass("scala.ScalaObject") :: currentLibraries
env.classpath.value = cp.mkString(pathSeparator)
env.usejavacp.value = true
env
}
def assertCompileSuccess(source: String): Unit = {
val out = new java.io.ByteArrayOutputStream
val interpreterWriter = new java.io.PrintWriter(out)
val interpreter = new Interpreter(env, interpreterWriter)
val interpreter = new scala.tools.nsc.interpreter.IMain(env, interpreterWriter)
try {
val result = interpreter.interpret(source.replaceAll("package", "import"))
if (result != Success) {