Skip to content

Commit

Permalink
CommunitySuite: display number of states visited
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 11, 2024
1 parent 5a47335 commit 5030080
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +22,7 @@ abstract class CommunityRepoSuite(giturl: String, name: String)
dialect,
styles = styles,
fileOverride = Option(fileOverride),
statsPerStyle = statsPerStyle,
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ object TestStats {
s1.linesParsed + s2.linesParsed,
)

case class Style(expectedStatesVisited: Int)
}

0 comments on commit 5030080

Please sign in to comment.