Skip to content

Commit

Permalink
Fix a test case to not use git
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Sep 22, 2023
1 parent 2ad095f commit 762bc14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import fastparse.ParserInput
import fastparse.internal.Util

import java.io.File
import java.net.URL
import java.net.{URI, URL}
import java.nio.file.Path
import scala.collection.Searching
import scala.io.Source
Expand Down Expand Up @@ -121,8 +121,19 @@ case class FileParserInput(file: File) extends RiddlParserInput {
def this(path: Path) = this(path.toFile)
}

case class URIParserInput(uri: URI) extends RiddlParserInput {
lazy val data: String = {
val source: Source = Source.fromURI(uri)
try { source.getLines().mkString("\n") }
finally { source.close() }
}
override def isEmpty: Boolean = data.isEmpty
val root: File = new File(uri.getPath)
def origin: String = uri.toString
}

case class URLParserInput(url: URL) extends RiddlParserInput {
require(url.getProtocol.startsWith("http"), s"Non-http URL protocol '${url.getProtocol}``")
// require(url.getProtocol.startsWith("http"), s"Non-http URL protocol '${url.getProtocol}``")
lazy val data: String = {
val source: Source = Source.fromURL(url)
try { source.getLines().mkString("\n") }
Expand Down Expand Up @@ -160,4 +171,6 @@ object RiddlParserInput {
}

implicit def apply(url: URL): RiddlParserInput = URLParserInput(url)

implicit def apply(uri: URI): RiddlParserInput = URIParserInput(uri)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class IncludeAndImportTest extends ParsingTest {
}
}
"handle bad URL" in {
val badURL = new java.net.URL("https://incredible.lightness.of.being:8900000/@@@")
val badURL = new java.net.URI("https://incredible.lightness.of.being:8900000/@@@").toURL
parseDomainDefinition(
RiddlParserInput(badURL),
identity
Expand All @@ -43,7 +43,7 @@ class IncludeAndImportTest extends ParsingTest {
}
}
"handle non existent URL" in {
val emptyURL = new java.net.URL(
val emptyURL = new java.net.URI(
"https://raw.githubusercontent.com/reactific/riddl/main/testkit/src/test/input/domains/simpleDomain2.riddl"
)
parseDomainDefinition(
Expand All @@ -57,29 +57,20 @@ class IncludeAndImportTest extends ParsingTest {
errors.exists(_.format.contains("port out of range: 8900000"))
}
}
"handle existing URL" in {
"handle existing URI" in {
import sys.process._
val url: String = try {
val branchName = "git branch --show-current".!!.trim
s"https://raw.githubusercontent.com/reactific/riddl/$branchName/"
+ "testkit/src/test/input/domains/simpleDomain.riddl"
} catch {
case NonFatal(x) =>
""
val cwd = System.getProperty("user.dir", ".")
val urlStr: String = s"file:///${cwd}/testkit/src/test/input/domains/simpleDomain.riddl"
val uri = java.net.URI(urlStr)
parseDomainDefinition(
RiddlParserInput(uri),
identity
) match {
case Right(_) =>
succeed
case Left(errors) =>
fail(errors.format)
}
if url.isEmpty then
cancel("exception running git")
else
val fullURL = java.net.URI(url).toURL
parseDomainDefinition(
RiddlParserInput(fullURL),
identity
) match {
case Right(_) =>
succeed
case Left(errors) =>
fail(errors.format)
}
}
"handle inclusions into domain" in {
val rc = checkFile("Domain Includes", "domainIncludes.riddl")
Expand Down

0 comments on commit 762bc14

Please sign in to comment.