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

// $COVERAGE-OFF$ & // $COVERAGE-ON$ #155

Merged
merged 1 commit into from
Dec 6, 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: 5 additions & 1 deletion src/main/scala/sbtbuildinfo/ScalaCaseClassRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ case class ScalaCaseClassRenderer(options: Seq[BuildInfoOption], pkg: String, ob
// the project using `-Ywarn-unused-import` because we do not always generated references that are part of
// `scala` such as `scala.Option`.
def header = List(
"// $COVERAGE-OFF$",
s"package $pkg",
"",
"import scala.Predef._",
Expand All @@ -22,6 +23,8 @@ case class ScalaCaseClassRenderer(options: Seq[BuildInfoOption], pkg: String, ob
s"/** This file was generated by sbt-buildinfo. */"
)

def footer = List("// $COVERAGE-ON$")

override def renderKeys(buildInfoResults: Seq[BuildInfoResult]) =
header ++
caseClassDefinitionBegin ++
Expand All @@ -30,7 +33,8 @@ case class ScalaCaseClassRenderer(options: Seq[BuildInfoOption], pkg: String, ob
toMapMethod(buildInfoResults) ++
caseClassEnd ++
List("") ++
caseObjectLine(buildInfoResults)
caseObjectLine(buildInfoResults) ++
footer

private def caseClassDefinitionBegin = List(
withPkgPriv(s"case class $obj(")
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/sbtbuildinfo/ScalaCaseObjectRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private[sbtbuildinfo] case class ScalaCaseObjectRenderer(options: Seq[BuildInfoO
// the project using `-Ywarn-unused-import` because we do not always generated references that are part of
// `scala` such as `scala.Option`.
def header = List(
"// $COVERAGE-OFF$",
s"package $pkg",
"",
"import scala.Predef._",
Expand All @@ -22,7 +23,7 @@ private[sbtbuildinfo] case class ScalaCaseObjectRenderer(options: Seq[BuildInfoO
withPkgPriv(s"case object $obj$objTraits {")
)

def footer = List("}")
def footer = List("}", "// $COVERAGE-ON$")

override def renderKeys(buildInfoResults: Seq[BuildInfoResult]) =
header ++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ case class ScalaFinalCaseObjectRenderer(options: Seq[BuildInfoOption], pkg: Stri
// the project using `-Ywarn-unused-import` because we do not always generated references that are part of
// `scala` such as `scala.Option`.
def header = List(
"// $COVERAGE-OFF$",
s"package $pkg",
"",
"import scala.Predef._",
Expand All @@ -22,7 +23,7 @@ case class ScalaFinalCaseObjectRenderer(options: Seq[BuildInfoOption], pkg: Stri
withPkgPriv(s"case object $obj$objTraits {")
)

def footer = List("}")
def footer = List("}", "// $COVERAGE-ON$")

override def renderKeys(buildInfoResults: Seq[BuildInfoResult]) =
header ++
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/append/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand All @@ -45,7 +46,8 @@ lazy val root = (project in file(".")).
""" name, version, scalaVersion, sbtVersion, organization, libraryDependencies, test_libraryDependencies, resolvers""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/buildtime/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand All @@ -42,7 +43,8 @@ lazy val root = (project in file(".")).
""" name, version, scalaVersion, builtAtString, builtAtMillis""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil =>
case _ => sys.error("unexpected output:\n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/caching/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ lazy val root = (project in file(".")).
val f = dir / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand All @@ -30,7 +31,8 @@ lazy val root = (project in file(".")).
""" name, version""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/caseclassrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""import scala.Any""" ::
Expand Down Expand Up @@ -71,7 +72,8 @@ lazy val root = (project in file(".")).
targetInfo ::
""" val get = apply()""" ::
""" val value = apply()""" ::
"""}""" :: Nil if (targetInfo contains "target = new java.io.File(") =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if (targetInfo contains "target = new java.io.File(") =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/finalcaseobjectrenderer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand Down Expand Up @@ -71,7 +72,8 @@ lazy val root = (project in file(".")).
""" name, projectVersion, scalaVersion, ivyXML, homepage, licenses, apiMappings, isSnapshot, year, sym, buildTime, someCp, target""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil if targetInfo contains "target: java.io.File = new java.io.File(" =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if targetInfo contains "target: java.io.File = new java.io.File(" =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/multi/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ lazy val app = (project in file("app")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand All @@ -47,7 +48,8 @@ lazy val app = (project in file("app")).
""" name, projectID, version, homepage, scalaVersion""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil =>
case _ => sys.error("unexpected output: " + lines.mkString("\n"))
}
()
Expand Down
85 changes: 44 additions & 41 deletions src/sbt-test/sbt-buildinfo/options/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,50 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
"""/** This object was generated by sbt-buildinfo. */""" ::
"""private[hello] case object BuildInfo extends TestTrait1 with TestTrait2 with TestTrait3 {""" ::
""" /** The value is "helloworld". */"""::
""" val name: String = "helloworld"""" ::
""" /** The value is "2.12.7". */""" ::
""" val scalaVersion: String = "2.12.7"""" ::
""" override val toString: String = {""" ::
""" "name: %s, scalaVersion: %s".format(""" ::
""" name, scalaVersion""" ::
""" )""" ::
""" }""" ::
""" val toMap: Map[String, Any] = Map[String, Any](""" ::
""" "name" -> name,""" ::
""" "scalaVersion" -> scalaVersion)""" ::
"""""" ::
""" private def quote(x: Any): String = "\"" + x + "\""""" ::
""" private def toJsonValue(value: Any): String = {""" ::
""" value match {""" ::
""" case elem: Seq[_] => elem.map(toJsonValue).mkString("[", ",", "]")""" ::
""" case elem: Option[_] => elem.map(toJsonValue).getOrElse("null")""" ::
""" case elem: Map[String, Any] => elem.map {""" ::
""" case (k, v) => toJsonValue(k) + ":" + toJsonValue(v)""" ::
""" }.mkString("{", ", ", "}")""" ::
""" case d: Double => d.toString""" ::
""" case f: Float => f.toString""" ::
""" case l: Long => l.toString""" ::
""" case i: Int => i.toString""" ::
""" case s: Short => s.toString""" ::
""" case bool: Boolean => bool.toString""" ::
""" case str: String => quote(str)""" ::
""" case other => quote(other.toString)""" ::
""" }""" ::
""" }""" ::
"""""" ::
""" val toJson: String = toJsonValue(toMap)""" ::
"""}""" :: Nil =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
"""/** This object was generated by sbt-buildinfo. */""" ::
"""private[hello] case object BuildInfo extends TestTrait1 with TestTrait2 with TestTrait3 {""" ::
""" /** The value is "helloworld". */""" ::
""" val name: String = "helloworld"""" ::
""" /** The value is "2.12.7". */""" ::
""" val scalaVersion: String = "2.12.7"""" ::
""" override val toString: String = {""" ::
""" "name: %s, scalaVersion: %s".format(""" ::
""" name, scalaVersion""" ::
""" )""" ::
""" }""" ::
""" val toMap: Map[String, Any] = Map[String, Any](""" ::
""" "name" -> name,""" ::
""" "scalaVersion" -> scalaVersion)""" ::
"""""" ::
""" private def quote(x: Any): String = "\"" + x + "\""""" ::
""" private def toJsonValue(value: Any): String = {""" ::
""" value match {""" ::
""" case elem: Seq[_] => elem.map(toJsonValue).mkString("[", ",", "]")""" ::
""" case elem: Option[_] => elem.map(toJsonValue).getOrElse("null")""" ::
""" case elem: Map[String, Any] => elem.map {""" ::
""" case (k, v) => toJsonValue(k) + ":" + toJsonValue(v)""" ::
""" }.mkString("{", ", ", "}")""" ::
""" case d: Double => d.toString""" ::
""" case f: Float => f.toString""" ::
""" case l: Long => l.toString""" ::
""" case i: Int => i.toString""" ::
""" case s: Short => s.toString""" ::
""" case bool: Boolean => bool.toString""" ::
""" case str: String => quote(str)""" ::
""" case other => quote(other.toString)""" ::
""" }""" ::
""" }""" ::
"""""" ::
""" val toJson: String = toJsonValue(toMap)""" ::
"""}""" ::
"""// $COVERAGE-ON$""" ::
Nil =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
}
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package hello""" ::
case """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand Down Expand Up @@ -68,7 +69,8 @@ lazy val root = (project in file(".")).
""" name, projectVersion, scalaVersion, ivyXML, homepage, licenses, apiMappings, isSnapshot, year, sym, buildTime, someCp, target""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil if (targetInfo contains "val target: java.io.File = new java.io.File(") =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if (targetInfo contains "val target: java.io.File = new java.io.File(") =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down
6 changes: 4 additions & 2 deletions src/sbt-test/sbt-buildinfo/usepackageaspath/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ lazy val root = (project in file(".")).
val f = (sourceManaged in Compile).value / "foo" / "bar" / "baz" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
lines match {
case """package foo.bar.baz""" ::
case """// $COVERAGE-OFF$""" ::
"""package foo.bar.baz""" ::
"""""" ::
"""import scala.Predef._""" ::
"""""" ::
Expand Down Expand Up @@ -64,7 +65,8 @@ lazy val root = (project in file(".")).
""" name, projectVersion, scalaVersion, ivyXML, homepage, licenses, apiMappings, isSnapshot, year, sym, buildTime, target""" ::
""" )""" ::
""" }""" ::
"""}""" :: Nil if (targetInfo contains "val target: java.io.File = new java.io.File(") =>
"""}""" ::
"""// $COVERAGE-ON$""" :: Nil if (targetInfo contains "val target: java.io.File = new java.io.File(") =>
case _ => sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
Expand Down