Skip to content

Commit

Permalink
Merge pull request #1085 from scala-steward/update/scalafmt-core-3.5.1
Browse files Browse the repository at this point in the history
Update scalafmt-core to 3.5.1
  • Loading branch information
xuwei-k authored Apr 9, 2022
2 parents 9539010 + e86ef24 commit c550e78
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.4.3
version = 3.5.1
runner.dialect = scala212

project.git = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val (_, testCallback) = compileSrcs(srcs)
val binaryDependencies = testCallback.binaryDependencies
ExtractedClassDependencies.fromPairs(
binaryDependencies.collect { case (_, bin, src, DependencyByMemberRef) => src -> bin },
binaryDependencies.collect { case (_, bin, src, DependencyByInheritance) => src -> bin },
binaryDependencies.collect { case (_, bin, src, DependencyByMemberRef) => src -> bin },
binaryDependencies.collect { case (_, bin, src, DependencyByInheritance) => src -> bin },
binaryDependencies.collect { case (_, bin, src, LocalDependencyByInheritance) => src -> bin },
)
}
Expand Down Expand Up @@ -99,7 +99,10 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
if (assertDefaultScope) for {
(className, used) <- analysisCallback.usedNamesAndScopes
analysisCallback.TestUsedName(name, scopes) <- used
} assert(scopes.size() == 1 && scopes.contains(UseScope.Default), s"$className uses $name in $scopes")
} assert(
scopes.size() == 1 && scopes.contains(UseScope.Default),
s"$className uses $name in $scopes"
)

val classesInActualSrc = analysisCallback.classNames(tempSrcFile).map(_._1)
classesInActualSrc.map(className => className -> analysisCallback.usedNames(className)).toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ class ExtractUsedNamesPerformanceSpecification

