Skip to content

Commit

Permalink
windows: make tests run
Browse files Browse the repository at this point in the history
- need to replace '\r\n' with '\n' some places because ST normalized newlines
- need to compare diffs without newlines and whitespace (matches digest logic)
  • Loading branch information
oyvindberg committed Nov 15, 2022
1 parent 6789cd6 commit a829a36
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,16 @@ trait ImporterHarness extends AnyFunSuite {
GitLock.synchronized(%("git", "add", checkFolder))
}

Try(%%("diff", "-Naur", checkFolder, targetFolder)) match {
Try(%%("diff", "-NaurwB", checkFolder, targetFolder)) match {
case Success(_) => if (run.update) pending else succeed
case Failure(th: ShelloutException) =>
val diff = %%("diff", "-r", checkFolder, targetFolder).out.string
fail(s"Output for test $testFolder was not as expected : $diff", th)
try {
val diff = %%("diff", "-rwB", checkFolder, targetFolder).out.string
fail(s"Output for test $testFolder was not as expected : $diff", th)
} catch {
// not serializable
case th: ShelloutException => sys.error(th.getMessage)
}
case Failure(th) => throw th
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ContentForPublishTest extends AnyFunSuite with Matchers {
<dependency org="deporg" name="departifactid_sjs1_2.13" rev="depversion" conf="compile-&gt;default(compile)"/>
<dependency org="externaldeporg" name="externaldepartifact_sjs1_2.13" rev="externaldepversion" conf="compile-&gt;default(compile)"/>
</dependencies>
</ivy-module>""",
</ivy-module>""".replace("\r\n", "\n"),
)
}

Expand Down Expand Up @@ -126,7 +126,7 @@ class ContentForPublishTest extends AnyFunSuite with Matchers {
<version>externaldepversion</version>
</dependency>
</dependencies>
</project>""",
</project>""".replace("\r\n", "\n"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package org.scalablytyped.converter.internal
package ts
package parser

import org.scalablytyped.converter.internal.ts.parser.TsLexer.{CommentLineToken, DirectiveToken}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import java.io.File

final class CommentTests extends AnyFunSuite with Matchers {
import ParserHarness._

Expand All @@ -15,7 +16,9 @@ final class CommentTests extends AnyFunSuite with Matchers {
| * Width of the tangible instance, length on the X-axis in 3D.
| */""".stripMargin
shouldParseAs(content, TsParser.lexical.comment)(
TsParser.lexical.CommentBlockToken(content),
TsParser.lexical.CommentBlockToken(
content.replace("\r\n", "\n"),
),
)
}

Expand Down Expand Up @@ -67,7 +70,7 @@ final class CommentTests extends AnyFunSuite with Matchers {
"""/**
| * A react component that renders a row of the grid
| */
|""".stripMargin,
|""".stripMargin.replace("\r\n", "\n"),
)

value.comments.cs.zip(expecteds.cs).foreach {
Expand All @@ -86,35 +89,35 @@ final class CommentTests extends AnyFunSuite with Matchers {
shouldParseAs(
"/// <reference path=\"../bluebird/bluebird-2.0.d.ts\" />",
TsParser.lexical.directive,
)(DirectiveToken("reference", "path", "../bluebird/bluebird-2.0.d.ts"))
)(TsLexer.DirectiveToken("reference", "path", "../bluebird/bluebird-2.0.d.ts"))
}

test("directive three") {
shouldParseAs(
"/// <reference path='../bluebird/bluebird-2.0.d.ts' />",
TsParser.lexical.directive,
)(DirectiveToken("reference", "path", "../bluebird/bluebird-2.0.d.ts"))
)(TsLexer.DirectiveToken("reference", "path", "../bluebird/bluebird-2.0.d.ts"))
}

test("directive lib") {
shouldParseAs(
"""/// <reference lib="dom.iterable" />""",
TsParser.lexical.directive,
)(DirectiveToken("reference", "lib", "dom.iterable"))
)(TsLexer.DirectiveToken("reference", "lib", "dom.iterable"))
}

test("directive no-default-lib") {
shouldParseAs(
"""/// <reference no-default-lib="true"/>""",
TsParser.lexical.directive,
)(DirectiveToken("reference", "no-default-lib", "true"))
)(TsLexer.DirectiveToken("reference", "no-default-lib", "true"))
}

test("amd-module") {
shouldParseAs(
"""/// <amd-module name="angular/packages/zone.js/lib/zone"/>""",
TsParser.lexical.directive,
)(DirectiveToken("amd-module", "name", "angular/packages/zone.js/lib/zone"))
)(TsLexer.DirectiveToken("amd-module", "name", "angular/packages/zone.js/lib/zone"))
}

