Skip to content

Commit

Permalink
Merge pull request #184 from olafurpg/scala-2.13
Browse files Browse the repository at this point in the history
Add support for Scala 2.13
  • Loading branch information
olafurpg authored Aug 25, 2019
2 parents a73bc89 + a23b191 commit 6d1e3be
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 49 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ stages:
jobs:
include:
# default stage is test
- env: TEST="scalafmt"
- name: Scalafmt
script: ./bin/scalafmt --test
- env: TEST="Scala 2.12"
- env: Scala 2.13
script: sbt "++2.13.0 test"
- env: Scala 2.12
script: sbt test plugin/scripted
- env: TEST="Scala 2.11"
script: sbt ++2.11.12 test
- env: TEST="Java 11"
- env: Scala 2.11
script: sbt "++2.11.12 test"
- env: Scala 2.12
script: sbt test plugin/scripted
jdk: openjdk11
- stage: release
Expand Down
74 changes: 55 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
def scala212 = "2.12.8"
def scala212 = "2.12.9"
def scala211 = "2.11.12"
def scala213 = "2.13.0"
inThisBuild(
List(
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211),
crossScalaVersions := List(scala212, scala211, scala213),
scalacOptions ++= List(
"-Xexperimental",
"-deprecation"
Expand All @@ -27,6 +28,7 @@ inThisBuild(
url("https://geirsson.com")
)
),
resolvers += Resolver.sonatypeRepo("public"),
// faster publishLocal:
publishArtifact.in(packageDoc) := sys.env.contains("CI"),
publishArtifact.in(packageSrc) := sys.env.contains("CI")
Expand All @@ -38,15 +40,25 @@ skip in publish := true
crossScalaVersions := Nil

val V = new {
val scalameta = "4.1.0"
val scalameta = "4.2.2"
}

lazy val pprintVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.5.4"
else "0.5.5"
}

lazy val fansiVersion = Def.setting {
if (scalaVersion.value.startsWith("2.11")) "0.2.6"
else "0.2.7"
}

lazy val runtime = project
.settings(
moduleName := "mdoc-runtime",
libraryDependencies ++= List(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"com.lihaoyi" %% "pprint" % "0.5.2"
"com.lihaoyi" %% "pprint" % pprintVersion.value
)
)

Expand All @@ -73,9 +85,9 @@ lazy val mdoc = project
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0",
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scalameta" %% "scalameta" % V.scalameta,
"com.geirsson" %% "metaconfig-typesafe-config" % "0.9.1",
"com.geirsson" %% "metaconfig-typesafe-config" % "0.9.4",
"com.vladsch.flexmark" % "flexmark-all" % "0.40.4",
"com.lihaoyi" %% "fansi" % "0.2.5",
"com.lihaoyi" %% "fansi" % fansiVersion.value,
"io.methvin" % "directory-watcher" % "0.8.0",
"me.xdrop" % "fuzzywuzzy" % "1.1.10", // for link hygiene "did you mean?"
// live reload
Expand All @@ -93,14 +105,31 @@ lazy val testsInput = project
skip in publish := true
)

val isScala213 = Def.setting {
VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector(">=2.13"))
}

def scala212LibraryDependencies(deps: List[ModuleID]) = List(
libraryDependencies ++= {
if (isScala213.value) Nil
else deps
}
)

