Skip to content

Commit

Permalink
Update coreJVMTests
Browse files Browse the repository at this point in the history
  • Loading branch information
cchantep committed Sep 5, 2022
1 parent 5a16eee commit 4ebb5cf
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 184 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ jobs:
- java: 11
scala: 2.11.12
- java: 11
scala: 2.12.14
scala: 2.12.16
- java: 11
scala: 2.13.6
scala: 2.13.8
- java: 11
scala: 3.2.1-RC1
runs-on: ubuntu-latest
env:
SCALAJS_TEST_OPT: full
# define Java options for both official sbt and sbt-extras
JAVA_OPTS: -Xms6G -Xmx6G -Xss4M -XX:ReservedCodeCacheSize=256M -XX:MaxMetaspaceSize=1G -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -Dfile.encoding=UTF-8
JVM_OPTS: -Xms6G -Xmx6G -Xss4M -XX:ReservedCodeCacheSize=256M -XX:MaxMetaspaceSize=1G -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -Dfile.encoding=UTF-8
SBT_OPTS: -Denumeratum.devMacros
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -39,26 +42,23 @@ jobs:
sbt -v ++${{ matrix.scala }} scalafmtCheck scalafmtSbtCheck scala_2_11/test:compile scala_2_11/test:doc
sbt -v ++${{ matrix.scala }} scala_2_11/test
;;
2.12.14)
2.12.16)
sbt -v ++${{ matrix.scala }} test:compile test:doc
sbt -v ++${{ matrix.scala }} coverage test coverageReport
sbt -v ++${{ matrix.scala }} coverageAggregate
;;
2.13.6)
*)
sbt -v ++${{ matrix.scala }} test:compile test:doc
sbt -v ++${{ matrix.scala }} test
;;
*)
echo unknown Scala Version ${{ matrix.scala }}
exit 1
esac
rm -rf "$HOME/.ivy2/local" || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
- name: Upload coverage to Codecov
if: ${{ matrix.scala == '2.12.14' }}
if: ${{ matrix.scala == '2.12.16' }}
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
52 changes: 27 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
lazy val scala_2_11Version = "2.11.12"
lazy val scala_2_12Version = "2.12.16"
lazy val scala_2_13Version = "2.13.8"
lazy val scala_3Version = "3.2.1-RC1"
lazy val scalaVersionsAll = Seq(scala_2_11Version, scala_2_12Version, scala_2_13Version, scala_3Version)
lazy val scala_3Version = "3.2.1-RC1"
lazy val scalaVersionsAll =
Seq(scala_2_11Version, scala_2_12Version, scala_2_13Version, scala_3Version)

lazy val theScalaVersion = scala_2_12Version

Expand All @@ -20,15 +21,15 @@ lazy val quillVersion = "4.1.0"
def theDoobieVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor <= 11 => "0.7.1"
case Some(_) => "1.0.0-RC2"
case Some(_) => "1.0.0-RC2"
case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion for Doobie")
}

def theArgonautVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 => "6.2.5"
case Some(_) => "6.3.0"
case Some(_) => "6.3.0"

case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion for Argonaut")
Expand All @@ -37,23 +38,23 @@ def theArgonautVersion(scalaVersion: String) =
def thePlayVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor >= 12 => "2.8.0"
case Some((3, _)) => "2.8.0"
case Some((3, _)) => "2.8.0"
case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion for Play")
}

def theSlickVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor <= 11 => "3.3.3"
case Some(_) => "3.3.3"
case Some(_) => "3.3.3"
case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion for Slick")
}

def theCatsVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, scalaMajor)) if scalaMajor <= 11 => "2.0.0"
case Some(_) => "2.6.1"
case Some(_) => "2.6.1"
case _ =>
throw new IllegalArgumentException(s"Unsupported Scala version $scalaVersion for Cats")
}
Expand All @@ -70,7 +71,7 @@ def thePlayJsonVersion(scalaVersion: String) =