test("parameter comments") {
Expand Down Expand Up @@ -264,19 +267,19 @@ final class CommentTests extends AnyFunSuite with Matchers {
}

test("handle stray references") {
withTsFile("parsertests/graphql.d.ts") { content =>
withTsFile(s"parsertests${File.separator}graphql.d.ts") { content =>
parseAs(content, TsParser.tsContainerOrDecls)
}
}

test("trailing comments") {
withTsFile("parsertests/egg.d.ts") { content =>
withTsFile(s"parsertests${File.separator}egg.d.ts") { content =>
parseAs(content, TsParser.tsContainerOrDecls)
}
}

test("trailing comments (2)") {
withTsFile("parsertests/emissary.d.ts") { content =>
withTsFile(s"parsertests${File.separator}emissary.d.ts") { content =>
parseAs(content, TsParser.parsedTsFile)
}
}
Expand All @@ -295,7 +298,7 @@ final class CommentTests extends AnyFunSuite with Matchers {
}

test("handle trailing comments in block") {
withTsFile("parsertests/knockout.d.ts") { content =>
withTsFile(s"parsertests${File.separator}knockout.d.ts") { content =>
parseAs(content, TsParser.tsContainerOrDecls)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import org.scalablytyped.converter.internal.ts.JsLocation.Zero
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import java.io.File

final class ImportExportParseTests extends AnyFunSuite with Matchers {
import ParserHarness._

Expand Down Expand Up @@ -270,7 +272,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers {
}

test("history") {
withTsFile("parsertests/history.d.ts") { contents: String =>
withTsFile(s"parsertests${File.separator}history.d.ts") { contents: String =>
parseAs(contents, TsParser.parsedTsFile)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.scalablytyped.converter.internal.ts.parser

import org.scalablytyped.converter.internal.{files, InFile}
import org.scalatest.Assertion
import org.scalatest.matchers.should.Matchers._

import java.nio.file.{Files, Paths}
import scala.util.parsing.combinator.Parsers
import scala.util.parsing.input.CharSequenceReader

Expand Down Expand Up @@ -33,7 +33,7 @@ object ParserHarness {
}

def withTsFile[T](resourceName: String)(f: String => T): T =
f(files.content(InFile(os.Path(getClass.getResource(s"/$resourceName").getFile))))
f(Files.readString(Paths.get(getClass.getResource(s"/$resourceName").toURI)))

def parseAs[T](input: String, parser: String => Parsers#ParseResult[T]): T =
parser(input).force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import org.scalablytyped.converter.internal.ts.OptionalModifier.Noop
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers._

import java.io.File

final class ParserTests extends AnyFunSuite {
private val T = TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("T"))), Empty)

import ParserHarness._

test("whole file") {
withTsFile("parsertests/path-case.d.ts") { content =>
withTsFile(s"parsertests${File.separator}path-case.d.ts") { content =>
val expected =
TsParsedFile(
NoComments,
Expand Down Expand Up @@ -67,13 +69,13 @@ final class ParserTests extends AnyFunSuite {
}

test("handle byte order mark") {
withTsFile("parsertests/adm-zip.d.ts") { content =>
withTsFile(s"parsertests${File.separator}adm-zip.d.ts") { content =>
parseAs(content, TsParser.tsContainerOrDecls)
}
}

test("CR line endings") {
withTsFile("parsertests/mathfield.d.ts") { content =>
withTsFile(s"parsertests${File.separator}mathfield.d.ts") { content =>
parseAs(content, TsParser.parsedTsFile)
}
}
Expand All @@ -96,7 +98,7 @@ final class ParserTests extends AnyFunSuite {
}

test("windows line separators and mixed newlines/whitespace") {
withTsFile("parsertests/adal.d.ts") { content =>
withTsFile(s"parsertests${File.separator}adal.d.ts") { content =>
parseAs(content, TsParser.parsedTsFile)
}
}
Expand Down

0 comments on commit a829a36

Please sign in to comment.