From 50300809d9f97af2fe7cf855c87643cad37d50ba Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:02:24 -0700 Subject: [PATCH] CommunitySuite: display number of states visited --- .../org/scalafmt/community/common/CommunityBuild.scala | 1 + .../scalafmt/community/common/CommunityRepoSuite.scala | 2 ++ .../org/scalafmt/community/common/CommunitySuite.scala | 8 ++++++++ .../scala/org/scalafmt/community/common/TestStats.scala | 1 + 4 files changed, 12 insertions(+) diff --git a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityBuild.scala b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityBuild.scala index bf5e3eb078..6d4516423a 100644 --- a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityBuild.scala +++ b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityBuild.scala @@ -19,6 +19,7 @@ case class CommunityBuild( styles: Set[String] = Set.empty, stylesIncluded: Boolean = true, fileOverride: Option[String] = null, + statsPerStyle: Map[String, TestStats.Style] = Map.empty, ) { private val excludedMatchers = { val fs = FileSystems.getDefault diff --git a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityRepoSuite.scala b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityRepoSuite.scala index 7c2c0bc484..0909616173 100644 --- a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityRepoSuite.scala +++ b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunityRepoSuite.scala @@ -12,6 +12,7 @@ abstract class CommunityRepoSuite(giturl: String, name: String) excluded: List[String] = Nil, fileOverride: String = null, styles: Set[String] = Set.empty, + statsPerStyle: Map[String, TestStats.Style] = Map.empty, ) = CommunityBuild( giturl, ref, @@ -21,6 +22,7 @@ abstract class CommunityRepoSuite(giturl: String, name: String) dialect, styles = styles, fileOverride = Option(fileOverride), + statsPerStyle = statsPerStyle, ) } diff --git a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunitySuite.scala b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunitySuite.scala index 6bb3c7f752..985b70e928 100644 --- a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunitySuite.scala +++ b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/CommunitySuite.scala @@ -4,6 +4,7 @@ import org.scalafmt.config._ import org.scalafmt.sysops.OsSpecific import java.nio.file._ +import java.util.concurrent.atomic.AtomicInteger import scala.collection.mutable.ListBuffer import scala.concurrent.duration @@ -35,17 +36,21 @@ abstract class CommunitySuite extends FunSuite { build: CommunityBuild, ): Unit = { val folder = fetchCommunityBuild + val atomicStatesVisited = new AtomicInteger(0) implicit val customStyle: ScalafmtConfig = style + .withCompleteCallback(x => atomicStatesVisited.getAndAdd(x.totalExplored)) val stats = checkFilesRecursive(styleName, folder.toAbsolutePath) .getOrElse(TestStats.init) val timePer1KLines = Math .round(stats.timeTaken / (stats.linesParsed / 1000.0)) + val statesVisited = atomicStatesVisited.get() println("--------------------------") println(s"${build.name} [ref=${build.commit}] [style=$styleName]") println(s"Files parsed correctly ${stats.checkedFiles - stats.errors}") println(s"Files errored: ${stats.errors}") + println(s"Total states visited: $statesVisited") println(s"Time taken: ${stats.timeTaken}ms") if (stats.linesParsed < 1000) println(s"Lines parsed: ${stats.linesParsed}") else println(s"Lines parsed: ~${stats.linesParsed / 1000}k") @@ -59,6 +64,9 @@ abstract class CommunitySuite extends FunSuite { build.checkedFiles * 2, s"expected ${stats.checkedFiles / 2} per run", ) + build.statsPerStyle.get(styleName).foreach { styleStats => + assertEquals(statesVisited, styleStats.expectedStatesVisited) + } } private def fetchCommunityBuild(implicit build: CommunityBuild): Path = { diff --git a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStats.scala b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStats.scala index 99651757e0..716720214e 100644 --- a/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStats.scala +++ b/scalafmt-tests-community/common/src/main/scala/org/scalafmt/community/common/TestStats.scala @@ -19,4 +19,5 @@ object TestStats { s1.linesParsed + s2.linesParsed, ) + case class Style(expectedStatesVisited: Int) }