def theCirceVersion(scalaVersion: String) =
CrossVersion.partialVersion(scalaVersion) match {
case Some((3, _)) => "0.14.1"
case Some((3, _)) => "0.14.1"
case Some((2, scalaMajor)) if scalaMajor >= 12 => "0.14.1"
case Some((2, scalaMajor)) if scalaMajor >= 11 => "0.11.1"
case _ =>
Expand Down Expand Up @@ -122,7 +123,7 @@ lazy val scala_2_13 = Project(id = "scala_2_13", base = file("scala_2_13"))
// Do not publish this project (it just serves as an aggregate)
publishArtifact := false,
publishLocal := {},
//doctestWithDependencies := false, // sbt-doctest is not yet compatible with this 2.13
// doctestWithDependencies := false, // sbt-doctest is not yet compatible with this 2.13
aggregate in publish := false,
aggregate in PgpKeys.publishSigned := false
)
Expand Down Expand Up @@ -157,7 +158,7 @@ lazy val scala_2_11 = Project(id = "scala_2_11", base = file("scala_2_11"))
// Do not publish this project (it just serves as an aggregate)
publishArtifact := false,
publishLocal := {},
//doctestWithDependencies := false, // sbt-doctest is not yet compatible with this 2.13
// doctestWithDependencies := false, // sbt-doctest is not yet compatible with this 2.13
aggregate in publish := false,
aggregate in PgpKeys.publishSigned := false
)
Expand Down Expand Up @@ -206,9 +207,7 @@ lazy val macros = crossProject(JSPlatform, JVMPlatform)
.settings(testSettings)
.jsSettings(jsTestSettings)
.settings(commonWithPublishSettings)
.settings(withCompatUnmanagedSources(
jsJvmCrossProject = true,
includeTestSrcs = false))
.settings(withCompatUnmanagedSources(jsJvmCrossProject = true, includeTestSrcs = false))
.settings(
name := "enumeratum-macros",
version := Versions.Macros.head,
Expand Down Expand Up @@ -238,9 +237,9 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
.jsSettings(jsTestSettings)
.settings(commonWithPublishSettings)
.settings(
name := "enumeratum",
version := Versions.Core.head,
crossScalaVersions := scalaVersionsAll,
name := "enumeratum",
version := Versions.Core.head,
crossScalaVersions := scalaVersionsAll,
libraryDependencies ++= {
if (devMacros) {
Seq.empty
Expand Down Expand Up @@ -300,9 +299,14 @@ lazy val coreJVMTests = Project(id = "coreJVMTests", base = file("enumeratum-cor
name := "coreJVMTests",
version := Versions.Core.stable,
crossScalaVersions := scalaVersionsAll,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Test
),
Test / sourceGenerators += CoreJVMTest.testsGenerator,
libraryDependencies += {
if (scalaBinaryVersion.value == "3") {
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value % Test
} else {
"org.scala-lang" % "scala-compiler" % scalaVersion.value % Test
}
},
publishArtifact := false,
publishLocal := {}
)
Expand Down Expand Up @@ -359,9 +363,7 @@ lazy val enumeratumPlay = Project(id = "enumeratum-play", base = file("enumeratu
scalaTestPlay(scalaVersion.value)
)
)
.settings(withCompatUnmanagedSources(
jsJvmCrossProject = false,
includeTestSrcs = true))
.settings(withCompatUnmanagedSources(jsJvmCrossProject = false, includeTestSrcs = true))
.dependsOn(enumeratumPlayJsonJvm % "compile->compile;test->test")

lazy val circeAggregate = aggregateProject("circe", enumeratumCirceJs, enumeratumCirceJvm)
Expand Down Expand Up @@ -626,8 +628,8 @@ lazy val compilerSettings = Seq(
) // unused-import breaks Circe Either shim

case Some((2, 11)) => base ++ Seq("-deprecation:false", "-Xlint", "-Ywarn-unused-import")
case Some((2, _)) => base ++ Seq("-Xlint")
case _ => base
case Some((2, _)) => base ++ Seq("-Xlint")
case _ => base
}
},
Test / scalacOptions ++= {
Expand Down Expand Up @@ -724,7 +726,7 @@ def withCompatUnmanagedSources(
): Seq[Setting[_]] = {
def compatDirs(projectbase: File, scalaVersion: String, isMain: Boolean) = {
val base = if (jsJvmCrossProject) projectbase / ".." else projectbase
val cat = if (isMain) "main" else "test"
val cat = if (isMain) "main" else "test"

CrossVersion.partialVersion(scalaVersion) match {
case Some((3, _)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Argonaut._
* }}}
*
* @tparam ValueType
* @tparam EntryType
* @tparam EntryType
*/
sealed trait ArgonautValueEnum[ValueType, EntryType <: ValueEnumEntry[ValueType]] {
this: ValueEnum[ValueType, EntryType] =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,5 @@ package enumeratum
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

class EnumJVMSpec extends AnyFunSpec with Matchers {

describe("findValues Vector") {

// This is a fairly intense test.
it("should be in the same order that the objects were declared in") {
import scala.util._
(1 to 100).foreach { i =>
val members = Random.shuffle((1 to Random.nextInt(20)).map { m =>
s"Member$m"
})
val membersDefs = members
.map { m =>
s"case object $m extends Enum$i"
}
.mkString("\n\n")
val objDefinition =
s"""
import enumeratum._
sealed trait Enum$i extends EnumEntry

case object Enum$i extends Enum[Enum$i] {
$membersDefs
val values = findValues
}

Enum$i
"""
val obj = Eval.apply[Enum[_ <: EnumEntry]](objDefinition)
obj.values.map(_.entryName) shouldBe members
}
}

}

}
// See `projects/project/CoreJVMTest.scala`#generateEnumTests
final class EnumJVMSpec extends generated.EnumBaseSpec
25 changes: 0 additions & 25 deletions enumeratum-core-jvm-tests/src/test/scala/enumeratum/Eval.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,91 +1,14 @@
package enumeratum.values

import enumeratum.Eval
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

import scala.reflect.ClassTag
import scala.util.Random

/** Created by Lloyd on 8/30/16.
*
* Copyright 2016
*/
class ValueEnumJVMSpec extends AnyFunSpec with Matchers {

private def stringGenerator =
Random.alphanumeric.grouped(10).toStream.map(_.mkString.replaceAll("[0-9]", "")).distinct

/*
Non-deterministically generates a bunch of different types of ValueEnums and tests the ability to resolve
proper members by value
*/
testValuesOf(Stream.continually(Random.nextInt()))
testValuesOf(Stream.continually(Random.nextLong()), valueSuffix = "L")
testValuesOf(
Stream
.continually(Random.nextInt(Short.MaxValue - Short.MinValue) + Short.MinValue)
.map(_.toShort)
)
testValuesOf(
Stream.continually(Random.nextInt(Byte.MaxValue - Byte.MinValue) + Byte.MinValue).map(_.toByte)
)
testValuesOf(stringGenerator, "\"", "\"")
testValuesOf(
Stream.continually(Random.nextPrintableChar()).filter(c => Character.isAlphabetic(c.toInt)),
"'",
"'"
)

private def testValuesOf[A: ClassTag](
valuesGenerator: => Stream[A],
valuePrefix: String = "",
valueSuffix: String = ""
): Unit = {

val typeName = implicitly[ClassTag[A]].runtimeClass.getSimpleName.capitalize

describe(s"${typeName}Enum withValue") {

it("should return proper members for valid values but throw otherwise") {
(1 to 20).foreach { i =>
val enumName = s"Generated${typeName}Enum$i"
val names = stringGenerator.take(5)
val values = valuesGenerator.distinct.take(5)
val namesToValues = names.zip(values)
val memberDefs = namesToValues
.map { case (n, v) =>
s"""case object $n extends $enumName($valuePrefix$v$valueSuffix)"""
}
.mkString("\n\n")
val objDef =
s"""
|import enumeratum.values._
|
|sealed abstract class $enumName(val value: $typeName) extends ${typeName}EnumEntry
|
|object $enumName extends ${typeName}Enum[$enumName] {
| val values = findValues
|
| $memberDefs
|}
|$enumName
""".stripMargin
val obj = Eval.apply[ValueEnum[A, _ <: ValueEnumEntry[A]]](objDef)
namesToValues.foreach { case (n, v) =>
obj.withValue(v).toString shouldBe n
}
// filterNot is not lazy until 2.12
valuesGenerator.filter(a => !values.contains(a)).take(5).foreach { invalidValue =>
intercept[NoSuchElementException] {
obj.withValue(invalidValue)
}
}
}
}

}

}

}
// See `projects/project/CoreJVMTest.scala`#generateValueEnumTests
final class ValueEnumJVMSpec
extends generated.IntValueEnumBaseSpec
with generated.LongValueEnumBaseSpec
with generated.ShortValueEnumBaseSpec
with generated.ByteValueEnumBaseSpec
with generated.StringValueEnumBaseSpec
with generated.CharValueEnumBaseSpec
Loading

0 comments on commit 4ebb5cf

Please sign in to comment.