Skip to content

Commit

Permalink
LeftPad testForkGrouping sub-keys to ensure they're probably sortable…
Browse files Browse the repository at this point in the history
… and greppable (#3653)
  • Loading branch information
lihaoyi authored Oct 3, 2024
1 parent d85dd40 commit c8eddd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 5 additions & 6 deletions main/eval/src/mill/eval/EvaluatorCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
for (terminal <- terminals) {
val deps = interGroupDeps(terminal)
futures(terminal) = Future.sequence(deps.map(futures)).map { upstreamValues =>
val countMsg = count
.getAndIncrement()
.toString
.reverse
.padTo(terminals.size.toString.length, '0')
.reverse
val countMsg = mill.util.Util.leftPad(
count.getAndIncrement().toString,
terminals.length.toString.length,
'0'
)

val verboseKeySuffix = s"/${terminals0.size}"
logger.setPromptLeftHeader(s"$countMsg$verboseKeySuffix")
Expand Down
4 changes: 4 additions & 0 deletions main/util/src/mill/util/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ object Util {
def millProperty(key: String): Option[String] =
Option(sys.props(key)) // System property has priority
.orElse(Option(LongMillProps.getProperty(key)))

def leftPad(s: String, targetLength: Int, char: Char): String = {
char.toString * (targetLength - s.length) + s
}
}
7 changes: 5 additions & 2 deletions scalalib/src/mill/scalalib/TestModuleUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,22 @@ private[scalalib] object TestModuleUtil {
case Nil => runTestRunnerSubprocess(Nil, T.dest)
case Seq(singleTestClassList) => runTestRunnerSubprocess(singleTestClassList, T.dest)
case multipleTestClassLists =>
val maxLength = multipleTestClassLists.length.toString.length
val futures = multipleTestClassLists.zipWithIndex.map { case (testClassList, i) =>
val groupPromptMessage = testClassList match {
case Seq(single) => single
case multiple =>
collapseTestClassNames(multiple).mkString(", ") + s", ${multiple.length} suites"
}

val paddedIndex = mill.util.Util.leftPad(i.toString, maxLength, '0')
val folderName = testClassList match {
case Seq(single) => single
case multiple => s"group-$i-${multiple.head}"
case multiple =>
s"group-$paddedIndex-${multiple.head}"
}

T.fork.async(T.dest / folderName, "" + i, groupPromptMessage) {
T.fork.async(T.dest / folderName, paddedIndex, groupPromptMessage) {
(folderName, runTestRunnerSubprocess(testClassList, T.dest / folderName))
}
}
Expand Down

0 comments on commit c8eddd7

Please sign in to comment.