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

Migrated core tests to munit #265

Merged
merged 4 commits into from
May 27, 2020
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
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val V = new {
val `kind-projector` = "0.11.0"
val kittens = "2.1.0"
val `log-effect-fs2` = "0.12.2"
val munit = "0.7.7"
val `parallel-collections` = "0.2.0"
val refined = "0.9.14"
val scalacheck = "1.14.3"
Expand Down Expand Up @@ -44,6 +45,8 @@ val `refined-scalacheck` = Def.setting("eu.timepit" %%% "refined-scalacheck" %
val scalacheck = Def.setting("org.scalacheck" %%% "scalacheck" % V.scalacheck % Test)
val scalatest = Def.setting("org.scalatest" %%% "scalatest" % V.scalatest % Test)
val `scalatest-plus` = Def.setting("org.scalatestplus" %%% "scalacheck-1-14" % V.`scalatest-plus` % Test)
val munit = Def.setting("org.scalameta" %%% "munit" % V.munit % Test)
val `munit-scalacheck` = Def.setting("org.scalameta" %%% "munit-scalacheck" % V.munit % Test)

val `scala-parallel-collections` = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand All @@ -67,8 +70,8 @@ val coreDeps = Def.Initialize.join {
shapeless,
`refined-scalacheck`,
scalacheck,
scalatest,
`scalatest-plus`
munit,
`munit-scalacheck`
)
}

Expand Down Expand Up @@ -239,6 +242,8 @@ lazy val publishSettings = Seq(
)

lazy val testSettings = Seq(
testFrameworks += new TestFramework("munit.Framework"),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oDF")
)

Expand Down
14 changes: 6 additions & 8 deletions core/.js/src/test/scala/laserdisc/ScalaCheckSettings.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package laserdisc

import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
import munit.ScalaCheckSuite

private[laserdisc] trait ScalaCheckSettings extends ScalaCheckPropertyChecks {
override implicit val generatorDrivenConfig: PropertyCheckConfiguration =
PropertyCheckConfiguration(
minSuccessful = 10,
maxDiscardedFactor = 10.0,
workers = 16
)
private[laserdisc] trait ScalaCheckSettings extends ScalaCheckSuite {
override val scalaCheckTestParameters =
super.scalaCheckTestParameters
.withMinSuccessfulTests(10)
.withWorkers(8)
}
20 changes: 10 additions & 10 deletions core/.jvm/src/test/scala/laserdisc/ScalaCheckSettings.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package laserdisc

import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
import munit.ScalaCheckSuite

private[laserdisc] trait ScalaCheckSettings extends ScalaCheckPropertyChecks {
override implicit val generatorDrivenConfig: PropertyCheckConfiguration =
PropertyCheckConfiguration(
minSuccessful = 200,
maxDiscardedFactor = 10.0,
minSize = 0,
sizeRange = 100,
workers = 16
)
private[laserdisc] trait ScalaCheckSettings extends ScalaCheckSuite {
override val scalaCheckTestParameters =
super.scalaCheckTestParameters
.withMinSuccessfulTests(200)
.withMaxDiscardRatio(20)
.disableLegacyShrinking
.withWorkers(32)
.withMinSize(0)
.withMaxSize(150)
}
250 changes: 152 additions & 98 deletions core/src/test/boilerplate/BListExtPSpec.scala.template
Original file line number Diff line number Diff line change
@@ -1,105 +1,159 @@
package laserdisc
package protocol

import org.scalatest.OptionValues

abstract class BListExtPSpec extends BaseSpec with OptionValues with BListP {

"The Blocking List extended protocol" when {

"using blpop" should {

"fail to compile" when {
"given key but missing read instance" in {
"""blpop[Bar](Key("a"))""" shouldNot compile
}
"given key and timeout but missing read instance" in {
"""blpop[Bar](Key("a"), PosInt(1))""" shouldNot compile
}
}

"roundtrip successfully" when {
//BLPOP with no timeout specified
[1..5#"given [#key1#]" in forAll([#"key1"#], "returned value") { ([#k1: Key#], i: Int) =>
val protocol = blpop[Int]([#k1#])

protocol.encode shouldBe Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(##0))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, i))
}#
]
//BLPOP with no timeout specified and specific read instance
[1..5#"given [#key1#] and specific read instance" in forAll([#"key1"#], "returned value") { ([#k1: Key#], i: Int) =>
val protocol = blpop[Foo]([#k1#])

protocol.encode shouldBe Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(##0))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, Foo(i)))
}#
]
//BLPOP with timeout specified
[1..4#"given [#key1#] and positive timeout" in forAll([#"key1"#], "timeout", "returned value") { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = blpop[Int]([#k1#], pi)

protocol.encode shouldBe Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(pi))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, i))
}#
]
//BLPOP with timeout specified and specific read instance
[1..4#"given [#key1#], positive timeout and specific read instance" in forAll([#"key1"#], "timeout", "returned value") { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = blpop[Foo]([#k1#], pi)

protocol.encode shouldBe Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(pi))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, Foo(i)))
}#
]
}

import org.scalacheck.Prop.forAll

final class BListExtPSpec extends BListPSpec {
test("The Blocking List extended protocol using blpop fails to compile given key but missing read instance") {
assertNoDiff(
compileErrors("""blpop[Bar](Key("a"))"""),
"""|error:
|Implicit not found Read[laserdisc.protocol.Bulk, laserdisc.Bar].
|
|Try writing your own, for example:
|
|implicit final val myRead: Read[laserdisc.protocol.Bulk, laserdisc.Bar] = new Read[laserdisc.protocol.Bulk, laserdisc.Bar] {
| override final def read(a: laserdisc.protocol.Bulk): Option[laserdisc.Bar] = ???
|}
|
|Note 1: you can use the factory method Read.instance instead of creating it manually as shown above
|Note 2: make sure to inspect the combinators as you may be able to leverage some other Read instance
|
|blpop[Bar](Key("a"))
| ^
|""".stripMargin
)
}
test("The Blocking List extended protocol using blpop fails to compile given key and timeout but missing read instance") {
assertNoDiff(
compileErrors("""blpop[Bar](Key("a"), PosInt(1))"""),
"""|error:
|Implicit not found Read[laserdisc.protocol.Bulk, laserdisc.Bar].
|
|Try writing your own, for example:
|
|implicit final val myRead: Read[laserdisc.protocol.Bulk, laserdisc.Bar] = new Read[laserdisc.protocol.Bulk, laserdisc.Bar] {
| override final def read(a: laserdisc.protocol.Bulk): Option[laserdisc.Bar] = ???
|}
|
|Note 1: you can use the factory method Read.instance instead of creating it manually as shown above
|Note 2: make sure to inspect the combinators as you may be able to leverage some other Read instance
|
|blpop[Bar](Key("a"), PosInt(1))
| ^
|""".stripMargin
)
}
//BLPOP with no timeout specified
[1..5#property("The Blocking List extended protocol using blpop roundtrips successfully given [#key1#]") {
forAll { ([#k1: Key#], i: Int) =>
val protocol = blpop[Int]([#k1#])
assertEquals(protocol.encode, Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(##0)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, i))
}

"using brpop" should {

"fail to compile" when {
"given key but missing read instance" in {
"""brpop[Bar](Key("a"))""" shouldNot compile
}
"given key and timeout but missing read instance" in {
"""brpop[Bar](Key("a"), PosInt(1))""" shouldNot compile
}
}

"roundtrip successfully" when {
//BRPOP with no timeout specified
[1..5#"given [#key1#]" in forAll([#"key1"#], "returned value") { ([#k1: Key#], i: Int) =>
val protocol = brpop[Int]([#k1#])

protocol.encode shouldBe Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(##0))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, i))
}#
]
//BRPOP with no timeout specified and specific read instance
[1..5#"given [#key1#] and specific read instance" in forAll([#"key1"#], "returned value") { ([#k1: Key#], i: Int) =>
val protocol = brpop[Foo]([#k1#])

protocol.encode shouldBe Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(##0))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, Foo(i)))
}#
]
//BRPOP with timeout specified
[1..4#"given [#key1#] and positive timeout" in forAll([#"key1"#], "timeout", "returned value") { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = brpop[Int]([#k1#], pi)

protocol.encode shouldBe Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(pi))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, i))
}#
]
//BRPOP with timeout specified and specific read instance
[1..4#"given [#key1#], positive timeout and specific read instance" in forAll([#"key1"#], "timeout", "returned value") { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = brpop[Foo]([#k1#], pi)

protocol.encode shouldBe Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(pi))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_.value shouldBe KV(k##1, Foo(i)))
}#
]
}
}#
]
//BLPOP with no timeout specified and specific read instance
[1..5#property("The Blocking List extended protocol using blpop roundtrips successfully given [#key1#] and specific read instance") {
forAll { ([#k1: Key#], i: Int) =>
val protocol = blpop[Foo]([#k1#])
assertEquals(protocol.encode, Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(##0)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, Foo(i)))
}
}#
]
//BLPOP with timeout specified
[1..5#property("The Blocking List extended protocol using blpop roundtrips successfully given [#key1#] and positive timeout") {
forAll { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = blpop[Int]([#k1#], pi)
assertEquals(protocol.encode, Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(pi)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, i))
}
}#
]
//BLPOP with timeout specified and specific read instance
[1..5#property("The Blocking List extended protocol using blpop roundtrips successfully given [#key1#], positive timeout and specific read instance") {
forAll { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = blpop[Foo]([#k1#], pi)
assertEquals(protocol.encode, Arr(Bulk("BLPOP"), [#Bulk(k1)#], Bulk(pi)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, Foo(i)))
}
}#
]
test("The Blocking List extended protocol using brpop fails to compile given key but missing read instance") {
assertNoDiff(
compileErrors("""brpop[Bar](Key("a"))"""),
"""|error:
|Implicit not found Read[laserdisc.protocol.Bulk, laserdisc.Bar].
|
|Try writing your own, for example:
|
|implicit final val myRead: Read[laserdisc.protocol.Bulk, laserdisc.Bar] = new Read[laserdisc.protocol.Bulk, laserdisc.Bar] {
| override final def read(a: laserdisc.protocol.Bulk): Option[laserdisc.Bar] = ???
|}
|
|Note 1: you can use the factory method Read.instance instead of creating it manually as shown above
|Note 2: make sure to inspect the combinators as you may be able to leverage some other Read instance
|
|brpop[Bar](Key("a"))
| ^
|""".stripMargin
)
}
test("The Blocking List extended protocol using brpop fails to compile given key and timeout but missing read instance") {
assertNoDiff(
compileErrors("""brpop[Bar](Key("a"), PosInt(1))"""),
"""|error:
|Implicit not found Read[laserdisc.protocol.Bulk, laserdisc.Bar].
|
|Try writing your own, for example:
|
|implicit final val myRead: Read[laserdisc.protocol.Bulk, laserdisc.Bar] = new Read[laserdisc.protocol.Bulk, laserdisc.Bar] {
| override final def read(a: laserdisc.protocol.Bulk): Option[laserdisc.Bar] = ???
|}
|
|Note 1: you can use the factory method Read.instance instead of creating it manually as shown above
|Note 2: make sure to inspect the combinators as you may be able to leverage some other Read instance
|
|brpop[Bar](Key("a"), PosInt(1))
| ^
|""".stripMargin
)
}
//BRPOP with no timeout specified
[1..5#property("The Blocking List extended protocol using brpop roundtrips successfully given [#key1#]") {
forAll { ([#k1: Key#], i: Int) =>
val protocol = brpop[Int]([#k1#])
assertEquals(protocol.encode, Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(##0)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, i))
}
}#
]
//BRPOP with no timeout specified and specific read instance
[1..5#property("The Blocking List extended protocol using brpop roundtrips successfully given [#key1#] and specific read instance") {
forAll { ([#k1: Key#], i: Int) =>
val protocol = brpop[Foo]([#k1#])
assertEquals(protocol.encode, Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(##0)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, Foo(i)))
}
}#
]
//BRPOP with timeout specified
[1..5#property("The Blocking List extended protocol using brpop roundtrips successfully given [#key1#] and positive timeout") {
forAll { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = brpop[Int]([#k1#], pi)
assertEquals(protocol.encode, Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(pi)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, i))
}
}#
]
//BRPOP with timeout specified and specific read instance
[1..5#property("The Blocking List extended protocol using brpop roundtrips successfully given [#key1#], positive timeout and specific read instance") {
forAll { ([#k1: Key#], pi: PosInt, i: Int) =>
val protocol = brpop[Foo]([#k1#], pi)
assertEquals(protocol.encode, Arr(Bulk("BRPOP"), [#Bulk(k1)#], Bulk(pi)))
protocol.decode(Arr(Bulk(k##1), Bulk(i))) onRight (_ contains KV(k##1, Foo(i)))
}
}#
]
}
Loading