diff --git a/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala b/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala index 4126345ac3..7c40f17fe8 100644 --- a/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala +++ b/scalafmt-dynamic/jvm/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala @@ -1,7 +1,6 @@ package org.scalafmt.dynamic -import org.scalafmt.interfaces.PositionException -import org.scalafmt.interfaces.ScalafmtReporter +import org.scalafmt.interfaces._ import java.io.ByteArrayOutputStream import java.io.PrintStream @@ -595,6 +594,14 @@ class DynamicSuite extends FunSuite { } } + test("Scalafmt interface") { + import scala.util._ + Try(Scalafmt.create(this.getClass.getClassLoader)) match { + case Success(value) => assertNotEquals(value, null) + case Failure(error) => fail(error.getMessage) + } + } + } private object DynamicSuite { diff --git a/scalafmt-dynamic/native/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala b/scalafmt-dynamic/native/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala new file mode 100644 index 0000000000..68f9062d26 --- /dev/null +++ b/scalafmt-dynamic/native/src/test/scala/org/scalafmt/dynamic/DynamicSuite.scala @@ -0,0 +1,15 @@ +package org.scalafmt.dynamic + +import org.scalafmt.interfaces._ + +import munit.FunSuite + +class DynamicSuite extends FunSuite { + + test("Scalafmt interface") { + interceptMessage[ScalafmtException] { + "Can't use different version for native CLI" + }(Scalafmt.create(this.getClass.getClassLoader)) + } + +} diff --git a/scalafmt-interfaces/native/src/main/java/org/scalafmt/interfaces/Scalafmt.scala b/scalafmt-interfaces/native/src/main/java/org/scalafmt/interfaces/Scalafmt.scala index a1c51c4a8d..f6b262638e 100644 --- a/scalafmt-interfaces/native/src/main/java/org/scalafmt/interfaces/Scalafmt.scala +++ b/scalafmt-interfaces/native/src/main/java/org/scalafmt/interfaces/Scalafmt.scala @@ -138,6 +138,8 @@ object Scalafmt { * @throws NoSuchElementException * if the classloader does not have the 'scalafmt-dynamic' module. */ - def create(loader: ClassLoader): Scalafmt = - throw new Exception("Can't use different version for native CLI") + def create(loader: ClassLoader): Scalafmt = throw new ScalafmtException( + "Can't use different version for native CLI", + null, + ) }