Skip to content

Commit

Permalink
HasTests: move scalafmtRunner() to companion
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 10, 2024
1 parent b5af71a commit b55f7d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val runner = t.style.runner
val result = Scalafmt.formatCode(
t.original,
t.style.copy(runner = scalafmtRunner(runner, debug)),
t.style.copy(runner = HasTests.scalafmtRunner(runner, debug)),
filename = t.filename,
)
debug.printTest()
Expand Down Expand Up @@ -90,7 +90,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
debug2Opt = Some(debug2)
val result2 = Scalafmt.formatCode(
obtained,
t.style.copy(runner = scalafmtRunner(runner, debug2)),
t.style.copy(runner = HasTests.scalafmtRunner(runner, debug2)),
filename = t.filename,
)
debug2.printTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ import munit.Location

trait HasTests extends FormatAssertions {
import HasTests._
import LoggerOps._

def scalafmtRunner(sr: ScalafmtRunner, dg: Debug): ScalafmtRunner = sr.copy(
debug = true,
maxStateVisits = sr.maxStateVisits.orElse(Some(150000)),
completeCallback = dg.completed,
eventCallback = {
case CreateFormatOps(ops) => dg.formatOps = ops
case Routes(routes) => dg.routes = routes
case explored: Explored if explored.n % 10000 == 0 =>
logger.elem(explored)
case Enqueue(split) => dg.enqueued(split)
case x: Written => dg.locations = x.formatLocations
case _ =>
},
)

lazy val debugResults = mutable.ArrayBuilder.make[Result]
val testDir = BuildInfo.resourceDirectory.toPath
Expand Down Expand Up @@ -275,4 +259,19 @@ object HasTests {
if (isPrefix(name, prefix)) Some(name.substring(prefix.length).trim)
else None

def scalafmtRunner(sr: ScalafmtRunner, dg: Debug): ScalafmtRunner = sr.copy(
debug = true,
maxStateVisits = sr.maxStateVisits.orElse(Some(150000)),
completeCallback = dg.completed,
eventCallback = {
case CreateFormatOps(ops) => dg.formatOps = ops
case Routes(routes) => dg.routes = routes
case explored: Explored if explored.n % 10000 == 0 =>
org.scalafmt.util.LoggerOps.logger.elem(explored)
case Enqueue(split) => dg.enqueued(split)
case x: Written => dg.locations = x.formatLocations
case _ =>
},
)

}

0 comments on commit b55f7d7

Please sign in to comment.