val jsdocs = project
.in(file("tests/jsdocs"))
.settings(
skip in publish := true,
scalaJSModuleKind := ModuleKind.CommonJSModule,
libraryDependencies ++= {
if (isScala213.value) Nil
else
List(
"in.nvilla" %%% "monadic-html" % "0.4.0-RC1"
)
},
libraryDependencies ++= List(
"in.nvilla" %%% "monadic-html" % "0.4.0-RC1",
"org.scala-js" %%% "scalajs-dom" % "0.9.6"
"org.scala-js" %%% "scalajs-dom" % "0.9.7"
),
scalaJSUseMainModuleInitializer := true,
npmDependencies in Compile ++= List(
Expand All @@ -114,14 +143,17 @@ lazy val unit = project
.in(file("tests/unit"))
.settings(
skip in publish := true,
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.8"),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
resolvers += Resolver.bintrayRepo("cibotech", "public"),
scala212LibraryDependencies(
List(
"com.cibo" %% "evilplot" % "0.6.0"
)
),
libraryDependencies ++= List(
"com.cibo" %% "evilplot" % "0.6.0",
"co.fs2" %% "fs2-core" % "0.10.4",
"org.scalacheck" %% "scalacheck" % "1.13.5" % Test,
"org.scalacheck" %% "scalacheck" % "1.13.5" % Test,
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
"co.fs2" %% "fs2-core" % "1.1.0-M1",
"org.scalacheck" %% "scalacheck" % "1.14.0" % Test,
"org.scalatest" %% "scalatest" % "3.0.8" % Test,
"org.scalameta" %% "testkit" % V.scalameta % Test
),
// forking causes https://github.com/scalatest/scalatest/issues/556
Expand All @@ -144,8 +176,8 @@ lazy val plugin = project
moduleName := "sbt-mdoc",
libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.11.3",
"org.scalacheck" %% "scalacheck" % "1.13.5" % Test,
"org.scalameta" %% "testkit" % "4.0.0-M11" % Test
"org.scalacheck" %% "scalacheck" % "1.14.0" % Test,
"org.scalameta" %% "testkit" % V.scalameta % Test
),
resourceGenerators.in(Compile) += Def.task {
val out =
Expand Down Expand Up @@ -174,9 +206,11 @@ lazy val js = project
.in(file("mdoc-js"))
.settings(
moduleName := "mdoc-js",
libraryDependencies ++= List(
"org.scala-js" % "scalajs-compiler" % "0.6.26" cross CrossVersion.full,
"org.scala-js" %% "scalajs-tools" % "0.6.26"
scala212LibraryDependencies(
List(
"org.scala-js" % "scalajs-compiler" % "0.6.28" cross CrossVersion.full,
"org.scala-js" %% "scalajs-tools" % "0.6.28"
)
)
)
.dependsOn(mdoc)
Expand All @@ -185,6 +219,7 @@ lazy val lsp = project
.in(file("mdoc-lsp"))
.settings(
moduleName := "mdoc-lsp",
crossScalaVersions := List(scala212),
libraryDependencies ++= List(
"org.eclipse.lsp4j" % "org.eclipse.lsp4j" % "0.5.0",
"com.outr" %% "scribe" % "2.6.0",
Expand All @@ -197,6 +232,7 @@ lazy val docs = project
.in(file("mdoc-docs"))
.settings(
moduleName := "mdoc-docs",
crossScalaVersions := List(scala212),
skip in publish :=
!scalaVersion.value.startsWith("2.12") ||
version.in(ThisBuild).value.endsWith("-SNAPSHOT"),
Expand Down
2 changes: 1 addition & 1 deletion mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ final class MainOps(
}

def clearScreen(): Unit = {
print("\033[H\033[2J")
print("\u001b[H\u001b[2J")
}

def waitingForFileChanges(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mdoc.internal.pos.PositionSyntax
import mdoc.internal.pos.PositionSyntax._
import mdoc.internal.pos.TokenEditDistance
import scala.collection.JavaConverters._
import scala.collection.Seq
import scala.meta._
import scala.meta.inputs.Input
import scala.meta.inputs.Position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mdoc.internal.pos
import difflib._
import difflib.myers.Equalizer
import scala.annotation.tailrec
import scala.collection.Seq
import scala.meta._
import mdoc.internal.pos.PositionSyntax._

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ addSbtCoursier
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.2.2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.14.0")
libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.11.3",
Expand Down
2 changes: 1 addition & 1 deletion project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M9")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "2.0.0-RC3-3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tests.markdown

import mdoc.PostModifier
import mdoc.PostModifierContext

class EvilplotPostModifier extends PostModifier {
val name = "evilplot"
def process(ctx: PostModifierContext): String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mdoc.modifiers

class JsModifier extends mdoc.PreModifier {
val name: String = "js"
def process(ctx: mdoc.PreModifierContext): String = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ package tests.markdown
import mdoc.PostModifier
import mdoc.PostModifierContext

class BulletPostModifier extends PostModifier {
val name = "bullet"
override def process(ctx: PostModifierContext): String = {
ctx.lastValue match {
case n: Int =>
1.to(n).map(i => s"$i. Bullet").mkString("\n")
case els =>
ctx.reporter.error(s"expected int runtime value. Obtained $els")
""
}
}
}

class PostModifierSuite extends BaseMarkdownSuite {
check(
"basic",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tests.markdown

import mdoc.PostModifier
import mdoc.PostModifierContext

class EvilplotPostModifier extends PostModifier {
val name = "evilplot"
def process(ctx: PostModifierContext): String = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mdoc.modifiers

class JsModifier extends mdoc.PreModifier {
val name: String = "js"
def process(ctx: mdoc.PreModifierContext): String = ""
}
17 changes: 16 additions & 1 deletion tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ class AsyncSuite extends BaseMarkdownSuite {
| at repl.Session$App$.<init>(timeout.md:11)
| at repl.Session$App$.<clinit>(timeout.md)
| ... 1 more
""".stripMargin
|""".stripMargin,
"2.13" ->
"""|error: timeout.md:4:1: Future timed out after [10 milliseconds]
|Await.result(Future(Thread.sleep(1000)), Duration("10ms"))
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|java.lang.ExceptionInInitializerError
| at repl.Session$.app(timeout.md:3)
|Caused by: java.util.concurrent.TimeoutException: Future timed out after [10 milliseconds]
| at scala.concurrent.impl.Promise$DefaultPromise.tryAwait0(Promise.scala:212)
| at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:225)
| at scala.concurrent.Await$.$anonfun$result$1(package.scala:200)
| at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:62)
| at scala.concurrent.Await$.result(package.scala:124)
| at repl.Session$App$.<clinit>(timeout.md:11)
| ... 1 more
|""".stripMargin
)
)

Expand Down
10 changes: 8 additions & 2 deletions tests/unit/src/test/scala/tests/markdown/BaseMarkdownSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
)
)
.withProperties(MdocProperties.default(PathIO.workingDirectory))

def postProcessObtained: Map[String, String => String] = Map.empty
def postProcessExpected: Map[String, String => String] = Map.empty
private val myStdout = new ByteArrayOutputStream()
private def newReporter(): ConsoleReporter = {
new ConsoleReporter(new PrintStream(myStdout))
Expand Down Expand Up @@ -68,8 +71,11 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
val input = Input.VirtualFile(name + ".md", original)
Markdown.toMarkdown(input, getMarkdownSettings(context), reporter, settings)
assert(reporter.hasErrors, "Expected errors but reporter.hasErrors=false")
val obtainedErrors = fansi.Str(myStdout.toString).plainText.trimLineEnds
assertNoDiffOrPrintExpected(obtainedErrors, Compat(expected, compat))
val obtainedErrors = Compat.postProcess(
fansi.Str(myStdout.toString).plainText.trimLineEnds,
postProcessObtained
)
assertNoDiffOrPrintExpected(obtainedErrors, Compat(expected, compat, postProcessExpected))
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/BulletPostModifier.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tests.markdown

import mdoc.PostModifier
import mdoc.PostModifierContext

class BulletPostModifier extends PostModifier {
val name = "bullet"
override def process(ctx: PostModifierContext): String = {
ctx.lastValue match {
case n: Int =>
1.to(n).map(i => s"$i. Bullet").mkString("\n")
case els =>
ctx.reporter.error(s"expected int runtime value. Obtained $els")
""
}
}
}
25 changes: 23 additions & 2 deletions tests/unit/src/test/scala/tests/markdown/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@ import mdoc.internal.BuildInfo

object Compat {
def isScala212: Boolean = BuildInfo.scalaVersion.startsWith("2.12")
def apply(default: String, compat: Map[String, String]): String = {
compat
def postProcess(default: String, compat: Map[String, String => String]): String = {
val processor = compat
.get(BuildInfo.scalaVersion)
.orElse(compat.get(BuildInfo.scalaBinaryVersion))
processor match {
case None => default
case Some(fn) => fn(default)
}
}
def apply(
default: String,
compat: Map[String, String],
postProcess: Map[String, String => String] = Map.empty
): String = {
val result = compat
.get(BuildInfo.scalaVersion)
.orElse(compat.get(BuildInfo.scalaBinaryVersion))
.getOrElse(
BuildInfo.scalaBinaryVersion match {
case "2.11" =>
default
.replaceAllLiterally("Predef.scala:288", "Predef.scala:230")
case "2.12" =>
default
.replaceAllLiterally("package.scala:219", "package.scala:220")
case "2.13" =>
default
.replaceAllLiterally("<init>", "<clinit>")
.replaceAllLiterally("Predef.scala:288", "Predef.scala:347")
case _ => default
}
)
this.postProcess(result, postProcess)
}
}
12 changes: 12 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ package tests.markdown

class ErrorSuite extends BaseMarkdownSuite {

override def postProcessObtained: Map[String, String => String] = Map(
"2.13" -> { old =>
old.linesIterator.filterNot(_.startsWith("did you mean")).mkString("\n")
}
)

override def postProcessExpected: Map[String, String => String] = Map(
"2.13" -> { old =>
old.linesIterator.filterNot(_.contains("<clinit>(crash.md)")).mkString("\n")
}
)

checkError(
"crash",
"""
Expand Down
Loading

0 comments on commit 6d1e3be

Please sign in to comment.