Skip to content

Commit

Permalink
Update scalafmt-core to 3.6.0 (#262)
Browse files Browse the repository at this point in the history
* Update scalafmt-core to 3.6.0

* Reformat with scalafmt 3.6.0

Executed command: scalafmt --non-interactive

* Add 'Reformat with scalafmt 3.6.0' to .git-blame-ignore-revs

Co-authored-by: Reid Spencer <[email protected]>
  • Loading branch information
scala-steward and reid-spencer authored Oct 24, 2022
1 parent 86dbf05 commit 3616f7d
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 80 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.6.0
76d587e550bf6d64686b5c688dbeccf3502f0011
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.5.9
version=3.6.0
preset = default
maxColumn = 80

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,34 @@ package com.reactific.riddl.commands
import com.reactific.riddl.language.CommonOptions
import com.reactific.riddl.language.Messages.Messages
import com.reactific.riddl.utils.Logger
import pureconfig.{ConfigCursor, ConfigReader}
import pureconfig.ConfigCursor
import pureconfig.ConfigReader
import scopt.OParser

import java.nio.file.Path

object ASimpleTestCommand {
case class Options(
command: String = "test",
arg1: String = "",
) extends CommandOptions {
arg1: String = "")
extends CommandOptions {
override def inputFile: Option[Path] = None
}
}

/** A pluggable command for testing plugin commands! */
class ASimpleTestCommand extends CommandPlugin[ASimpleTestCommand.Options]("test") {
class ASimpleTestCommand
extends CommandPlugin[ASimpleTestCommand.Options]("test") {
import ASimpleTestCommand.Options
override def getOptions: (OParser[Unit, Options], Options) = {
val builder = OParser.builder[Options]
import builder.*
OParser.sequence(
cmd("test")
.children(
arg[String]("arg1").action( (s,to)=>
to.copy(arg1 = s))
.validate { a1 =>
if (a1.nonEmpty) { Right(()) }
else { Left("All argument keys must be nonempty") }
}
)
) -> Options()
OParser.sequence(cmd("test").children(
arg[String]("arg1").action((s, to) => to.copy(arg1 = s)).validate { a1 =>
if (a1.nonEmpty) { Right(()) }
else { Left("All argument keys must be nonempty") }
}
)) -> Options()
}

override def getConfigReader: ConfigReader[Options] = { (cur: ConfigCursor) =>
Expand All @@ -49,9 +46,7 @@ class ASimpleTestCommand extends CommandPlugin[ASimpleTestCommand.Options]("test
contentObjCur <- contentCur.asObjectCursor
arg1Res <- contentObjCur.atKey("arg1")
str <- arg1Res.asString
} yield {
Options(arg1 = str)
}
} yield { Options(arg1 = str) }
}

override def run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PluginCommandTest
val (parser, default) = plugin.getOptions
OParser.parse(parser, args, default) match {
case Some(to) => to.arg1 must be("Success!")
case None => fail("No options returned from OParser.parse")
case None => fail("No options returned from OParser.parse")
}
}
"get options from config file" in {
Expand All @@ -51,7 +51,7 @@ class PluginCommandTest
ConfigSource.file(path.toFile)
.load[ASimpleTestCommand.Options](reader) match {
case Right(loadedOptions) => loadedOptions.arg1 mustBe "Success!"
case Left(failures) => fail(failures.prettyPrint())
case Left(failures) => fail(failures.prettyPrint())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ import com.reactific.riddl.translator.hugo_git_check.GitCheckCommand
import java.nio.file.Path

class GitCheckTranslatorTest
extends RunCommandOnExamplesTest[
GitCheckCommand.Options, GitCheckCommand]("git-check") {
extends RunCommandOnExamplesTest[GitCheckCommand.Options, GitCheckCommand](
"git-check"
) {

val output: String = "hugo-git-check/target/test"

def makeTranslatorOptions(fileName: String): GitCheckCommand.Options = {
val gitCloneDir = Path.of(".").toAbsolutePath.getParent
val relativeDir = Path.of(".").resolve(fileName).getParent
GitCheckCommand.Options(
Some(gitCloneDir), Some(relativeDir)
)
GitCheckCommand.Options(Some(gitCloneDir), Some(relativeDir))
}

"HugoGitCheck" should {
"run stuff when git changes" in {
runTests()
}
}
"HugoGitCheck" should { "run stuff when git changes" in { runTests() } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@

package com.reactific.riddl.language

import java.time.{Clock, Instant, ZoneId}
import java.time.Clock
import java.time.Instant
import java.time.ZoneId

/** An implementation of java.time.Clock which only moves through time via calls to `updateInstant`.
* This allows fine-grained, side-effect-free deterministic control over the progression of system
* time, which is useful for testing purposes.
*/
/** An implementation of java.time.Clock which only moves through time via calls
* to `updateInstant`. This allows fine-grained, side-effect-free deterministic
* control over the progression of system time, which is useful for testing
* purposes.
*/
final class AdjustableClock(
private var inst: Instant,
zone: ZoneId = ZoneId.of("UTC"))
extends Clock {

override def getZone: ZoneId = zone

override def withZone(zone: ZoneId): Clock = new AdjustableClock(instant(), zone)
override def withZone(zone: ZoneId): Clock =
new AdjustableClock(instant(), zone)
override def instant(): Instant = inst

/** Updates the current time of this clock to the result of applying `f` to the current time
/** Updates the current time of this clock to the result of applying `f` to
* the current time
*/
def updateInstant(f: Instant => Instant): this.type = {
this.inst = f(this.inst)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.reactific.riddl.language
import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.ast.Location
import com.reactific.riddl.language.parsing.StringParser

/** Unit Tests For CommonParser */
class CommonParserTest extends ParsingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package com.reactific.riddl.language

import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.ast.Location
import com.reactific.riddl.language.parsing.{RiddlParserInput, StringParser}
import com.reactific.riddl.language.parsing.RiddlParserInput
import com.reactific.riddl.language.parsing.StringParser
import org.scalatest.Assertion

import scala.collection.immutable.ListMap
Expand Down Expand Up @@ -133,7 +134,10 @@ class ConditionParserTest extends ParsingTest {
Comparison(
1 -> 12,
AST.eq,
ArbitraryCondition(1->15, LiteralString(1 -> 15, "sooth")),
ArbitraryCondition(
1 -> 15,
LiteralString(1 -> 15, "sooth")
),
False(1 -> 24)
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.reactific.riddl.language

import com.reactific.riddl.language.AST.Example

/** Unit Tests For Handler */
class GherkinTest extends ParsingTest {
"Gherkin" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

package com.reactific.riddl.language

import com.reactific.riddl.language.AST.{Context, Entity}
import com.reactific.riddl.language.AST.Context
import com.reactific.riddl.language.AST.Entity

/** Unit Tests For Handler */
class HandlerTest extends ParsingTest {
"Handlers" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
package com.reactific.riddl.language

import com.reactific.riddl.language.ast.Location
import com.reactific.riddl.language.parsing.{RiddlParserInput, SourceParserInput}
import com.reactific.riddl.language.parsing.RiddlParserInput
import com.reactific.riddl.language.parsing.SourceParserInput
import org.scalatest.matchers.must
import org.scalatest.wordspec.AnyWordSpec

Expand Down Expand Up @@ -51,8 +52,8 @@ class RiddlParserInputTest extends AnyWordSpec with must.Matchers {
|1234
|56
|""".stripMargin)
Map((1 -> 4) -> (0, 6), (4 -> 3) -> (13, 18)).foreach { case (loc, offset) =>
input.rangeOf(Location(loc)) mustBe offset
Map((1 -> 4) -> (0, 6), (4 -> 3) -> (13, 18)).foreach {
case (loc, offset) => input.rangeOf(Location(loc)) mustBe offset
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.reactific.riddl.language

import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.parsing.RiddlParserInput

/** Unit Tests For StreamingParser */
class StreamingParserTest extends ParsingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

package com.reactific.riddl.language

import com.reactific.riddl.language.AST.{BlockDescription, Identifier, LiteralString, Term}
import com.reactific.riddl.language.AST.BlockDescription
import com.reactific.riddl.language.AST.Identifier
import com.reactific.riddl.language.AST.LiteralString
import com.reactific.riddl.language.AST.Term
import com.reactific.riddl.language.ast.Location
class TermTest extends ParsingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

package com.reactific.riddl.language

import com.reactific.riddl.language.AST.{Field, *}
import com.reactific.riddl.language.AST.Field
import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.parsing.RiddlParserInput

/** Unit Tests For TypesParserTest */
class TypeParserTest extends ParsingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package com.reactific.riddl.language

import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.Messages.*
import com.reactific.riddl.language.parsing.{RiddlParserInput, TopLevelParser}
import com.reactific.riddl.language.parsing.RiddlParserInput
import com.reactific.riddl.language.parsing.TopLevelParser
import org.scalatest.Assertion

import java.io.File
Expand Down
5 changes: 3 additions & 2 deletions sbt-riddl/src/sbt-test/sbt-riddl/simple/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sys.props.get("plugin.version") match {
case Some(version) => addSbtPlugin("com.reactific" % "sbt-riddl" % version)
case _ => sys.error(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package com.reactific

object something {
// just here to get something to compile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ trait FileBuilder {
def nl: this.type = { sb.append(newLine); this }

override def toString: String = sb.toString
def toLines: Seq[String]= sb.toString.split(newLine).toIndexedSeq
def toLines: Seq[String] = sb.toString.split(newLine).toIndexedSeq
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ package com.reactific.riddl.utils

import java.nio.file.Path

/** Unit Tests For a plugin with a future version*/
/** Unit Tests For a plugin with a future version */

class FuturePluginSpec extends PluginSpecBase (
svcClassPath = Path.of("com/reactific/riddl/utils/FutureTestPlugin.class"),
implClassPath = Path.of("com/reactific/riddl/utils/FutureTestPlugin.class")
) {
class FuturePluginSpec
extends PluginSpecBase(
svcClassPath =
Path.of("com/reactific/riddl/utils/FutureTestPlugin.class"),
implClassPath = Path
.of("com/reactific/riddl/utils/FutureTestPlugin.class")
) {
"FuturePlugin" should {
"not load" in {

Expand Down
37 changes: 18 additions & 19 deletions utils/src/test/scala/com/reactific/riddl/utils/PluginSpecBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@ import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.must.Matchers

import java.io.PrintWriter
import java.nio.file.{Files, Path}
import java.nio.file.Files
import java.nio.file.Path
import scala.sys.process.Process

/** Base class for testing plugins */
/** Base class for testing plugins */
abstract class PluginSpecBase(
svcClassPath: Path = Path.of(
"com/reactific/riddl/utils/PluginInterface.class"),
implClassPath: Path = Path.of(
"com/reactific/riddl/utils/TestPlugin.class"),
svcClassPath: Path = Path
.of("com/reactific/riddl/utils/PluginInterface.class"),
implClassPath: Path = Path.of("com/reactific/riddl/utils/TestPlugin.class"),
moduleName: String = "utils",
jarFilename: String = "test-plugin.jar"
) extends AnyWordSpec with Matchers with BeforeAndAfterAll {
jarFilename: String = "test-plugin.jar")
extends AnyWordSpec with Matchers with BeforeAndAfterAll {

val tmpDir: Path = Files.createTempDirectory("RiddlTest")
final val providerConfigurationBasePath = Path.of("META-INF/services/")

def testClassesDir: Path =
Path.of(moduleName + s"/target/scala-${
RiddlBuildInfo.scalaCompatVersion}/test-classes/")
def testClassesDir: Path = Path.of(
moduleName +
s"/target/scala-${RiddlBuildInfo.scalaCompatVersion}/test-classes/"
)

def makeClassString(p: Path): String = {
p.toString.dropRight(".class".length).replace('/','.')
p.toString.dropRight(".class".length).replace('/', '.')
}
val svcClassStr: String = makeClassString(svcClassPath)
val implClassStr: String = makeClassString(implClassPath)

val providerRelativePath: Path =
providerConfigurationBasePath.resolve(svcClassStr)
val providerRelativePath: Path = providerConfigurationBasePath
.resolve(svcClassStr)

val providerConfigurationPath: Path =
testClassesDir.resolve(providerRelativePath).toAbsolutePath
val providerConfigurationPath: Path = testClassesDir
.resolve(providerRelativePath).toAbsolutePath

val jarFile: Path = tmpDir.resolve(jarFilename)

Expand All @@ -58,9 +59,7 @@ abstract class PluginSpecBase(
s"jar cvf ${jarFile.toAbsolutePath} $implClassPath $providerRelativePath"
val process = Process.apply(command, testClassesDir.toFile).run()
val rc = process.exitValue()
if (rc != 0) {
fail(s"'$command' failed with RC $rc != 0\n")
}
if (rc != 0) { fail(s"'$command' failed with RC $rc != 0\n") }
}
override def afterAll(): Unit = {
Files.deleteIfExists(jarFile)
Expand Down
9 changes: 4 additions & 5 deletions utils/src/test/scala/com/reactific/riddl/utils/TarSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ package com.reactific.riddl.utils
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec

import java.nio.file.{Files, Path}
import java.nio.file.Files
import java.nio.file.Path

class TarSpec extends AnyWordSpec with Matchers {

Expand All @@ -19,10 +20,8 @@ class TarSpec extends AnyWordSpec with Matchers {

val destDir = Files.createTempDirectory("TarSpec")
Tar.untar(test_tar_file, destDir) match {
case Right(filesCopied) =>
filesCopied must be(184)
case Left(message) =>
fail(message)
case Right(filesCopied) => filesCopied must be(184)
case Left(message) => fail(message)
}
}
}
Expand Down

0 comments on commit 3616f7d

Please sign in to comment.