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 tests on Windows CI #512

Merged
merged 1 commit into from
Jun 9, 2021
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* eol=lf
*.png eol=autocrlf
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ jobs:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v11
- run: sbt '++2.12.13 docs/mdoc'
test-windows:
name: "Windows"
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v10
with:
java-version: adopt@1.11
- run: sbt '++2.13.5 test'
shell: bash
test:
name: ${{ matrix.command }} ${{ matrix.java }}
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-Xss4m
-Xms1G
-Xmx4G
-Xmx2G
-XX:ReservedCodeCacheSize=1024m
-XX:+TieredCompilation
-XX:+CMSClassUnloadingEnabled
Expand Down
4 changes: 4 additions & 0 deletions cli/src/main/scala/mdoc/internal/cli/CliEnrichments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ import coursierapi.Dependency
import scala.meta.internal.io.FileIO
import scala.meta.internal.inputs._
import java.io.PrintStream
import scala.util.Try

trait CliEnrichments {
implicit class XtensionInputMdoc(input: Input) {
def filename: String =
input match {
case s: Input.Slice => s.input.filename
case f: Input.File => f.path.filename
case v: Input.VirtualFile =>
Try(AbsolutePath(Paths.get(v.path)).filename).getOrElse(v.path)
case _ => input.syntax
}
def relativeFilename(sourceroot: AbsolutePath): RelativePath =
Expand Down
11 changes: 7 additions & 4 deletions mdoc-sbt/src/test/scala/tests/RelativizeSuite.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package tests

import java.nio.file.Paths
import munit.TestOptions
import munit.FunSuite
import munit.TestOptions
import sbtdocusaurus.internal.Relativize

import java.nio.file.Files
import java.nio.file.Paths
import scala.meta.internal.io.PathIO
import scala.meta.io.AbsolutePath
import scala.meta.testkit.StringFS

class RelativizeSuite extends FunSuite {

def check(name: TestOptions, original: String, expected: String): Unit = {
test(name) {
val root = StringFS.fromString(original)
val root = AbsolutePath(Files.createTempDirectory("mdoc"))
StringFS.fromString(original, root)
Relativize.htmlSite(root.toNIO)
root.toRelative(PathIO.workingDirectory).toURI(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root might be on C: while working dir on D:

val isTrivial = Set(
"<html>",
"<body>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class MarkdownCompiler(
}

private def toSource(input: Input): BatchSourceFile = {
val filename = Paths.get(input.syntax).getFileName.toString
new BatchSourceFile(filename, new String(input.chars))
new BatchSourceFile(input.filename, new String(input.chars))
}

def shutdown(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class MarkdownCompiler(
}

private def toSource(input: Input): SourceFile = {
val filename = Paths.get(input.syntax).getFileName.toString
SourceFile.virtual(filename, new String(input.chars))
SourceFile.virtual(input.filename, new String(input.chars))
}

private def toInput(sourceFile: ISourceFile): Input = {
Expand Down
17 changes: 11 additions & 6 deletions tests/unit/src/main/scala/tests/cli/BaseCliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ abstract class BaseCliSuite extends BaseSuite {
override def postProcessObtained: Map[Compat.ScalaVersion, String => String] =
Map(
Compat.All -> { old =>
old
.replace(out().toString(), "<output>")
.replace(in().toString(), "<input>")
.linesIterator
.filterNot(line => line.startsWith("info: Compiled in"))
.mkString("\n")
{
val outDir = out().toString().replace("\\", "/")
val inDir = in().toString().replace("\\", "/")
old
.replace("\\", "/")
.replace(outDir, "<output>")
.replace(inDir, "<input>")
.linesIterator
.filterNot(line => line.startsWith("info: Compiled in"))
.mkString("\n")
}
}
)
override def munitFixtures: Seq[Fixture[_]] = List(in, out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class BaseMarkdownSuite extends tests.BaseSuite {
test(name) {
val reporter = newReporter()
val context = newContext(settings, reporter)
val input = Input.VirtualFile(name.name + ".md", original)
val input = Input.VirtualFile(name.name.replace(':', '-') + ".md", original)
val file = InputFile.fromRelativeFilename(input.path, settings)
Markdown.toMarkdown(input, context, file, baseSettings.site, reporter, settings)
assert(reporter.hasErrors, "Expected errors but reporter.hasErrors=false")
Expand All @@ -90,7 +90,7 @@ abstract class BaseMarkdownSuite extends tests.BaseSuite {
test(name) {
val reporter = newReporter()
val context = newContext(settings, reporter)
val input = Input.VirtualFile(name.name + ".md", original)
val input = Input.VirtualFile(name.name.replace(":", "-") + ".md", original)
val file = InputFile.fromRelativeFilename(input.path, settings)
val obtained =
Markdown.toMarkdown(input, context, file, baseSettings.site, reporter, settings)
Expand Down
54 changes: 37 additions & 17 deletions tests/unit/src/test/scala/tests/imports/DependencySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests.imports

import tests.markdown.BaseMarkdownSuite
import tests.markdown.Compat
import scala.util.Properties

class DependencySuite extends BaseMarkdownSuite {
val userHome = System.getProperty("user.home")
Expand Down Expand Up @@ -79,23 +80,42 @@ class DependencySuite extends BaseMarkdownSuite {
|import $dep.`org.scalameta::munit:0.7.5` // resolves OK
|println(42)
|```
| """.stripMargin,
"""|error: dep-error.md:3:49: Error downloading org.scalameta:foobar:1.2.1
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/foobar/1.2.1/foobar-1.2.1.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:4:13: Error downloading org.scalameta:not-exists_2.13.6:2.3.4
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/not-exists_2.13.6/2.3.4/not-exists_2.13.6-2.3.4.pom
|import $dep.`org.scalameta:::not-exists:2.3.4`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:3:13: Error downloading org.scalameta:mmunit_2.13:2.3.4
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/mmunit_2.13/2.3.4/mmunit_2.13-2.3.4.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|""".stripMargin
| """.stripMargin, {
if (Properties.isWin)
"""|error: dep-error.md:4:13: Error downloading org.scalameta:not-exists_2.13.5:2.3.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a lot of issues with this test, seems that on each version/platform the order is different, but it should fine now. We might split it into different tests in the future to avoid issues.

|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/not-exists_2.13.5/2.3.4/not-exists_2.13.5-2.3.4.pom
|import $dep.`org.scalameta:::not-exists:2.3.4`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:3:49: Error downloading org.scalameta:foobar:1.2.1
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/foobar/1.2.1/foobar-1.2.1.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:3:13: Error downloading org.scalameta:mmunit_2.13:2.3.4
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/mmunit_2.13/2.3.4/mmunit_2.13-2.3.4.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|""".stripMargin
else
"""|error: dep-error.md:3:49: Error downloading org.scalameta:foobar:1.2.1
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/foobar/1.2.1/foobar-1.2.1.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:4:13: Error downloading org.scalameta:not-exists_2.13.6:2.3.4
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/not-exists_2.13.6/2.3.4/not-exists_2.13.6-2.3.4.pom
|import $dep.`org.scalameta:::not-exists:2.3.4`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|error: dep-error.md:3:13: Error downloading org.scalameta:mmunit_2.13:2.3.4
|<redacted user.home>
| not found: https://repo1.maven.org/maven2/org/scalameta/mmunit_2.13/2.3.4/mmunit_2.13-2.3.4.pom
|import $dep.`org.scalameta::mmunit:2.3.4`, $dep.`org.scalameta:foobar:1.2.1`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|""".stripMargin
}
)

checkError(
Expand Down
15 changes: 8 additions & 7 deletions tests/unit/src/test/scala/tests/imports/FileSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests.imports
import tests.markdown.BaseMarkdownSuite
import tests.cli.BaseCliSuite
import scala.meta.io.RelativePath
import java.io.File

class FileSuite extends BaseCliSuite {

Expand Down Expand Up @@ -126,10 +127,10 @@ class FileSuite extends BaseCliSuite {
assertNoDiff(
stdout,
"""|info: Compiling 3 files to <output>
|error: <input>/readme.md:2:14: illegal cyclic dependency. To fix this problem, refactor the code so that no transitive $file imports end up depending on the original file.
| -- root --> <input>/readme.md:1
| -- depends on --> <input>/hello1.sc:0
| -- depends on --> <input>/hello2.sc:0
|error: readme.md:2:14: illegal cyclic dependency. To fix this problem, refactor the code so that no transitive $file imports end up depending on the original file.
| -- root --> readme.md:1
| -- depends on --> hello1.sc:0
| -- depends on --> hello2.sc:0
| -- cycle --> <input>/hello1.sc
|import $file.hello1
| ^^^^^^
Expand Down Expand Up @@ -170,7 +171,7 @@ class FileSuite extends BaseCliSuite {
| required: Int
|val number: Int = ""
| ^^
|error: <input>/readme.md:3:22: type mismatch;
|error: readme.md:3:22: type mismatch;
| found : String("")
| required: Int
|val something: Int = ""
Expand Down Expand Up @@ -262,7 +263,7 @@ class FileSuite extends BaseCliSuite {
assertNoDiff(
stdout,
"""|info: Compiling 2 files to <output>
|error: <input>/readme.md:2:16: unimports are not supported for $file imports. To fix this problem, remove the unimported symbol.
|error: readme.md:2:16: unimports are not supported for $file imports. To fix this problem, remove the unimported symbol.
|import $file.{ hello0 => _ }
| ^^^^^^^^^^^
|""".stripMargin
Expand All @@ -288,7 +289,7 @@ class FileSuite extends BaseCliSuite {
assertNoDiff(
stdout,
"""|info: Compiling 2 files to <output>
|error: <input>/readme.md:2:14: wildcards are not supported for $file imports. To fix this problem, explicitly import files using the `import $file.FILENAME` syntax.
|error: readme.md:2:14: wildcards are not supported for $file imports. To fix this problem, explicitly import files using the `import $file.FILENAME` syntax.
|import $file._
| ^
|""".stripMargin
Expand Down
23 changes: 4 additions & 19 deletions tests/unit/src/test/scala/tests/markdown/ErrorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ErrorSuite extends BaseMarkdownSuite {
line.startsWith("did you mean") ||
line.contains("(crash.md")
}
// Predef lines change between versions and platforms
.map(line => line.replaceAll("Predef\\.scala:\\d\\d\\d", "Predef.scala:???"))
.mkString("\n")
}
)
Expand All @@ -32,25 +34,8 @@ class ErrorSuite extends BaseMarkdownSuite {
|x + y + z
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:288)
|""".stripMargin,
compat = Map(
Compat.Scala213 ->
"""|error: crash.md:10:1: an implementation is missing
|x + y + z
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
|<TAB>at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
|""".stripMargin.replace("<TAB>", tab),
Compat.Scala3 ->
// Anton: for some reason, the compiler(?) returns tab in this particular place
"""|error: crash.md:10:1: an implementation is missing
|x + y + z
|^^^^^^^^^
|scala.NotImplementedError: an implementation is missing
|<TAB>at scala.Predef$.$qmark$qmark$qmark(Predef.scala:345)
""".stripMargin.replace("<TAB>", tab)
)
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:???)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this was a TAB in each version. I also changed Predef lines to ??? since it seems this changes very often.

|""".stripMargin
)

checkError(
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/src/test/scala/tests/markdown/MultiModsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class MultiModsSuite extends BaseMarkdownSuite {
|val x = 2
|```
""".stripMargin,
"""|error: silent:invisible.md:2:15: invalid combination of modifiers 'silent' and 'invisible'
"""|error: silent-invisible.md:2:15: invalid combination of modifiers 'silent' and 'invisible'
|```scala mdoc:reset:silent:invisible
| ^^^^^^^^^^^^^^^^^^^^^^
""".stripMargin
Expand All @@ -115,7 +115,7 @@ class MultiModsSuite extends BaseMarkdownSuite {
|val x = 2
|```
""".stripMargin,
"""|error: fail:crash.md:2:15: invalid combination of modifiers 'crash' and 'fail'
"""|error: fail-crash.md:2:15: invalid combination of modifiers 'crash' and 'fail'
|```scala mdoc:reset:fail:crash
| ^^^^^^^^^^^^^^^^
""".stripMargin
Expand All @@ -128,7 +128,7 @@ class MultiModsSuite extends BaseMarkdownSuite {
|val x = 2
|```
""".stripMargin,
"""|error: compile-only:passthrough.md:2:15: compile-only cannot be used in combination with passthrough
"""|error: compile-only-passthrough.md:2:15: compile-only cannot be used in combination with passthrough
|```scala mdoc:compile-only:passthrough
| ^^^^^^^^^^^^^^^^^^^^^^^^
""".stripMargin
Expand All @@ -155,7 +155,7 @@ class MultiModsSuite extends BaseMarkdownSuite {
|val x = "* 43"
|```
""".stripMargin,
"""|error: nest:reset.md:5:15: the modifier 'nest' is redundant when used in combination with 'reset'. To fix this error, remove 'nest'
"""|error: nest-reset.md:5:15: the modifier 'nest' is redundant when used in combination with 'reset'. To fix this error, remove 'nest'
|```scala mdoc:nest:reset
| ^^^^^^^^^^
|""".stripMargin
Expand All @@ -168,7 +168,7 @@ class MultiModsSuite extends BaseMarkdownSuite {
|val x = 2
|```
""".stripMargin,
"""|error: compile-only:multiple.md:2:15: compile-only cannot be used in combination with to-string, silent
"""|error: compile-only-multiple.md:2:15: compile-only cannot be used in combination with to-string, silent
|```scala mdoc:compile-only:to-string:silent
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
""".stripMargin
Expand Down