Skip to content

Commit

Permalink
Refactor the build for consistency with other Scalameta builds
Browse files Browse the repository at this point in the history
* tests live in `tests` project
* enable Scalafix `ExplicitResultTypes` and `RemoveUnused` rules
* enforce scalafmt and scalafix in CI
* use MUnit for ScalaCheck property tests
* use `*Suite` suffix for test suites
  • Loading branch information
Olafur Pall Geirsson committed Apr 18, 2020
1 parent 62477af commit f27e4c6
Show file tree
Hide file tree
Showing 63 changed files with 363 additions and 423 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rules = [
RemoveUnused,
ExplicitResultTypes,
]

ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = false
File renamed without changes.
132 changes: 72 additions & 60 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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")
Expand All @@ -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
Expand Down
36 changes: 0 additions & 36 deletions metaconfig-core/jvm/src/test/scala/metaconfig/CodecProps.scala

This file was deleted.

16 changes: 0 additions & 16 deletions metaconfig-core/jvm/src/test/scala/metaconfig/cli/Site.scala

This file was deleted.

4 changes: 1 addition & 3 deletions metaconfig-core/shared/src/main/scala/metaconfig/Conf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package metaconfig

import scala.language.experimental.macros
import scala.language.higherKinds
import scala.collection.compat._
import scala.reflect.ClassTag
Expand Down
8 changes: 5 additions & 3 deletions metaconfig-core/shared/src/main/scala/metaconfig/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ sealed abstract class Input(val path: String, val text: String)
object Input {

case object None extends Input("<none>", "") {
override def toString = "Input.None"
override def toString: Predef.String = "Input.None"
}

final case class String(override val text: Predef.String)
extends Input("<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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit f27e4c6

Please sign in to comment.