Skip to content

Commit 51b7962

Browse files
committed
Added support for arbitary jars in test runner. Added test for joda.
1 parent 3679859 commit 51b7962

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ libraryDependencies ++= Seq(
1010
"commons-io" % "commons-io" % "2.4",
1111
"org.scala-lang" % "scala-compiler" % "2.10.3" % "provided",
1212
"org.scalatest" %% "scalatest" % "2.1.0" % "test",
13-
"org.mockito" % "mockito-all" % "1.9.5" % "test"
13+
"org.mockito" % "mockito-all" % "1.9.5" % "test",
14+
"joda-time" % "joda-time" % "2.2" % "test",
15+
"org.joda" % "joda-convert" % "1.3.1" % "test"
1416
)
1517

1618
publishMavenStyle := true

src/test/scala/scoverage/PluginASTSupportTest.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,27 @@ class PluginASTSupportTest
6464
|} """.stripMargin)
6565
assert(!reporter.hasErrors)
6666
}
67+
68+
test("scoverage supports joda time #23") {
69+
addToClassPath("org.joda", "joda-convert", "1.3.1")
70+
addToClassPath("joda-time", "joda-time", "2.3")
71+
compileCodeSnippet( """class Test {
72+
|
73+
| import org.joda.time.LocalDate
74+
| import org.joda.time.DateTime
75+
|
76+
| case class Member(id: Long,
77+
| name: String,
78+
| activated: Boolean,
79+
| luckyNumber: Option[Long] = None,
80+
| birthday: Option[LocalDate] = None,
81+
| createdAt: DateTime,
82+
| updatedAt: DateTime)
83+
|} """.stripMargin)
84+
85+
assert(!reporter.hasErrors)
86+
87+
}
6788
}
89+
90+

src/test/scala/scoverage/PluginRunner.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ trait PluginSupport {
2727
file
2828
}
2929

30+
def addToClassPath(groupId: String, artifactId: String, version: String): Unit = {
31+
settings.classpath.value = settings.classpath.value + ":" + findIvyJar(groupId, artifactId, version).getAbsolutePath
32+
}
33+
3034
def compileCodeSnippet(code: String): ScoverageAwareCompiler = compileSourceFiles(writeCodeSnippetToTempFile(code))
3135

3236
def compileSourceFiles(files: File*): ScoverageAwareCompiler = {
@@ -48,6 +52,14 @@ trait PluginSupport {
4852
if (file.exists) file else throw new FileNotFoundException(s"Could not locate [$jarName]. Tests require SBT 0.13+")
4953
}
5054

55+
def findIvyJar(groupId: String, artifactId: String, version: String): File = {
56+
val userHome = System.getProperty("user.home")
57+
val sbtHome = userHome + "/.ivy2"
58+
val jarPath = sbtHome + "/cache/" + groupId + "/" + artifactId + "/jars/" + artifactId + "-" + version + ".jar"
59+
val file = new File(jarPath)
60+
if (file.exists) file else throw new FileNotFoundException(s"Could not locate [$jarPath]. Tests require SBT 0.13+")
61+
}
62+
5163
def sbtCompileDir: File = {
5264
val dir = new File("./target/scala-" + shortScalaVersion + "/classes")
5365
if (dir.exists) dir

0 commit comments

Comments
 (0)