it should "be executed in reasonable time" in {
var zipfs: Option[FileSystem] = None
val src = try {
val fileUri = getClass.getResource(TestResource).toURI
zipfs = initFileSystem(fileUri)
new String(Files.readAllBytes(Paths.get(fileUri)))
} finally zipfs.foreach { fs =>
try fs.close()
catch { case _: Throwable => /*ignore*/ }
}
val src =
try {
val fileUri = getClass.getResource(TestResource).toURI
zipfs = initFileSystem(fileUri)
new String(Files.readAllBytes(Paths.get(fileUri)))
} finally zipfs.foreach { fs =>
try fs.close()
catch { case _: Throwable => /*ignore*/ }
}
import org.scalatest.time.SpanSugar._
val usedNames = failAfter(30 seconds) {
extractUsedNamesFromSrc(src)
Expand All @@ -80,7 +81,7 @@ class ExtractUsedNamesPerformanceSpecification
assert(diffAndSort(usedNames("acme.DepFn1")) === diffAndSort(expectedNamesForDepFn1))
assert(diffAndSort(usedNames("acme.HList")) === diffAndSort(expectedNamesForHList))
// Todo
//assert(
// assert(
// diffAndSort(usedNames("acme.TuplerInstances")) === diffAndSort(
// expectedNamesForTuplerInstances))
// assert(diffAndSort(usedNames("acme.$colon$colon")) === diffAndSort(`expectedNamesFor::`))
Expand All @@ -105,7 +106,9 @@ class ExtractUsedNamesPerformanceSpecification
usedNames("TuplerInstances") -- scalaDiff === expectedNamesForTuplerInstances -- scalaDiff
)
assert(
usedNames("TuplerInstances.<refinement>") -- scalaDiff === expectedNamesForTuplerInstancesRefinement -- scalaDiff
usedNames(
"TuplerInstances.<refinement>"
) -- scalaDiff === expectedNamesForTuplerInstancesRefinement -- scalaDiff
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ object ScriptedMain {
case Some(tests) if tests.isEmpty => fail(s"No tests in ${directoryPath}")
case Some(_) if target == "*" => Some(ScriptedTest(directory, target))
case Some(tests) if tests.contains(target) => Some(ScriptedTest(directory, target))
case Some(_) => fail(s"Missing test directory ${directoryPath / target}")
case None => fail(s"Missing parent directory ${directoryPath}")
case Some(_) => fail(s"Missing test directory ${directoryPath / target}")
case None => fail(s"Missing parent directory ${directoryPath}")
}
case _ => fail("Expected only one '/' in the target scripted test(s).")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private[sbt] class BatchScriptRunner extends ScriptRunner {
val state = states(handler).asInstanceOf[handler.State]
Try(handler(st.command, st.arguments, state)) match {
case Success(s) if st.successExpected => states(handler) = s
case Success(_) => throw new PreciseScriptedError(st, "Expecting error at", null)
case Success(_) => throw new PreciseScriptedError(st, "Expecting error at", null)
case Failure(t: TestFailed) if st.successExpected =>
throw new PreciseScriptedError(st, s"${t.getMessage} produced by", null)
case Failure(err) if st.successExpected =>
Expand All @@ -58,8 +58,13 @@ private[sbt] object BatchScriptRunner {

// Should be used instead of sbt.internal.scripted.TestException that doesn't show failed command
final class PreciseScriptedError(st: Statement, msg: String, e: Throwable)
extends RuntimeException({
val args = if (st.arguments.nonEmpty) st.arguments.mkString(" ", " ", "") else ""
s"${st.linePrefix}$msg: '${st.command}$args'"
}, e, false, false)
extends RuntimeException(
{
val args = if (st.arguments.nonEmpty) st.arguments.mkString(" ", " ", "") else ""
s"${st.linePrefix}$msg: '${st.command}$args'"
},
e,
false,
false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co
val (project, commandToRun) = splitCommands match {
case sub :: cmd :: Nil => buildStructure(sub) -> cmd
case cmd :: Nil => buildStructure(RootIdentifier) -> cmd
case _ => sys.error(s"The command is either empty or has more than one `/`: $command")
case _ => sys.error(s"The command is either empty or has more than one `/`: $command")
}
val runner = (ii: IncState) => commands(commandToRun)(project, arguments, ii)
Some(onIncState(state, project)(runner))
Expand Down Expand Up @@ -213,7 +213,7 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co
// and `checkRecompilations` work.
lazy val commands: Map[String, IncCommand] = Map(
noArgs("compile") { case (p, i) => p.compile(i).map(_ => ()) },
noArgs("clean") { case (p, _) => p.clean() },
noArgs("clean") { case (p, _) => p.clean() },
onArgs("checkIterations") {
case (p, x :: Nil, i) => p.checkNumberOfCompilerIterations(i, x.toInt)
},
Expand All @@ -238,9 +238,9 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co
onArgs("checkNameExistsInClass") {
case (p, cls :: name :: Nil, i) => p.checkNameExistsInClass(i, dropRightColon(cls), name)
},
noArgs("checkSame") { case (p, i) => p.checkSame(i) },
noArgs("checkSame") { case (p, i) => p.checkSame(i) },
onArgs("run") { case (p, params, i) => p.run(i, params) },
noArgs("package") { case (p, i) => p.packageBin(i) },
noArgs("package") { case (p, i) => p.packageBin(i) },
onArgs("checkWarnings") {
case (p, count :: Nil, _) => p.checkMessages(count.toInt, Severity.Warn)
},
Expand Down Expand Up @@ -573,7 +573,8 @@ case class ProjectStructure(
} else {
triggerDeps(dep)._1.map(_ => dep.output)
}
} else triggerDeps(dep)._1.map(_ => dep.output)
}
else triggerDeps(dep)._1.map(_ => dep.output)
}
val futureScalaAnalysis = earlyDeps.map { internalCp =>
blocking {
Expand Down Expand Up @@ -773,7 +774,7 @@ case class ProjectStructure(
.of()
.withPipelining(defaultPipelining)
.withApiDebug(true)
//.withRelationsDebug(true)
// .withRelationsDebug(true)
val incOptions = {
val opts = IncOptionsUtil.fromStringMap(base, map, scriptedLog)
if (opts.recompileAllFraction() != IncOptions.defaultRecompileAllFraction()) opts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,28 @@ final class ScriptedTests(
runner.initStates(states, seqHandlers)

try groupedTests.map {
case ((group, name), originalDir) =>
val label = s"$group/$name"
val loggerName = s"scripted-$group-$name.log"
val logFile = createScriptedLogFile(loggerName)
val logger = rebindLogger(batchLogger, logFile)
if (bufferLog) batchLogger.buffer.record()

batchLogger.log.info(s"Running $label")
// Copy test's contents
IO.copyDirectory(originalDir, batchTmpDir.toFile)

// Reset the state of `IncHandler` between every scripted run
runner.cleanUpHandlers(seqHandlers, states)
runner.initStates(states, seqHandlers)

// Run the test and delete files (except global that holds local scala jars)
val runTest = () => commonRunTest(label, batchTmpDir, handlers, runner, states, logger)
val result = runOrHandleDisabled(label, batchTmpDir, runTest, logger)
IO.delete(batchTmpDir.toFile.*("*" -- "global").get)
result
} finally runner.cleanUpHandlers(seqHandlers, states)
case ((group, name), originalDir) =>
val label = s"$group/$name"
val loggerName = s"scripted-$group-$name.log"
val logFile = createScriptedLogFile(loggerName)
val logger = rebindLogger(batchLogger, logFile)
if (bufferLog) batchLogger.buffer.record()

batchLogger.log.info(s"Running $label")
// Copy test's contents
IO.copyDirectory(originalDir, batchTmpDir.toFile)

// Reset the state of `IncHandler` between every scripted run
runner.cleanUpHandlers(seqHandlers, states)
runner.initStates(states, seqHandlers)

// Run the test and delete files (except global that holds local scala jars)
val runTest = () => commonRunTest(label, batchTmpDir, handlers, runner, states, logger)
val result = runOrHandleDisabled(label, batchTmpDir, runTest, logger)
IO.delete(batchTmpDir.toFile.*("*" -- "global").get)
result
}
finally runner.cleanUpHandlers(seqHandlers, states)
}

private def runOrHandleDisabled(
Expand Down
5 changes: 1 addition & 4 deletions zinc/src/test/resources/sbt/inc/Ext1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ package test.pkg
object Ext1 {
val x = 2
}
class Ext1 {

}

class Ext1 {}
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/NoopMacroUsed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ import scala.language.experimental.macros

class NoopMacroUsed {
def noop(arg: Int): Int = macro NoopMacro.noop
}
}
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/a/AA.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ package a

import jar2.Jar2

class AA(jar2: Jar2)
class AA(jar2: Jar2)
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/b/B.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

package b

class B
class B
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/b/c/C.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ package b.c

import classesDep1.ClassesDep1

class C(myDep: ClassesDep1)
class C(myDep: ClassesDep1)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ package naha

object ClientWithImplicitNotUsed {
Seq(NormalDependecy.implicitMember, NormalDependecy.standardMember, WithImplicits.standardMember)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ object ClientWithImplicitUsed {

import WithImplicits._
vals.map(add)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ package naha

object ClientWithoutImplicit {
Seq(NormalDependecy.standardMember, WithImplicits.standardMember)
}
}
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/naha/NormalDependecy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ package naha
object NormalDependecy {
def implicitMember = "implicitMemberValue"
def standardMember = "standardMemberValue"
}
}
2 changes: 1 addition & 1 deletion zinc/src/test/resources/sources/naha/Other2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ object Other2 {
def standardMember = "standardMemberValue"

val otherSealed: OtherSealed = OtherSealed2
}
}

0 comments on commit c550e78

Please sign in to comment.