Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicSuite: test Scalafmt interface class loader #4572

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}