diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc49c1bb..20b16d78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,10 @@ jobs: - uses: olafurpg/setup-scala@v2 - name: Test run: sbt +test + checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: olafurpg/setup-scala@v7 + - run: ./bin/scalafmt --check + - run: sbt scalafixCheckAll diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 00000000..6d486e27 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,6 @@ +rules = [ + RemoveUnused, + ExplicitResultTypes, +] + +ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false diff --git a/scalafmt b/bin/scalafmt similarity index 100% rename from scalafmt rename to bin/scalafmt diff --git a/build.sbt b/build.sbt index 9b0a5d35..bfd82bfc 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,10 @@ import java.util.Date import sbtcrossproject.CrossPlugin.autoImport.crossProject +lazy val V = new { + def munit = "0.7.2" +} val scala211 = "2.11.12" -val scala212 = "2.12.10" +val scala212 = "2.12.11" val scala213 = "2.13.1" val ScalaVersions = List(scala212, scala211, scala213) inThisBuild( @@ -31,6 +34,15 @@ inThisBuild( ) ) +addCommandAlias( + "scalafixAll", + s"; ++$scala212 ; scalafixEnable ; all scalafix test:scalafix" +) +addCommandAlias( + "scalafixCheckAll", + s"; ++$scala212 ; scalafixEnable ; scalafix --check ; test:scalafix --check" +) + addCommandAlias( "native-image", "; tests/graalvm-native-image:packageBin ; taskready" @@ -41,55 +53,24 @@ commands += Command.command("taskready") { s => s } -lazy val testSettings = List( - testOptions.in(Test) += - Tests.Argument(TestFrameworks.ScalaCheck, "-verbosity", "2"), - testFrameworks := List( - new TestFramework("munit.Framework"), - new TestFramework("org.scalacheck.ScalaCheckFramework") - ), - libraryDependencies ++= { - if (SettingKey[Boolean]("nativeLinkStubs").?.value.contains(true)) - List( - "org.scalameta" %%% "munit" % "0.4.5" % Test, - "com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test - ) - else - List( - "org.scalameta" %%% "munit" % "0.4.5" % Test, - "org.scalacheck" %%% "scalacheck" % "1.14.0" % Test, - "com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.3" % Test - ) - } -) +lazy val warnUnusedImport = Def.setting { + if (scalaVersion.value.startsWith("2.13")) "-Wunused:imports" + else "-Ywarn-unused-import" +} -lazy val nativeSettings = List( - nativeLinkStubs := true, - scalaVersion := scala211, - crossScalaVersions := List(scala211), - test.in(Test) := {} +lazy val sharedSettings = List[Setting[_]]( + scalacOptions ++= List( + "-Yrangepos", + warnUnusedImport.value + ) ) skip.in(publish) := true -lazy val json = project - .in(file("metaconfig-json")) - .settings( - testSettings, - moduleName := "metaconfig-json", - libraryDependencies ++= List( - "org.scalameta" %% "testkit" % "4.1.12" % Test - ) :+ (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 11 | 12)) => "com.lihaoyi" %%% "upickle" % "0.7.4" - case _ => "com.lihaoyi" %% "upickle" % "0.7.5" - }) - ) - .dependsOn(coreJVM) - lazy val core = crossProject(JVMPlatform, JSPlatform) .in(file("metaconfig-core")) .settings( - testSettings, + sharedSettings, moduleName := "metaconfig-core", libraryDependencies ++= List( "org.typelevel" %%% "paiges-core" % "0.3.0", @@ -100,54 +81,78 @@ lazy val core = crossProject(JVMPlatform, JSPlatform) case _ => "com.lihaoyi" %%% "pprint" % "0.5.9" }) ) - .jsSettings(scalaJSModuleKind := ModuleKind.CommonJSModule) - // .nativeSettings(nativeSettings) - .jvmSettings( - libraryDependencies += "org.scalameta" %% "testkit" % "4.1.12" % Test - ) lazy val coreJVM = core.jvm lazy val coreJS = core.js -// lazy val coreNative = core.native -lazy val typesafeConfig = "com.typesafe" % "config" % "1.2.1" +lazy val json = project + .in(file("metaconfig-json")) + .settings( + sharedSettings, + moduleName := "metaconfig-json", + libraryDependencies ++= List( + "org.scalameta" %% "testkit" % "4.1.12" % Test + ) :+ (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, 11 | 12)) => "com.lihaoyi" %%% "upickle" % "0.7.4" + case _ => "com.lihaoyi" %% "upickle" % "0.7.5" + }) + ) + .dependsOn(coreJVM) lazy val typesafe = project .in(file("metaconfig-typesafe-config")) .settings( - testSettings, + sharedSettings, moduleName := "metaconfig-typesafe-config", description := "Integration for HOCON using typesafehub/config.", - libraryDependencies += typesafeConfig + libraryDependencies += "com.typesafe" % "config" % "1.2.1" ) - .dependsOn(coreJVM % "test->test;compile->compile") + .dependsOn(coreJVM) lazy val sconfig = crossProject(JVMPlatform) .in(file("metaconfig-sconfig")) .settings( - testSettings, + sharedSettings, moduleName := "metaconfig-sconfig", description := "Integration for HOCON using ekrich/sconfig.", libraryDependencies ++= List( "org.ekrich" %%% "sconfig" % "1.0.0" ) ) - // .nativeSettings(nativeSettings) - .dependsOn(core % "test->test;compile->compile") + .dependsOn(core) lazy val sconfigJVM = sconfig.jvm -// lazy val sconfigNative = sconfig.native val scalatagsVersion = Def.setting { if (scalaVersion.value.startsWith("2.11")) "0.6.7" else "0.7.0" } -lazy val tests = project +lazy val tests = crossProject(JVMPlatform, JSPlatform) .in(file("metaconfig-tests")) .settings( + sharedSettings, skip in publish := true, + publishArtifact.in(Compile, packageDoc) := false, + testOptions.in(Test) += + Tests.Argument(TestFrameworks.ScalaCheck, "-verbosity", "2"), + testFrameworks := List( + new TestFramework("munit.Framework") + ), + libraryDependencies ++= { + if (SettingKey[Boolean]("nativeLinkStubs").?.value.contains(true)) + List( + "org.scalameta" %%% "munit-scalacheck" % V.munit % Test + ) + else + List( + "org.scalameta" %%% "munit-scalacheck" % V.munit % Test, + "com.github.alexarchambault" %%% "scalacheck-shapeless_1.14" % "1.2.3" % Test + ) + } + ) + .jsSettings(scalaJSModuleKind := ModuleKind.CommonJSModule) + .jvmSettings( mainClass in GraalVMNativeImage := Some("metaconfig.tests.ExampleMain"), sources.in(Compile, doc) := Seq.empty, - publishArtifact.in(Compile, packageDoc) := false, graalVMNativeImageOptions ++= { val reflectionFile = Keys.sourceDirectory.in(Compile).value./("graal")./("reflection.json") @@ -168,10 +173,17 @@ lazy val tests = project ) } ) - .enablePlugins(GraalVMNativeImagePlugin) - .dependsOn(coreJVM) + .jvmConfigure( + _.enablePlugins(GraalVMNativeImagePlugin) + .dependsOn(json, typesafe, sconfigJVM) + ) + .dependsOn(core) +lazy val testsJVM = tests.jvm +lazy val testsJS = tests.js + lazy val docs = project .settings( + sharedSettings, moduleName := "metaconfig-docs", libraryDependencies ++= List( "com.lihaoyi" %% "scalatags" % scalatagsVersion.value diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/CodecProps.scala b/metaconfig-core/jvm/src/test/scala/metaconfig/CodecProps.scala deleted file mode 100644 index 70f3d163..00000000 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/CodecProps.scala +++ /dev/null @@ -1,36 +0,0 @@ -package metaconfig - -import metaconfig.generic.Surface -import org.scalacheck.Prop.forAll -import org.scalacheck.Properties -import org.scalacheck.ScalacheckShapeless._ - -case class Inner(a: String = "a", b: Boolean = true) -object Inner { - implicit val surface: Surface[Inner] = generic.deriveSurface[Inner] - implicit val codec: ConfCodec[Inner] = generic.deriveCodec(Inner()) -} - -case class Outer(inner: Inner = Inner(), c: Int = 0) -object Outer { - implicit val surface: Surface[Outer] = generic.deriveSurface - implicit val codec: ConfCodec[Outer] = generic.deriveCodec(Outer()) -} - -class CodecProps extends Properties("Codec") { - - def checkRoundtrip[T: ConfCodec](a: T): Boolean = { - val conf = ConfEncoder[T].write(a) - val b = ConfDecoder[T].read(conf).get - a == b - } - - property("roundtrip AllTheAnnotations") = forAll { a: AllTheAnnotations => - checkRoundtrip(a) - } - - property("roundtrip Outer") = forAll { a: Outer => - checkRoundtrip(a) - } - -} diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/Site.scala b/metaconfig-core/jvm/src/test/scala/metaconfig/cli/Site.scala deleted file mode 100644 index 17238b26..00000000 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/Site.scala +++ /dev/null @@ -1,16 +0,0 @@ -package metaconfig.cli - -import java.nio.file.Paths -import metaconfig.annotation._ -import metaconfig._ -import metaconfig.generic.Settings -import java.io.File - -case class Site( - foo: String = "foo", - custom: Map[String, String] = Map.empty -) -object Site { - implicit val surface = generic.deriveSurface[Site] - implicit val codec = generic.deriveCodec[Site](Site()) -} diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala b/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala index 88cb7338..c529d432 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala @@ -9,8 +9,6 @@ import metaconfig.internal.CliParser import metaconfig.internal.ConfGet import metaconfig.internal.ConfPatch import metaconfig.internal.HoconPrinter -import org.typelevel.paiges.Doc -import metaconfig.generic.Surface sealed abstract class Conf extends Product with Serializable { def dynamic: ConfDynamic = ConfDynamic(Configured.Ok(this)) @@ -115,7 +113,7 @@ object Conf { .getOrElse(Configured.Ok(None)) } object Obj { - val empty = Obj() + val empty: Obj = Obj() def apply(values: (String, Conf)*): Obj = Obj(values.toList) } } diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/ConfCodec.scala b/metaconfig-core/shared/src/main/scala/metaconfig/ConfCodec.scala index 13613893..1b14b95d 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/ConfCodec.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/ConfCodec.scala @@ -1,7 +1,5 @@ package metaconfig -import scala.language.higherKinds - trait ConfCodec[A] extends ConfDecoder[A] with ConfEncoder[A] { self => def bimap[B](in: B => A, out: A => B): ConfCodec[B] = new ConfCodec[B] { override def write(value: B): Conf = self.write(in(value)) diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala index 03f39fb6..0ecb4e83 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/ConfDecoder.scala @@ -1,6 +1,5 @@ package metaconfig -import scala.language.experimental.macros import scala.language.higherKinds import scala.collection.compat._ import scala.reflect.ClassTag diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/Input.scala b/metaconfig-core/shared/src/main/scala/metaconfig/Input.scala index 41786919..63259480 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/Input.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/Input.scala @@ -66,19 +66,21 @@ sealed abstract class Input(val path: String, val text: String) object Input { case object None extends Input("", "") { - override def toString = "Input.None" + override def toString: Predef.String = "Input.None" } final case class String(override val text: Predef.String) extends Input("", text) { - override def toString = s"""Input.String("$text")""" + override def toString: Predef.String = + s"""Input.String("$text")""" } final case class VirtualFile( override val path: Predef.String, override val text: Predef.String ) extends Input(path, text) { - override def toString = s"""Input.VirtualFile("$path", "...")""" + override def toString: Predef.String = + s"""Input.VirtualFile("$path", "...")""" } final case class File(file: Path, charset: Charset) diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/Position.scala b/metaconfig-core/shared/src/main/scala/metaconfig/Position.scala index 36e272e9..ac0aa7d6 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/Position.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/Position.scala @@ -77,7 +77,7 @@ object Position { def endLine: Int = input.offsetToLine(end) def endColumn: Int = end - input.lineToOffset(endLine) override def text = new String(input.chars, start, end - start) - override def toString = s"[$start..$end) in $input" + override def toString: String = s"[$start..$end) in $input" } } diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/CliApp.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/CliApp.scala index 7d221edb..809ac788 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/CliApp.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/CliApp.scala @@ -2,9 +2,6 @@ package metaconfig.cli import java.io.PrintStream import java.io.InputStream -import metaconfig.generic -import metaconfig.ConfEncoder -import metaconfig.generic.Surface import java.nio.file.Path import fansi.Str import fansi.Color diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/Command.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/Command.scala index 8860d71e..85d3faef 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/Command.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/Command.scala @@ -1,11 +1,8 @@ package metaconfig.cli import java.io.PrintStream -import java.io.InputStream -import metaconfig.generic import metaconfig.ConfEncoder import metaconfig.generic.Surface -import java.nio.file.Path import org.typelevel.paiges.Doc import java.io.ByteArrayOutputStream import java.nio.charset.StandardCharsets diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpCommand.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpCommand.scala index 925f3dc9..15695f19 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpCommand.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpCommand.scala @@ -1,20 +1,7 @@ package metaconfig.cli -import metaconfig.generic.Field -import metaconfig.generic.Surface -import metaconfig.ConfEncoder -import metaconfig.Conf import org.typelevel.paiges.Doc -import scala.util.control.NonFatal -import metaconfig.Conf.Str -import java.io.PrintStream -import java.io.ByteArrayOutputStream -import java.nio.charset.StandardCharsets import metaconfig.internal.TermInfo -import metaconfig.annotation.ExtraName -import metaconfig.ConfDecoder -import metaconfig.Configured -import metaconfig.Conf.Obj import metaconfig.internal.Levenshtein object HelpCommand @@ -30,7 +17,7 @@ class HelpCommand( appDescription: CliApp => Doc, appExamples: CliApp => Doc ) extends Command[HelpOptions]("help") { - override def description = Doc.paragraph("Print this help message") + override def description: Doc = Doc.paragraph("Print this help message") override def extraNames: List[String] = List("-h", "--help", "-help") override def complete( context: TabCompletionContext diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpOptions.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpOptions.scala index efb92be5..80af8175 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpOptions.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/HelpOptions.scala @@ -4,12 +4,6 @@ import metaconfig.generic.Field import metaconfig.generic.Surface import metaconfig.ConfEncoder import metaconfig.Conf -import org.typelevel.paiges.Doc -import scala.util.control.NonFatal -import metaconfig.Conf.Str -import java.io.PrintStream -import java.io.ByteArrayOutputStream -import java.nio.charset.StandardCharsets import metaconfig.annotation.ExtraName import metaconfig.ConfDecoder import metaconfig.Configured @@ -23,7 +17,7 @@ case class HelpOptions( // in the same project as where we define macros. The boilerplat is not nice at // all. object HelpOptions { - val default = HelpOptions() + val default: HelpOptions = HelpOptions() implicit val surface: Surface[HelpOptions] = new Surface( List( List( diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/Messages.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/Messages.scala index 1dbb193e..bc829bb5 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/Messages.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/Messages.scala @@ -1,8 +1,5 @@ package metaconfig.cli -import java.io.ByteArrayOutputStream -import java.io.PrintStream -import java.nio.charset.StandardCharsets import metaconfig.annotation.Hidden import metaconfig.annotation.Inline import metaconfig.annotation.Section diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteCommand.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteCommand.scala index 5e2a55bc..5e34a80f 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteCommand.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteCommand.scala @@ -1,18 +1,13 @@ package metaconfig.cli -import metaconfig.generic.Surface import scala.collection.immutable.Nil import metaconfig.generic.Settings import metaconfig.internal.CliParser import java.io.File import java.nio.file.Files import java.nio.file.Paths -import metaconfig.Conf -import metaconfig.generic import metaconfig.internal.Case import java.nio.file.Path -import scala.util.Try -import metaconfig.generic.Setting object TabCompleteCommand extends Command[TabCompleteOptions]("tab-complete") { diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteOptions.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteOptions.scala index 3ce53707..328298b5 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteOptions.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/TabCompleteOptions.scala @@ -3,7 +3,6 @@ package metaconfig.cli import metaconfig._ import metaconfig.annotation._ import metaconfig.generic._ -import metaconfig.generic import metaconfig.internal.CliParser case class TabCompleteOptions( @@ -12,7 +11,7 @@ case class TabCompleteOptions( arguments: List[String] = Nil ) object TabCompleteOptions { - val default = TabCompleteOptions() + val default: TabCompleteOptions = TabCompleteOptions() implicit val surface: Surface[TabCompleteOptions] = new Surface( List( List( diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/cli/VersionCommand.scala b/metaconfig-core/shared/src/main/scala/metaconfig/cli/VersionCommand.scala index d9bbfe8f..d2589a4b 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/cli/VersionCommand.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/cli/VersionCommand.scala @@ -1,8 +1,5 @@ package metaconfig.cli -import metaconfig.generic.Surface -import metaconfig.ConfEncoder -import metaconfig.Conf import org.typelevel.paiges.Doc object VersionCommand extends Command[Unit]("version") { diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/internal/CliParser.scala b/metaconfig-core/shared/src/main/scala/metaconfig/internal/CliParser.scala index ac327185..8436650f 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/internal/CliParser.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/internal/CliParser.scala @@ -5,7 +5,6 @@ import metaconfig.generic.Setting import metaconfig.generic.Settings import metaconfig.Configured.ok import metaconfig.annotation.Inline -import metaconfig.Configured.Ok import metaconfig.Configured.NotOk class CliParser[T]( diff --git a/metaconfig-core/shared/src/main/scala/metaconfig/internal/Macros.scala b/metaconfig-core/shared/src/main/scala/metaconfig/internal/Macros.scala index 7ce14095..97d65c0e 100644 --- a/metaconfig-core/shared/src/main/scala/metaconfig/internal/Macros.scala +++ b/metaconfig-core/shared/src/main/scala/metaconfig/internal/Macros.scala @@ -1,7 +1,5 @@ package metaconfig.internal -import scala.language.experimental.macros - import scala.annotation.StaticAnnotation import scala.reflect.macros.blackbox import metaconfig._ diff --git a/metaconfig-json/src/main/scala/metaconfig/internal/JsonConfParser.scala b/metaconfig-json/src/main/scala/metaconfig/internal/JsonConfParser.scala index 29a1c4f3..414c72d3 100644 --- a/metaconfig-json/src/main/scala/metaconfig/internal/JsonConfParser.scala +++ b/metaconfig-json/src/main/scala/metaconfig/internal/JsonConfParser.scala @@ -11,7 +11,7 @@ final class JsonConfParser[J](input: Input) with CharBasedParser[J] { var line = 0 val chars = input.chars - val wrapped = CharBuffer.wrap(chars) + val wrapped: CharBuffer = CharBuffer.wrap(chars) override def die(i: Int, msg: String): Nothing = { val pos = Position.Range(input, i, i) diff --git a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/PatchProps.scala b/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/PatchProps.scala deleted file mode 100644 index e9fbd697..00000000 --- a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/PatchProps.scala +++ /dev/null @@ -1,58 +0,0 @@ -package metaconfig.sconfig - -import metaconfig.Conf -import metaconfig.ConfOps -import metaconfig.ConfShow -import org.scalacheck.Prop.forAll -import org.scalacheck.Properties -import org.scalameta.logger -import scala.meta.testkit.DiffAssertions -import metaconfig.Generators.argConfShow - -object PatchProps { - // asserts that applying - def checkPatch(a: String, b: String): Boolean = { - val original = Conf.parseString(a).get - val revised = Conf.parseString(b).get - val patch = Conf.patch(original, revised) - val expected = Conf.applyPatch(original, revised) - val obtained = Conf.applyPatch(original, patch) - if (obtained != expected) { - logger.elem( - obtained, - expected, - patch.toString, - Conf.patch(obtained, expected) - ) - } - obtained == expected - } -} - -class PatchProps extends Properties("Patch") { - - property("roundtrip") = forAll { (a: ConfShow, b: ConfShow) => - PatchProps.checkPatch(a.str, b.str) - } - -} -class PatchPropsSuite extends munit.FunSuite { - def check(a: String, b: String): Unit = { - test(a) { - assert(PatchProps.checkPatch(clue(a), clue(b))) - } - } - - check( - """ - |ad.da = true - |cc.bd = "dd" - """.stripMargin, - """ - | - |ad.a.dc = false - |ad = "ad" - """.stripMargin - ) - -} diff --git a/metaconfig-sconfig/shared/src/main/scala/metaconfig/sconfig/package.scala b/metaconfig-sconfig/shared/src/main/scala/metaconfig/sconfig/package.scala index 103b538e..f74ae56a 100644 --- a/metaconfig-sconfig/shared/src/main/scala/metaconfig/sconfig/package.scala +++ b/metaconfig-sconfig/shared/src/main/scala/metaconfig/sconfig/package.scala @@ -1,12 +1,13 @@ package metaconfig package object sconfig { - implicit val sConfigMetaconfigParser = new MetaconfigParser { - override def fromInput(input: Input): Configured[Conf] = input match { - case Input.File(path, _) => - SConfig2Class.gimmeConfFromFile(path.toFile) - case els => - SConfig2Class.gimmeConfFromString(new String(els.chars)) + implicit val sConfigMetaconfigParser: MetaconfigParser = + new MetaconfigParser { + override def fromInput(input: Input): Configured[Conf] = input match { + case Input.File(path, _) => + SConfig2Class.gimmeConfFromFile(path.toFile) + case els => + SConfig2Class.gimmeConfFromString(new String(els.chars)) + } } - } } diff --git a/metaconfig-tests/src/main/graal/reflection.json b/metaconfig-tests/jvm/src/main/graal/reflection.json similarity index 100% rename from metaconfig-tests/src/main/graal/reflection.json rename to metaconfig-tests/jvm/src/main/graal/reflection.json diff --git a/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Markdownish.scala b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Markdownish.scala new file mode 100644 index 00000000..010d6f95 --- /dev/null +++ b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Markdownish.scala @@ -0,0 +1,28 @@ +package metaconfig.cli + +import metaconfig.generic +import metaconfig.annotation.Description +import metaconfig.ConfCodec +import metaconfig.generic.Surface + +case class Markdownish( + @Description( + """|The JVM classpath is a list of path ':' separated files. + |Example: + | + |``` + |a.jar:b.jar:c.jar + |``` + | + |The JVM classpath is a list of path ':' separated files. + |""".stripMargin + ) + classpath: List[String] = Nil +) +object Markdownish { + val default: Markdownish = Markdownish() + implicit val surface: Surface[Markdownish] = + generic.deriveSurface[Markdownish] + implicit val codec: ConfCodec[Markdownish] = + generic.deriveCodec[Markdownish](default) +} diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/Options.scala b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Options.scala similarity index 92% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/Options.scala rename to metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Options.scala index a6b814d5..0f693ebe 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/Options.scala +++ b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Options.scala @@ -3,8 +3,7 @@ package metaconfig.cli import java.nio.file.Paths import metaconfig.annotation._ import metaconfig._ -import metaconfig.generic.Settings -import java.io.File +import metaconfig.generic.Surface case class Options( @Description("The input directory to generate the fox site.") @@ -41,7 +40,7 @@ case class Options( hidden: Int = 87 ) object Options { - implicit val surface = generic.deriveSurface[Options] + implicit val surface: Surface[Options] = generic.deriveSurface[Options] implicit val codec: ConfCodec[Options] = generic.deriveCodec[Options](Options()) } diff --git a/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Site.scala b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Site.scala new file mode 100644 index 00000000..097bf7d4 --- /dev/null +++ b/metaconfig-tests/jvm/src/main/scala/metaconfig/cli/Site.scala @@ -0,0 +1,13 @@ +package metaconfig.cli + +import metaconfig._ +import metaconfig.generic.Surface + +case class Site( + foo: String = "foo", + custom: Map[String, String] = Map.empty +) +object Site { + implicit val surface: Surface[Site] = generic.deriveSurface[Site] + implicit val codec: ConfCodec[Site] = generic.deriveCodec[Site](Site()) +} diff --git a/metaconfig-tests/src/main/scala/metaconfig/tests/ExampleMain.scala b/metaconfig-tests/jvm/src/main/scala/metaconfig/tests/ExampleMain.scala similarity index 84% rename from metaconfig-tests/src/main/scala/metaconfig/tests/ExampleMain.scala rename to metaconfig-tests/jvm/src/main/scala/metaconfig/tests/ExampleMain.scala index 44746119..db52231b 100644 --- a/metaconfig-tests/src/main/scala/metaconfig/tests/ExampleMain.scala +++ b/metaconfig-tests/jvm/src/main/scala/metaconfig/tests/ExampleMain.scala @@ -8,7 +8,8 @@ import metaconfig.cli.HelpCommand import metaconfig.cli.VersionCommand import metaconfig.cli.TabCompleteCommand import metaconfig.annotation.ExtraName -import metaconfig.annotation.TabCompleteAsPath +import metaconfig.ConfCodec +import metaconfig.generic.Surface case class ExampleOptions( path: Path = Paths.get(".").toAbsolutePath().normalize(), @@ -18,9 +19,9 @@ case class ExampleOptions( ) object ExampleOptions { - implicit val surface = + implicit val surface: Surface[ExampleOptions] = metaconfig.generic.deriveSurface[ExampleOptions] - implicit val codec = + implicit val codec: ConfCodec[ExampleOptions] = metaconfig.generic.deriveCodec[ExampleOptions](ExampleOptions()) } @@ -31,7 +32,7 @@ object ExampleCommand extends Command[ExampleOptions]("example") { } object ExampleMain { - val app = CliApp( + val app: CliApp = CliApp( version = "1.0", "hello", List( diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/CodecRoundtripSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/CodecRoundtripSuite.scala new file mode 100644 index 00000000..5b11c551 --- /dev/null +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/CodecRoundtripSuite.scala @@ -0,0 +1,26 @@ +package metaconfig + +import org.scalacheck.Prop.forAll +import org.scalacheck.ScalacheckShapeless._ + +class CodecRoundtripSuite extends munit.ScalaCheckSuite { + + def checkRoundtrip[T: ConfCodec](a: T): Boolean = { + val conf = ConfEncoder[T].write(a) + val b = ConfDecoder[T].read(conf).get + a == b + } + + property("roundtrip AllTheAnnotations") { + forAll { a: AllTheAnnotations => + checkRoundtrip(a) + } + } + + property("roundtrip Outer") { + forAll { a: Outer => + checkRoundtrip(a) + } + } + +} diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/HoconPrinterSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/HoconPrinterSuite.scala similarity index 100% rename from metaconfig-core/jvm/src/test/scala/metaconfig/HoconPrinterSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/HoconPrinterSuite.scala diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/Inner.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/Inner.scala new file mode 100644 index 00000000..bba83d9b --- /dev/null +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/Inner.scala @@ -0,0 +1,9 @@ +package metaconfig + +import metaconfig.generic.Surface + +case class Inner(a: String = "a", b: Boolean = true) +object Inner { + implicit val surface: Surface[Inner] = generic.deriveSurface[Inner] + implicit val codec: ConfCodec[Inner] = generic.deriveCodec(Inner()) +} diff --git a/metaconfig-json/src/test/scala/metaconfig/JsonSchemaSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/JsonSchemaSuite.scala similarity index 85% rename from metaconfig-json/src/test/scala/metaconfig/JsonSchemaSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/JsonSchemaSuite.scala index c6a4b809..9fc9d701 100644 --- a/metaconfig-json/src/test/scala/metaconfig/JsonSchemaSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/JsonSchemaSuite.scala @@ -2,7 +2,7 @@ package metaconfig import metaconfig.annotation._ import metaconfig.generic.Settings -import scala.meta.testkit.DiffAssertions +import metaconfig.generic.Surface class JsonSchemaSuite extends munit.FunSuite { @@ -30,8 +30,8 @@ class JsonSchemaSuite extends munit.FunSuite { repeated: Seq[Int] ) object Simple { - implicit val encoder = generic.deriveEncoder[Simple] - implicit val surface = generic.deriveSurface[Simple] + implicit val encoder: ConfEncoder[Simple] = generic.deriveEncoder[Simple] + implicit val surface: Surface[Simple] = generic.deriveSurface[Simple] } check( @@ -70,8 +70,8 @@ class JsonSchemaSuite extends munit.FunSuite { value: String ) object B { - implicit val encoder = generic.deriveEncoder[B] - implicit val surface = generic.deriveSurface[B] + implicit val encoder: ConfEncoder[B] = generic.deriveEncoder[B] + implicit val surface: Surface[B] = generic.deriveSurface[B] } case class A( value: Int, @@ -79,8 +79,8 @@ class JsonSchemaSuite extends munit.FunSuite { b: B ) object A { - implicit val encoder = generic.deriveEncoder[A] - implicit val surface = generic.deriveSurface[A] + implicit val encoder: ConfEncoder[A] = generic.deriveEncoder[A] + implicit val surface: Surface[A] = generic.deriveSurface[A] } check( diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/Outer.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/Outer.scala new file mode 100644 index 00000000..783c2326 --- /dev/null +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/Outer.scala @@ -0,0 +1,9 @@ +package metaconfig + +import metaconfig.generic.Surface + +case class Outer(inner: Inner = Inner(), c: Int = 0) +object Outer { + implicit val surface: Surface[Outer] = generic.deriveSurface + implicit val codec: ConfCodec[Outer] = generic.deriveCodec(Outer()) +} diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/PatchSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/PatchSuite.scala similarity index 100% rename from metaconfig-core/jvm/src/test/scala/metaconfig/PatchSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/PatchSuite.scala diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala similarity index 91% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala index 308804fe..2ed68ad1 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/BaseCliParserSuite.scala @@ -1,13 +1,10 @@ package metaconfig.cli -import java.nio.file.Paths -import metaconfig.annotation._ import metaconfig._ import metaconfig.generic.Settings -import java.io.File class BaseCliParserSuite extends munit.FunSuite { - val settings = Settings[Options] + val settings: Settings[Options] = Settings[Options] def toString(options: Options): String = { settings.settings .zip(options.productIterator.toList) diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/CaseSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CaseSuite.scala similarity index 100% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/CaseSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CaseSuite.scala diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala similarity index 97% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala index 48fb4390..5aeeddfb 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliParserSuite.scala @@ -1,10 +1,6 @@ package metaconfig.cli -import java.nio.file.Paths -import metaconfig.annotation._ import metaconfig._ -import metaconfig.generic.Settings -import java.io.File class CliParserSuite extends BaseCliParserSuite { diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliSuite.scala similarity index 71% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliSuite.scala index e3712275..226d7d26 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/CliSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/CliSuite.scala @@ -1,34 +1,6 @@ package metaconfig.cli -import metaconfig.generic -import metaconfig.generic.Settings -import metaconfig.Conf import org.typelevel.paiges.Doc -import metaconfig.annotation.Description -import metaconfig.ConfCodec -import metaconfig.generic.Surface - -case class Markdownish( - @Description( - """|The JVM classpath is a list of path ':' separated files. - |Example: - | - |``` - |a.jar:b.jar:c.jar - |``` - | - |The JVM classpath is a list of path ':' separated files. - |""".stripMargin - ) - classpath: List[String] = Nil -) -object Markdownish { - val default = Markdownish() - implicit val surface: Surface[Markdownish] = - generic.deriveSurface[Markdownish] - implicit val codec: ConfCodec[Markdownish] = - generic.deriveCodec[Markdownish](default) -} class CliSuite extends munit.FunSuite { def checkOptions[T]( diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala similarity index 89% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala index 0ebb4da8..12fab986 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/SubcommandSuite.scala @@ -9,6 +9,8 @@ import metaconfig.annotation.Section import metaconfig.annotation.Description import metaconfig.annotation.Inline import metaconfig.annotation.Hidden +import metaconfig.ConfCodec +import metaconfig.generic.Surface class SubcommandSuite extends FunSuite { case class CommonOptions( @@ -24,17 +26,20 @@ class SubcommandSuite extends FunSuite { invisible: Int = 41, @Inline() common: CommonOptions = CommonOptions() ) - implicit val commonSurface = metaconfig.generic.deriveSurface[CommonOptions] - implicit val commonCodec = + implicit val commonSurface: Surface[CommonOptions] = + metaconfig.generic.deriveSurface[CommonOptions] + implicit val commonCodec: ConfCodec[CommonOptions] = metaconfig.generic.deriveCodec[CommonOptions](CommonOptions()) - implicit val surface = metaconfig.generic.deriveSurface[TestOptions] - implicit val codec = + implicit val surface: Surface[TestOptions] = + metaconfig.generic.deriveSurface[TestOptions] + implicit val codec: ConfCodec[TestOptions] = metaconfig.generic.deriveCodec[TestOptions](TestOptions()) object TestCommand extends Command[TestOptions]("test") { override def description: Doc = Doc.paragraph("Run tests") override def options: Doc = Messages.options(TestOptions()) - override def usage = Doc.text("app test [OPTIONS] [project ...]") - override def examples = Doc.text("app test --max-count=100 project-name") + override def usage: Doc = Doc.text("app test [OPTIONS] [project ...]") + override def examples: Doc = + Doc.text("app test --max-count=100 project-name") def run(value: Value, app: CliApp): Int = { app.out.println("verbose: " + value.verbose) app.out.println("max-count: " + value.maxCount) @@ -42,7 +47,7 @@ class SubcommandSuite extends FunSuite { 0 } } - def checkError(args: List[String], expected: String) = + def checkError(args: List[String], expected: String): Unit = check(args, expected, expectedExit = 1) def check( args: List[String], diff --git a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala similarity index 97% rename from metaconfig-core/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala index 47a07fd7..ebadfd16 100644 --- a/metaconfig-core/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/cli/TabCompletionSuite.scala @@ -25,7 +25,8 @@ class TabCompletionSuite extends FunSuite { hidden: Int = 87 ) object TabOptions { - implicit val surface = generic.deriveSurface[TabOptions] + implicit val surface: generic.Surface[TabOptions] = + generic.deriveSurface[TabOptions] implicit val codec: ConfCodec[TabOptions] = generic.deriveCodec[TabOptions](TabOptions()) } diff --git a/metaconfig-json/src/test/scala/metaconfig/internal/JsonConfErrorSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/internal/JsonConfErrorSuite.scala similarity index 100% rename from metaconfig-json/src/test/scala/metaconfig/internal/JsonConfErrorSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/internal/JsonConfErrorSuite.scala diff --git a/metaconfig-json/src/test/scala/metaconfig/internal/JsonConfParserSuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/internal/JsonConfParserSuite.scala similarity index 100% rename from metaconfig-json/src/test/scala/metaconfig/internal/JsonConfParserSuite.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/internal/JsonConfParserSuite.scala diff --git a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterProps.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterRoundtripSuite.scala similarity index 51% rename from metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterProps.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterRoundtripSuite.scala index 06a7a06a..ed8ba728 100644 --- a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterProps.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/HoconPrinterRoundtripSuite.scala @@ -1,41 +1,22 @@ package metaconfig.sconfig import metaconfig.Conf -import metaconfig.ConfOps import metaconfig.ConfShow -import org.scalacheck.Properties -import org.scalameta.logger -import scala.meta.testkit.DiffAssertions import metaconfig.Generators.argConfShow import org.scalacheck.Prop.forAll -object HoconPrinterProps { - def checkRoundtrip(conf: String): Boolean = { +class HoconPrinterRoundtripSuite extends munit.ScalaCheckSuite { + def assertRoundtrip(conf: String): Unit = { val a = Conf.parseString(conf).get val hocon = Conf.printHocon(a) val b = Conf.parseString(hocon).get val isEqual = a == b - if (!isEqual) { - pprint.log(a) - pprint.log(b) - logger.elem(conf, hocon, Conf.patch(a, b)) - } - a == b - } - -} - -class HoconPrinterProps extends Properties("HoconPrinter") { - property("roundtrip") = forAll { conf: ConfShow => - HoconPrinterProps.checkRoundtrip(conf.str) + assertEquals(a, b) } -} - -class HoconPrinterRoundtripSuite extends munit.FunSuite { def ignore(conf: String): Unit = super.test(conf.ignore) {} def checkRoundtrip(conf: String): Unit = test(conf.take(100)) { - assert(HoconPrinterProps.checkRoundtrip(conf)) + assertRoundtrip(clue(conf)) } ignore( @@ -52,4 +33,10 @@ class HoconPrinterRoundtripSuite extends munit.FunSuite { |aa.aa = "cb" """.stripMargin ) + + property("roundtrip") { + forAll { conf: ConfShow => + assertRoundtrip(conf.str) + } + } } diff --git a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassTest.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassSuite.scala similarity index 95% rename from metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassTest.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassSuite.scala index e59e7049..bbb81bb7 100644 --- a/metaconfig-sconfig/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassTest.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SConfig2ClassSuite.scala @@ -5,7 +5,7 @@ import java.nio.file.Files import java.nio.file.Paths import metaconfig.Conf -class SConfig2ClassTest extends munit.FunSuite { +class SConfig2ClassSuite extends munit.FunSuite { test("basic") { val file = File.createTempFile("prefix", ".conf") Files.write( diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SconfigPropertySuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SconfigPropertySuite.scala new file mode 100644 index 00000000..575b1a5b --- /dev/null +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/sconfig/SconfigPropertySuite.scala @@ -0,0 +1,41 @@ +package metaconfig.sconfig + +import metaconfig.Conf +import metaconfig.ConfShow +import org.scalacheck.Prop.forAll +import metaconfig.Generators.argConfShow + +class SconfigPropertySuite extends munit.ScalaCheckSuite { + def assertRoundtrip(a: String, b: String): Unit = { + val original = Conf.parseString(a).get + val revised = Conf.parseString(b).get + val patch = Conf.patch(original, revised) + val expected = Conf.applyPatch(original, revised) + val obtained = Conf.applyPatch(original, patch) + assertEquals(obtained, expected) + } + + def checkRoundtrip(a: String, b: String): Unit = { + test(a) { + assertRoundtrip(a, b) + } + } + + checkRoundtrip( + """ + |ad.da = true + |cc.bd = "dd" + """.stripMargin, + """ + | + |ad.a.dc = false + |ad = "ad" + """.stripMargin + ) + + property("roundtrip") { + forAll { (a: ConfShow, b: ConfShow) => + assertRoundtrip(a.str, b.str) + } + } +} diff --git a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/HoconPrinterProps.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/HoconPrinterRoundtripSuite.scala similarity index 51% rename from metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/HoconPrinterProps.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/HoconPrinterRoundtripSuite.scala index fe0d29cc..45d20b18 100644 --- a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/HoconPrinterProps.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/HoconPrinterRoundtripSuite.scala @@ -1,43 +1,30 @@ package metaconfig.typesafeconfig import metaconfig.Conf -import metaconfig.ConfOps import metaconfig.ConfShow -import org.scalacheck.Properties -import org.scalameta.logger -import scala.meta.testkit.DiffAssertions import metaconfig.Generators.argConfShow import org.scalacheck.Prop.forAll -object HoconPrinterProps { - def checkRoundtrip(conf: String): Boolean = { +class HoconPrinterRoundtripSuite extends munit.ScalaCheckSuite { + def assertRoundtrip(conf: String): Unit = { val a = Conf.parseString(conf).get val hocon = Conf.printHocon(a) val b = Conf.parseString(hocon).get val isEqual = a == b - if (!isEqual) { - pprint.log(a) - pprint.log(b) - logger.elem(conf, hocon, Conf.patch(a, b)) - } - a == b - } - -} - -class HoconPrinterProps extends Properties("HoconPrinter") { - property("roundtrip") = forAll { conf: ConfShow => - HoconPrinterProps.checkRoundtrip(conf.str) + assertEquals(a, b) } -} - -class HoconPrinterRoundtripSuite extends munit.FunSuite { def ignore(conf: String): Unit = super.test(conf.ignore) {} + def checkRoundtrip(conf: String): Unit = test(conf.take(100)) { - assert(HoconPrinterProps.checkRoundtrip(conf)) + assertRoundtrip(conf) } + property("roundtrip") { + forAll { conf: ConfShow => + assertRoundtrip(conf.str) + } + } ignore( """ |a.a = "d" diff --git a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassTest.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassSuite.scala similarity index 95% rename from metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassTest.scala rename to metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassSuite.scala index b1cb2ac1..fac36cf2 100644 --- a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassTest.scala +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfig2ClassSuite.scala @@ -5,7 +5,7 @@ import java.nio.file.Files import java.nio.file.Paths import metaconfig.Conf -class TypesafeConfig2ClassTest extends munit.FunSuite { +class TypesafeConfig2ClassSuite extends munit.FunSuite { test("basic") { val file = File.createTempFile("prefix", ".conf") Files.write( diff --git a/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfigPropertySuite.scala b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfigPropertySuite.scala new file mode 100644 index 00000000..6b673e21 --- /dev/null +++ b/metaconfig-tests/jvm/src/test/scala/metaconfig/typesafeconfig/TypesafeConfigPropertySuite.scala @@ -0,0 +1,42 @@ +package metaconfig.typesafeconfig + +import metaconfig.Conf +import metaconfig.ConfShow +import org.scalacheck.Prop.forAll +import metaconfig.Generators.argConfShow + +class TypesafeConfigPropertySuite extends munit.ScalaCheckSuite { + def check(a: String, b: String): Unit = { + test(a) { + assertRoundtrip(a, b) + } + } + + def assertRoundtrip(a: String, b: String): Unit = { + val original = Conf.parseString(a).get + val revised = Conf.parseString(b).get + val patch = Conf.patch(original, revised) + val expected = Conf.applyPatch(original, revised) + val obtained = Conf.applyPatch(original, patch) + assertEquals(obtained, expected) + } + + property("roundtrip") { + forAll { (a: ConfShow, b: ConfShow) => + assertRoundtrip(a.str, b.str) + } + } + + check( + """ + |ad.da = true + |cc.bd = "dd" + """.stripMargin, + """ + | + |ad.a.dc = false + |ad = "ad" + """.stripMargin + ) + +} diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/AllTheAnnotations.scala b/metaconfig-tests/shared/src/main/scala/metaconfig/AllTheAnnotations.scala similarity index 69% rename from metaconfig-core/shared/src/test/scala/metaconfig/AllTheAnnotations.scala rename to metaconfig-tests/shared/src/main/scala/metaconfig/AllTheAnnotations.scala index 8081fbc9..4da48f2b 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/AllTheAnnotations.scala +++ b/metaconfig-tests/shared/src/main/scala/metaconfig/AllTheAnnotations.scala @@ -36,14 +36,17 @@ object AllTheAnnotations { case class OneParam(param: Int = 82) object OneParam { implicit val surface: Surface[OneParam] = generic.deriveSurface[OneParam] - implicit val codec = generic.deriveCodec[OneParam](OneParam()) + implicit val codec: ConfCodec[OneParam] = + generic.deriveCodec[OneParam](OneParam()) } case class HasOption(b: Option[Int] = None) object HasOption { - implicit val surface = generic.deriveSurface[HasOption] - implicit val decoder = generic.deriveDecoder[HasOption](HasOption()) - implicit val encoder = generic.deriveEncoder[HasOption] + implicit val surface: Surface[HasOption] = generic.deriveSurface[HasOption] + implicit val decoder: ConfDecoder[HasOption] = + generic.deriveDecoder[HasOption](HasOption()) + implicit val encoder: ConfEncoder[HasOption] = + generic.deriveEncoder[HasOption] } case class Curry(a: Int)(b: String) @@ -65,19 +68,22 @@ case class IsIterable( b: Iterable[String] = Iterable.empty ) object IsIterable { - implicit val surface = generic.deriveSurface[IsIterable] - implicit val decoder = generic.deriveDecoder[IsIterable](IsIterable()) - implicit val encoder = generic.deriveEncoder[IsIterable] + implicit val surface: Surface[IsIterable] = generic.deriveSurface[IsIterable] + implicit val decoder: ConfDecoder[IsIterable] = + generic.deriveDecoder[IsIterable](IsIterable()) + implicit val encoder: ConfEncoder[IsIterable] = + generic.deriveEncoder[IsIterable] } case class Nested2(c: String = "nested2", b: OneParam = OneParam()) object Nested2 { - implicit val surface = generic.deriveSurface[Nested2] - implicit val codec = generic.deriveCodec[Nested2](Nested2()) + implicit val surface: Surface[Nested2] = generic.deriveSurface[Nested2] + implicit val codec: ConfCodec[Nested2] = + generic.deriveCodec[Nested2](Nested2()) } case class Nested(a: Int = 31, b: OneParam = OneParam(), c: Nested2 = Nested2()) object Nested { - implicit val surface = generic.deriveSurface[Nested] - implicit val codec = generic.deriveCodec[Nested](Nested()) + implicit val surface: Surface[Nested] = generic.deriveSurface[Nested] + implicit val codec: ConfCodec[Nested] = generic.deriveCodec[Nested](Nested()) } diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/Generators.scala b/metaconfig-tests/shared/src/main/scala/metaconfig/Generators.scala similarity index 88% rename from metaconfig-core/shared/src/test/scala/metaconfig/Generators.scala rename to metaconfig-tests/shared/src/main/scala/metaconfig/Generators.scala index 90623b34..62563f59 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/Generators.scala +++ b/metaconfig-tests/shared/src/main/scala/metaconfig/Generators.scala @@ -4,11 +4,11 @@ import org.scalacheck._ object Generators { import Conf._ - val genIdent = for { + val genIdent: Gen[String] = for { len <- Gen.choose(1, 2) chars <- Gen.listOfN(len, Gen.oneOf('a' to 'd')) } yield chars.mkString - val genKey = for { + val genKey: Gen[String] = for { depth <- Gen.choose(1, 3) idents <- Gen.listOfN(depth, genIdent) } yield idents.mkString(".") @@ -28,5 +28,5 @@ object Generators { } case class ConfShow(str: String) { - def input = Input.String(str) + def input: Input.String = Input.String(str) } diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/ConfDynamicTest.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/ConfDynamicSuite.scala similarity index 87% rename from metaconfig-core/shared/src/test/scala/metaconfig/ConfDynamicTest.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/ConfDynamicSuite.scala index de33ce11..d03bea79 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/ConfDynamicTest.scala +++ b/metaconfig-tests/shared/src/test/scala/metaconfig/ConfDynamicSuite.scala @@ -1,8 +1,8 @@ package metaconfig -class ConfDynamicTest extends munit.FunSuite { +class ConfDynamicSuite extends munit.FunSuite { - val conf = Conf.Obj( + val conf: Conf.Obj = Conf.Obj( "x" -> Conf.Obj("c" -> Conf.Obj("d" -> Conf.Num(2))), "banana" -> Conf.Num(2), "kass" -> Conf.Str("boo") diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/ConfErrorSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/ConfErrorSuite.scala similarity index 100% rename from metaconfig-core/shared/src/test/scala/metaconfig/ConfErrorSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/ConfErrorSuite.scala diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/ConfOptionTest.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/ConfOptionSuite.scala similarity index 92% rename from metaconfig-core/shared/src/test/scala/metaconfig/ConfOptionTest.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/ConfOptionSuite.scala index da46367a..d2559547 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/ConfOptionTest.scala +++ b/metaconfig-tests/shared/src/test/scala/metaconfig/ConfOptionSuite.scala @@ -9,7 +9,7 @@ object Foo { } } -class ConfOptionTest extends munit.FunSuite { +class ConfOptionSuite extends munit.FunSuite { import Conf._ test("simple") { diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfCodecSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfCodecSuite.scala similarity index 100% rename from metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfCodecSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfCodecSuite.scala diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala similarity index 96% rename from metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala index 00afceb4..0fb80c64 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala +++ b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfDecoderSuite.scala @@ -1,9 +1,6 @@ package metaconfig import metaconfig.Conf._ -import metaconfig.annotation._ -import metaconfig.generic.Settings -import metaconfig.generic.Surface class DeriveConfDecoderSuite extends munit.FunSuite { diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfEncoderSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfEncoderSuite.scala similarity index 100% rename from metaconfig-core/shared/src/test/scala/metaconfig/DeriveConfEncoderSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/DeriveConfEncoderSuite.scala diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala similarity index 92% rename from metaconfig-core/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala index 09fd9131..2a7da6ea 100644 --- a/metaconfig-core/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala +++ b/metaconfig-tests/shared/src/test/scala/metaconfig/DeriveSurfaceSuite.scala @@ -25,9 +25,14 @@ class DeriveSurfaceSuite extends munit.FunSuite { } case class Underlying(number: Int) - object Underlying { implicit val surface = generic.deriveSurface[Underlying] } + object Underlying { + implicit val surface: Surface[Underlying] = + generic.deriveSurface[Underlying] + } case class Enclosing(underlying: Underlying) - object Enclosing { implicit val surface = generic.deriveSurface[Enclosing] } + object Enclosing { + implicit val surface: Surface[Enclosing] = generic.deriveSurface[Enclosing] + } test("underlying") { val surface = generic.deriveSurface[Enclosing] val List(underlying :: Nil) = surface.fields diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/EqualitySuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/EqualitySuite.scala similarity index 100% rename from metaconfig-core/shared/src/test/scala/metaconfig/EqualitySuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/EqualitySuite.scala diff --git a/metaconfig-core/shared/src/test/scala/metaconfig/SettingsSuite.scala b/metaconfig-tests/shared/src/test/scala/metaconfig/SettingsSuite.scala similarity index 100% rename from metaconfig-core/shared/src/test/scala/metaconfig/SettingsSuite.scala rename to metaconfig-tests/shared/src/test/scala/metaconfig/SettingsSuite.scala diff --git a/metaconfig-typesafe-config/src/main/scala/metaconfig/typesafeconfig/package.scala b/metaconfig-typesafe-config/src/main/scala/metaconfig/typesafeconfig/package.scala index 62adb056..5b8c06a3 100644 --- a/metaconfig-typesafe-config/src/main/scala/metaconfig/typesafeconfig/package.scala +++ b/metaconfig-typesafe-config/src/main/scala/metaconfig/typesafeconfig/package.scala @@ -1,12 +1,13 @@ package metaconfig package object typesafeconfig { - implicit val typesafeConfigMetaconfigParser = new MetaconfigParser { - override def fromInput(input: Input): Configured[Conf] = input match { - case Input.File(path, _) => - TypesafeConfig2Class.gimmeConfFromFile(path.toFile) - case els => - TypesafeConfig2Class.gimmeConfFromString(new String(els.chars)) + implicit val typesafeConfigMetaconfigParser: MetaconfigParser = + new MetaconfigParser { + override def fromInput(input: Input): Configured[Conf] = input match { + case Input.File(path, _) => + TypesafeConfig2Class.gimmeConfFromFile(path.toFile) + case els => + TypesafeConfig2Class.gimmeConfFromString(new String(els.chars)) + } } - } } diff --git a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/PatchProps.scala b/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/PatchProps.scala deleted file mode 100644 index e33413c9..00000000 --- a/metaconfig-typesafe-config/src/test/scala/metaconfig/typesafeconfig/PatchProps.scala +++ /dev/null @@ -1,56 +0,0 @@ -package metaconfig.typesafeconfig - -import metaconfig.Conf -import metaconfig.ConfOps -import metaconfig.ConfShow -import org.scalacheck.Prop.forAll -import org.scalacheck.Properties -import org.scalameta.logger -import scala.meta.testkit.DiffAssertions -import metaconfig.Generators.argConfShow - -object PatchProps { - // asserts that applying - def checkPatch(a: String, b: String): Boolean = { - val original = Conf.parseString(a).get - val revised = Conf.parseString(b).get - val patch = Conf.patch(original, revised) - val expected = Conf.applyPatch(original, revised) - val obtained = Conf.applyPatch(original, patch) - if (obtained != expected) { - logger.elem( - obtained, - expected, - patch.toString, - Conf.patch(obtained, expected) - ) - } - obtained == expected - } -} - -class PatchProps extends Properties("Patch") { - - property("roundtrip") = forAll { (a: ConfShow, b: ConfShow) => - PatchProps.checkPatch(a.str, b.str) - } - -} -class PatchPropsSuite extends munit.FunSuite { - def check(a: String, b: String): Unit = { - test(a) { assert(PatchProps.checkPatch(clue(a), clue(b))) } - } - - check( - """ - |ad.da = true - |cc.bd = "dd" - """.stripMargin, - """ - | - |ad.a.dc = false - |ad = "ad" - """.stripMargin - ) - -} diff --git a/project/plugins.sbt b/project/plugins.sbt index 0a3d1aaf..346a0c5f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,7 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.6.1") addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.4.31") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.14") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.32") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.0") addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")