Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.7.6 #977

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ b8564609df3c849b3a258a411e0de645d4e8c7a0
# Code formatting (PR: #950)
ccd98e22a078e1282dbb2c1acfb40fe3afee01b6


# Scala Steward: Reformat with scalafmt 3.7.6
79da8216cac0c6ec8b2d6340c1980674fdd273aa
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.7.4
version=3.7.6
maxColumn = 120
assumeStandardLibraryStripMargin = true

Expand Down
24 changes: 10 additions & 14 deletions examples/commands-leveldb/src/test/scala/CommandsLevelDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.fusesource.leveldbjni.JniDBFactory._
import scala.util.{Try, Success}
import scala.collection.immutable.Map


object CommandsLevelDB extends org.scalacheck.Properties("CommandsLevelDB") {

property("leveldbspec") = LevelDBSpec.property()
Expand All @@ -18,28 +17,26 @@ object CommandsLevelDB extends org.scalacheck.Properties("CommandsLevelDB") {
object LevelDBSpec extends Commands {

case class State(
open: Boolean,
name: String,
contents: Map[List[Byte],List[Byte]]
open: Boolean,
name: String,
contents: Map[List[Byte], List[Byte]]
)

case class Sut(
var name: String,
var db: DB
var name: String,
var db: DB
) {
def path = s"db_$name"
}

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
) = {
def canCreateNewSut(newState: State, initSuts: Traversable[State], runningSuts: Traversable[Sut]) = {
!initSuts.exists(_.name == newState.name) &&
!runningSuts.exists(_.name == newState.name)
}

def newSut(state: State): Sut = Sut(state.name, null)

def destroySut(sut: Sut) = if(sut.db != null) sut.db.close
def destroySut(sut: Sut) = if (sut.db != null) sut.db.close

def initialPreCondition(state: State) = !state.open

Expand All @@ -57,13 +54,12 @@ object LevelDBSpec extends Commands {
genGetExisting(state)
)

val genPut: Gen[Put] = Gen.resultOf(Put(_,_))
val genPut: Gen[Put] = Gen.resultOf(Put(_, _))

def genPutExisting(state: State): Gen[Put] = for {
key <- Gen.oneOf(state.contents.keys.toSeq)
value <- Gen.oneOf(arbitrary[List[Byte]],
Gen.const(state.contents(key)))
} yield Put(key,value)
value <- Gen.oneOf(arbitrary[List[Byte]], Gen.const(state.contents(key)))
} yield Put(key, value)

val genGet: Gen[Get] = Gen.resultOf(Get(_))

Expand Down
52 changes: 25 additions & 27 deletions examples/commands-nix/src/test/scala/CommandsNix.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.scalacheck.Gen
import org.scalacheck.commands.Commands

import util.{Try,Success,Failure}
import util.{Try, Success, Failure}

object CommandsNix extends org.scalacheck.Properties("CommandsNix") {

Expand All @@ -13,14 +13,14 @@ object MachineSpec extends Commands {

val con = new org.libvirt.Connect("qemu:///session")

def runSshCmd(ip: String, cmd: String): Either[String,String] = {
def runSshCmd(ip: String, cmd: String): Either[String, String] = {
import scala.sys.process._
val err = new StringBuffer()
val logger = ProcessLogger(err.append(_))

val sshcmd =
s"ssh -q -i test-key_rsa -l root -o UserKnownHostsFile=/dev/null " +
s"-o StrictHostKeyChecking=no -o ConnectTimeout=1 ${ip}"
s"-o StrictHostKeyChecking=no -o ConnectTimeout=1 ${ip}"

if (s"$sshcmd true" ! logger != 0)
throw new Exception(err.toString)
Expand Down Expand Up @@ -55,10 +55,10 @@ object MachineSpec extends Commands {
prefixLength = 24;
};
boot.kernelPackages =
pkgs.linuxPackages_${m.kernelVer.replace('.','_')};
pkgs.linuxPackages_${m.kernelVer.replace('.', '_')};
"""

def toLibvirtXMLs(machines: State): Map[String,String] = {
def toLibvirtXMLs(machines: State): Map[String, String] = {
import scala.sys.process._
import java.io.ByteArrayInputStream

Expand All @@ -74,23 +74,23 @@ object MachineSpec extends Commands {

// Check that all expected output files can be read
xmlFiles.values foreach { f =>
if(!(new java.io.File(f)).canRead) throw new Exception(raw"""
if (!(new java.io.File(f)).canRead) throw new Exception(raw"""
No Libvirt XML produced (${f})
out = ${out.toString}
err = ${err.toString}
""")
}

xmlFiles map { case (id,f) => id -> io.Source.fromFile(f).mkString }
xmlFiles map { case (id, f) => id -> io.Source.fromFile(f).mkString }
}

case class Machine (
id: String,
uuid: java.util.UUID,
ip: String,
kernelVer: String,
memory: Int,
running: Boolean
case class Machine(
id: String,
uuid: java.util.UUID,
ip: String,
kernelVer: String,
memory: Int,
running: Boolean
)

// Machine.id mapped to a machine state
Expand All @@ -100,12 +100,10 @@ object MachineSpec extends Commands {
type Sut = Map[String, org.libvirt.Domain]

// TODO we should check for example total amount of memory used here
def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
): Boolean = true
def canCreateNewSut(newState: State, initSuts: Traversable[State], runningSuts: Traversable[Sut]): Boolean = true

def newSut(state: State): Sut = {
toLibvirtXMLs(state) map { case (id,xml) => id -> con.domainDefineXML(xml) }
toLibvirtXMLs(state) map { case (id, xml) => id -> con.domainDefineXML(xml) }
}

def destroySut(sut: Sut) = sut.values foreach { d =>
Expand All @@ -121,22 +119,22 @@ object MachineSpec extends Commands {

// generate a 10.x.y subnet
val genSubnet: Gen[List[Int]] = for {
x <- Gen.choose(0,255)
y <- Gen.choose(0,255)
} yield List(10,x,y)
x <- Gen.choose(0, 255)
y <- Gen.choose(0, 255)
} yield List(10, x, y)

def hasDuplicates(xs: Seq[Any]): Boolean = xs.distinct.length != xs.length

def genMachine(id: String, subnet: List[Int]): Gen[Machine] = for {
uuid <- Gen.uuid
//ip <- Gen.choose(2,254).map(n => (subnet :+ n).mkString("."))
ip <- Gen.choose(2,254).map(n => s"172.16.2.$n")
// ip <- Gen.choose(2,254).map(n => (subnet :+ n).mkString("."))
ip <- Gen.choose(2, 254).map(n => s"172.16.2.$n")
memory <- Gen.choose(96, 256)
kernel <- Gen.oneOf("3.14", "3.13", "3.12", "3.10")
} yield Machine (id, uuid, ip, kernel, memory, false)
} yield Machine(id, uuid, ip, kernel, memory, false)

val genInitialState: Gen[State] = for {
machineCount <- Gen.choose(5,5)
machineCount <- Gen.choose(5, 5)
idGen = Gen.listOfN(8, Gen.alphaLowerChar).map(_.mkString)
ids <- Gen.listOfN(machineCount, idGen)
subnet <- genSubnet
Expand All @@ -162,8 +160,8 @@ object MachineSpec extends Commands {
)

def genCommand(state: State): Gen[Command] =
if(state.forall(!_.running)) genBoot(state)
else if(state.forall(_.running)) Gen.frequency(
if (state.forall(!_.running)) genBoot(state)
else if (state.forall(_.running)) Gen.frequency(
(1, genShutdown(state)),
(4, genPingOnline(state))
)
Expand Down
44 changes: 21 additions & 23 deletions examples/commands-redis/src/test/scala/CommandsRedis.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.scalacheck.Gen
import org.scalacheck.Gen.{someOf, oneOf, const, nonEmptyListOf,
identifier, frequency}
import org.scalacheck.Gen.{someOf, oneOf, const, nonEmptyListOf, identifier, frequency}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.commands.Commands

Expand All @@ -10,7 +9,6 @@ import scala.collection.Seq

import com.redis.RedisClient


object CommandsRedis extends org.scalacheck.Properties("CommandsRedis") {

property("redisspec") = RedisSpec.property()
Expand All @@ -21,15 +19,13 @@ object RedisSpec extends Commands {

type Sut = RedisClient

case class State (
contents: collection.immutable.Map[String,String],
deleted: collection.immutable.Set[String],
connected: Boolean
case class State(
contents: collection.immutable.Map[String, String],
deleted: collection.immutable.Set[String],
connected: Boolean
)

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
): Boolean = {
def canCreateNewSut(newState: State, initSuts: Traversable[State], runningSuts: Traversable[Sut]): Boolean = {
initSuts.isEmpty && runningSuts.isEmpty
}

Expand All @@ -55,7 +51,7 @@ object RedisSpec extends Commands {
)

def genCommand(state: State): Gen[Command] = {
if(!state.connected) ToggleConnected
if (!state.connected) ToggleConnected
else
frequency(
(20, genDel),
Expand All @@ -66,13 +62,13 @@ object RedisSpec extends Commands {
(20, genGetExisting(state)),
(20, genGetDeleted(state)),
(20, const(DBSize)),
( 1, const(FlushDB)),
( 3, const(ToggleConnected))
(1, const(FlushDB)),
(3, const(ToggleConnected))
)
}

//val genKey = arbitrary[String]
//val genVal = arbitrary[String]
// val genKey = arbitrary[String]
// val genVal = arbitrary[String]
val genKey = identifier
val genVal = identifier

Expand All @@ -82,30 +78,32 @@ object RedisSpec extends Commands {
} yield Set(key, value)

def genDelExisting(state: State): Gen[Del] =
if(state.contents.isEmpty) genDel
if (state.contents.isEmpty) genDel
else someOf(state.contents.keys.toSeq).map(Del.apply)

def genSetExisting(state: State): Gen[Set] =
if(state.contents.isEmpty) genSet else for {
if (state.contents.isEmpty) genSet
else for {
key <- oneOf(state.contents.keys.toSeq)
value <- oneOf(genVal, const(state.contents(key)))
} yield Set(key,value)
} yield Set(key, value)

val genGet: Gen[Get] = genKey.map(Get.apply)

val genDel: Gen[Del] = nonEmptyListOf(genKey).map(Del.apply)

def genGetExisting(state: State): Gen[Get] =
if(state.contents.isEmpty) genGet else for {
if (state.contents.isEmpty) genGet
else for {
key <- oneOf(state.contents.keys.toSeq)
} yield Get(key)

def genGetDeleted(state: State): Gen[Get] =
if(state.deleted.isEmpty) genGet else for {
if (state.deleted.isEmpty) genGet
else for {
key <- oneOf(state.deleted.toSeq)
} yield Get(key)


case object DBSize extends Command {
type Result = Option[Long]
def run(sut: Sut) = sut.dbsize
Expand All @@ -130,7 +128,7 @@ object RedisSpec extends Commands {
case class Del(keys: Seq[String]) extends Command {
type Result = Option[Long]
def run(sut: Sut) =
if(keys.isEmpty) Some(0)
if (keys.isEmpty) Some(0)
else sut.del(keys.head, keys.tail.toSeq: _*)
def preCondition(state: State) = state.connected
def nextState(state: State) = state.copy(
Expand All @@ -155,7 +153,7 @@ object RedisSpec extends Commands {
case object ToggleConnected extends Command {
type Result = Boolean
def run(sut: Sut) = {
if(sut.connected) sut.quit
if (sut.connected) sut.quit
else sut.connect
}
def preCondition(state: State) = true
Expand Down
1 change: 0 additions & 1 deletion examples/scalajs/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1")

11 changes: 10 additions & 1 deletion examples/simple-sbt/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ scalaVersion := "3.1.0"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.15.4" % Test

Test / testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-maxSize", "5", "-minSuccessfulTests", "33", "-workers", "1", "-verbosity", "1")
Test / testOptions += Tests.Argument(
TestFrameworks.ScalaCheck,
"-maxSize",
"5",
"-minSuccessfulTests",
"33",
"-workers",
"1",
"-verbosity",
"1")