Skip to content

Commit

Permalink
Remove dependency on scalacheck-shapeless (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Jun 20, 2021
1 parent bc3d1df commit a8229aa
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
1 change: 0 additions & 1 deletion modules/generic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ crossScalaVersions := Seq(scala212, scala213)

libraryDependencies ++= Seq(
Dependencies.shapeless,
Dependencies.scalaCheckShapeless % "test",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ package pureconfig
import scala.collection.JavaConverters._

import com.typesafe.config.ConfigValueFactory
import org.scalacheck.ScalacheckShapeless._
import org.scalacheck.{Arbitrary, Gen}
import shapeless._

import pureconfig.error.{ConfigReaderFailures, ConvertFailure, WrongSizeList}
import pureconfig.generic.auto._
import pureconfig.generic.hlist._

class HListConvertersSuite extends BaseSuite {
case class Foo(a: Int, b: String)

implicit val arbFoo: Arbitrary[Foo] = Arbitrary {
Arbitrary.arbitrary[(Int, String)].map((Foo.apply _).tupled)
}

implicit val arbHNil: Arbitrary[HNil] = Arbitrary(Gen.const(HNil))

implicit def arbHCons[H: Arbitrary, T <: HList: Arbitrary]: Arbitrary[H :: T] = Arbitrary {
Arbitrary.arbitrary[(H, T)].map { case (h, t) => h :: t }
}

behavior of "ConfigConvert"

Expand All @@ -20,7 +31,6 @@ class HListConvertersSuite extends BaseSuite {
checkArbitrary[Int :: (Long :: String :: HNil) :: Boolean :: HNil]

// Check arbitrary HList with custom types
case class Foo(a: Int, b: String)
checkArbitrary[Long :: Foo :: Boolean :: Foo :: HNil]

// Check HNil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import scala.collection.JavaConverters._

import com.typesafe.config.{ConfigFactory, ConfigRenderOptions, ConfigValueFactory}
import org.scalacheck.Arbitrary
import org.scalacheck.ScalacheckShapeless._

import pureconfig.ConfigConvert.catchReadError
import pureconfig.error.{KeyNotFound, WrongType}
Expand All @@ -30,11 +29,22 @@ class ProductConvertersSuite extends BaseSuite {

case class RecType(ls: List[RecType])

implicit val arbFlatConfig: Arbitrary[FlatConfig] = Arbitrary {
Arbitrary.arbitrary[(Boolean, Double, Float, Int, Long, String, Option[String])].map((FlatConfig.apply _).tupled)
}

implicit val arbMyType: Arbitrary[MyType] = Arbitrary {
Arbitrary.arbitrary[String].map(new MyType(_))
}

implicit val arbConfigWithUnknownType: Arbitrary[ConfigWithUnknownType] = Arbitrary {
Arbitrary.arbitrary[MyType].map(ConfigWithUnknownType.apply)
}

// tests

checkArbitrary[FlatConfig]

implicit val arbMyType = Arbitrary(Arbitrary.arbitrary[String].map(new MyType(_)))
implicit val myTypeConvert = ConfigConvert.viaString[MyType](catchReadError(new MyType(_)), _.getMyField)
checkArbitrary[ConfigWithUnknownType]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package pureconfig
import scala.collection.JavaConverters._

import com.typesafe.config.{ConfigValueFactory, ConfigValueType}
import org.scalacheck.ScalacheckShapeless._
import org.scalacheck.Arbitrary

import pureconfig.error._
import pureconfig.generic.auto._

class TupleConvertersSuite extends BaseSuite {
case class Foo(a: Int, b: String)

implicit val arbFoo: Arbitrary[Foo] = Arbitrary {
Arbitrary.arbitrary[(Int, String)].map((Foo.apply _).tupled)
}

behavior of "ConfigConvert"

Expand All @@ -18,7 +23,6 @@ class TupleConvertersSuite extends BaseSuite {
checkArbitrary[(Int, (Long, String), Boolean)]

// Check arbitrary Tuples with custom types
case class Foo(a: Int, b: String)
checkArbitrary[(Long, Foo, Boolean, Foo)]

// Check readers from objects and lists
Expand Down
1 change: 0 additions & 1 deletion modules/magnolia/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ crossScalaVersions := Seq(scala212, scala213)

libraryDependencies ++= Seq(
"com.propensive" %% "magnolia" % "0.17.0",
Dependencies.scalaCheckShapeless % "test",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import scala.language.higherKinds

import com.typesafe.config.{ConfigFactory, ConfigRenderOptions, ConfigValueFactory}
import org.scalacheck.Arbitrary
import org.scalacheck.ScalacheckShapeless._

import pureconfig.ConfigConvert.catchReadError
import pureconfig._
Expand Down Expand Up @@ -33,11 +32,22 @@ class ProductConvertersSuite extends BaseSuite {

case class RecType(ls: List[RecType])

implicit val arbFlatConfig: Arbitrary[FlatConfig] = Arbitrary {
Arbitrary.arbitrary[(Boolean, Double, Float, Int, Long, String, Option[String])].map((FlatConfig.apply _).tupled)
}

implicit val arbMyType: Arbitrary[MyType] = Arbitrary {
Arbitrary.arbitrary[String].map(new MyType(_))
}

implicit val arbConfigWithUnknownType: Arbitrary[ConfigWithUnknownType] = Arbitrary {
Arbitrary.arbitrary[MyType].map(ConfigWithUnknownType.apply)
}

// tests

checkArbitrary[FlatConfig]

implicit val arbMyType = Arbitrary(Arbitrary.arbitrary[String].map(new MyType(_)))
implicit val myTypeConvert = ConfigConvert.viaString[MyType](catchReadError(new MyType(_)), _.getMyField)
checkArbitrary[ConfigWithUnknownType]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import scala.collection.JavaConverters._
import scala.language.higherKinds

import com.typesafe.config.{ConfigValueFactory, ConfigValueType}
import org.scalacheck.ScalacheckShapeless._
import org.scalacheck.Arbitrary

import pureconfig._
import pureconfig.error._
import pureconfig.module.magnolia.auto.reader._
import pureconfig.module.magnolia.auto.writer._

class TupleConvertersSuite extends BaseSuite {
case class Foo(a: Int, b: String)

implicit val arbFoo: Arbitrary[Foo] = Arbitrary {
Arbitrary.arbitrary[(Int, String)].map((Foo.apply _).tupled)
}

behavior of "ConfigConvert"

Expand All @@ -21,7 +26,6 @@ class TupleConvertersSuite extends BaseSuite {
checkArbitrary[(Int, (Long, String), Boolean)]

// Check arbitrary Tuples with custom types
case class Foo(a: Int, b: String)
checkArbitrary[(Long, Foo, Boolean, Foo)]

// Check readers from objects and lists
Expand Down
3 changes: 0 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object Dependencies {
val scalaTestPlusScalaCheck = "3.2.9.0"

val scalaCheck = "1.15.4"
val scalaCheckShapeless = "1.3.0"
}

val shapeless = "com.chuusai" %% "shapeless" % Version.shapeless
Expand All @@ -24,6 +23,4 @@ object Dependencies {
val scalaTest = "org.scalatest" %% "scalatest" % Version.scalaTest
val scalaTestPlusScalaCheck = "org.scalatestplus" %% "scalacheck-1-15" % Version.scalaTestPlusScalaCheck
val scalaCheck = "org.scalacheck" %% "scalacheck" % Version.scalaCheck
val scalaCheckShapeless =
"com.github.alexarchambault" %% s"scalacheck-shapeless_1.15" % Version.scalaCheckShapeless
}
4 changes: 2 additions & 2 deletions testkit/src/main/scala/pureconfig/BaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

class BaseSuite
extends AnyFlatSpec
with ConfigConvertChecks
with Matchers
with ConfigReaderMatchers
with EitherValues
with ScalaCheckDrivenPropertyChecks
with ConfigConvertChecks
with ConfigReaderMatchers

0 comments on commit a8229aa

Please sign in to comment.