summaryrefslogtreecommitdiff
path: root/src/partest/scala/tools/partest/package.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/partest/scala/tools/partest/package.scala')
-rw-r--r--src/partest/scala/tools/partest/package.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala
index 9e21b0f6ba..0b169c767a 100644
--- a/src/partest/scala/tools/partest/package.scala
+++ b/src/partest/scala/tools/partest/package.scala
@@ -31,6 +31,8 @@ package object partest {
def ojoin(xs: String*): String = oempty(xs: _*) mkString space
def nljoin(xs: String*): String = oempty(xs: _*) mkString EOL
+ implicit val codec = scala.io.Codec.UTF8
+
def setUncaughtHandler() = {
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler {
@@ -85,6 +87,18 @@ package object partest {
def copyTo(dest: Path): Unit = dest.toFile writeAll f.slurp(scala.io.Codec.UTF8)
}
+ implicit class LoaderOps(val loader: ClassLoader) extends AnyVal {
+ import scala.util.control.Exception.catching
+ /** Like ScalaClassLoader.create for the case where the result type is
+ * available to the current class loader, implying that the current
+ * loader is a parent of `loader`.
+ */
+ def instantiate[A >: Null](name: String): A = (
+ catching(classOf[ClassNotFoundException], classOf[SecurityException]) opt
+ (loader loadClass name).newInstance.asInstanceOf[A] orNull
+ )
+ }
+
implicit def temporaryPath2File(x: Path): File = x.jfile
implicit def stringPathToJavaFile(path: String): File = new File(path)