Skip to content

Commit

Permalink
DynamicSuite: test Scalafmt interface class loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 20, 2024
1 parent 3ee6a7c commit a29aa8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

0 comments on commit a29aa8a

Please sign in to comment.