Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Scala 2.11 #152

Merged
merged 5 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ jobs:
# default stage is test
- env: TEST="scalafmt"
script: ./bin/scalafmt --test
- env: TEST="sbt test"
- env: TEST="Scala 2.12"
script: sbt test plugin/scripted
- env: TEST="sbt test"
- env: TEST="Scala 2.11"
script: sbt ++2.11.12 test
- env: TEST="Java 11"
script: sbt test plugin/scripted
jdk: openjdk11
- stage: release
Expand Down
15 changes: 11 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
def scala212 = "2.12.8"
def scala211 = "2.11.12"
inThisBuild(
List(
scalaVersion := "2.12.8",
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211),
scalacOptions ++= List(
"-Xexperimental",
"-deprecation"
),
organization := "org.scalameta",
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
Expand Down Expand Up @@ -28,6 +35,8 @@ inThisBuild(

name := "mdocRoot"
skip in publish := true
crossScalaVersions := Nil

val V = new {
val scalameta = "4.1.0"
}
Expand Down Expand Up @@ -105,9 +114,6 @@ lazy val unit = project
.in(file("tests/unit"))
.settings(
skip in publish := true,
scalacOptions ++= List(
"-deprecation"
),
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.8"),
resolvers += Resolver.bintrayRepo("cibotech", "public"),
libraryDependencies ++= List(
Expand All @@ -134,6 +140,7 @@ lazy val plugin = project
.settings(
sbtPlugin := true,
sbtVersion in pluginCrossBuild := "1.0.0",
crossScalaVersions := List(scala212),
moduleName := "sbt-mdoc",
libraryDependencies ++= List(
"org.jsoup" % "jsoup" % "1.11.3",
Expand Down
51 changes: 27 additions & 24 deletions tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package tests.cli

import tests.markdown.Compat

class ScalacOptionsSuite extends BaseCliSuite {
checkCli(
"-Ywarn-unused-import",
"""
|/index.md
|# Hello
|```scala mdoc
|import scala.concurrent.Future
|```
if (Compat.isScala212)
checkCli(
"-Ywarn-unused-import",
"""
|/index.md
|# Hello
|```scala mdoc
|import scala.concurrent.Future
|```
""".stripMargin,
"",
extraArgs = Array(
"--report-relative-paths",
"--scalac-options",
"-Ywarn-unused -Xfatal-warnings"
),
expectedExitCode = 1,
onStdout = { out =>
val expected =
"""
|warning: index.md:3:1: Unused import
|import scala.concurrent.Future
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^""".stripMargin
assert(out.contains(expected))
}
)
"",
extraArgs = Array(
"--report-relative-paths",
"--scalac-options",
"-Ywarn-unused -Xfatal-warnings"
),
expectedExitCode = 1,
onStdout = { out =>
val expected =
"""
|warning: index.md:3:1: Unused import
|import scala.concurrent.Future
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^""".stripMargin
assert(out.contains(expected))
}
)

checkCli(
"kind-projector",
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/AsyncSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,25 @@ class AsyncSuite extends BaseMarkdownSuite {
| at repl.Session$App$.<init>(timeout.md:11)
| at repl.Session$App$.<clinit>(timeout.md)
| ... 1 more
""".stripMargin,
compat = Map(
"2.11" ->
"""|error: timeout.md:4:1: Futures 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: Futures timed out after [10 milliseconds]
| at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:223)
| at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:227)
| at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:190)
| at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
| at scala.concurrent.Await$.result(package.scala:190)
| at repl.Session$App$.<init>(timeout.md:11)
| at repl.Session$App$.<clinit>(timeout.md)
| ... 1 more
""".stripMargin
)
)

check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
name: String,
original: String,
expected: String,
settings: Settings = baseSettings
settings: Settings = baseSettings,
compat: Map[String, String] = Map.empty
): Unit = {
test(name) {
val reporter = newReporter()
Expand All @@ -68,7 +69,7 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
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, expected)
assertNoDiffOrPrintExpected(obtainedErrors, Compat(expected, compat))
}
}

Expand Down Expand Up @@ -100,7 +101,7 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
settings: Settings = baseSettings
): Unit = {
checkCompiles(name, original, settings, obtained => {
assertNoDiffOrPrintExpected(obtained, expected)
assertNoDiffOrPrintExpected(obtained, Compat(expected, Map.empty))
})
}

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

import mdoc.internal.BuildInfo

object Compat {
def isScala212: Boolean = BuildInfo.scalaVersion.startsWith("2.12")
def apply(default: String, compat: Map[String, String]): String = {
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 _ => default
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ class MarkdownCompilerSuite extends FunSuite with DiffAssertions {
def check(name: String, original: String, expected: String): Unit =
check(name, original :: Nil, expected)

def check(name: String, original: List[String], expected: String): Unit = {
def check(
name: String,
original: List[String],
expected: String,
compat: Map[String, String] = Map.empty
): Unit = {
test(name) {
val inputs = original.map(s => Input.String(s))
val obtained = Renderer.render(inputs, compiler, reporter, name + ".md", ReplVariablePrinter)
assertNoDiff(obtained, expected)
assertNoDiff(
obtained,
Compat(expected, compat)
)
}
}

Expand All @@ -46,7 +54,20 @@ class MarkdownCompilerSuite extends FunSuite with DiffAssertions {
|val y = x.length
|// y: Int = 10
|```
""".stripMargin
""".stripMargin,
compat = Map(
"2.11" ->
"""
|```scala
|val x = 1.to(10)
|// x: Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|```
|```scala
|val y = x.length
|// y: Int = 10
|```
""".stripMargin
)
)

check(
Expand Down