Skip to content

Fixed that URL does not contain the "empty" #103

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

Merged
merged 2 commits into from
Feb 19, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
val path = fileRelativeToSource.getParent
val value = fileRelativeToSource.getName

if (path.eq(null)) {
"(empty)/" + value
} else if (path.ne("")) {
if (path.ne("")) {
// (Normalise the pathSeparator to "/" in case we are running on Windows)
fileRelativeToSource.toString.replace(File.separator, "/")
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package coverage.sample

class Class1 {
def msg_coverage = println("measure coverage of code")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package coverage.sample

class Class2 {
def msg_test = println("test code")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package scoverage

import java.io._
import java.util.UUID
import scala.io.Source

import scala.xml.XML

import scoverage.report.ScoverageHtmlWriter

import org.scalatest.FunSuite

class ScoverageHtmlWriterTest extends FunSuite {

test("HTML coverage report has been created correctly") {

def tempDir(): File = {
val dir = new File(IOUtils.getTempDirectory, UUID.randomUUID().toString)
dir.mkdirs()
dir.deleteOnExit()
dir
}

val coverage = Coverage()

val class2 = getClass.getResource("forHtmlWriter/src/main/scala/subdir/Class2.scala").getFile()
val class1 = getClass.getResource("forHtmlWriter/src/main/scala/Class1.scala").getFile()

coverage.add(
Statement(class2,
Location("coverage.sample", "Class2","Class", ClassType.Object, "msg_test", class2),
2, 57, 77, 4, "scala.this.Predef.println("test code")",
"scala.Predef.println", "Apply", false, 0)
)

coverage.add(
Statement(class1,
Location("coverage.sample", "Class1","Class", ClassType.Object, "msg_coverage", class1),
1, 61, 96, 4, "scala.this.Predef.println("measure coverage of code")",
"scala.Predef.println", "Apply", false, 0)
)

val dir = getClass.getResource("forHtmlWriter/src/main/scala/").getFile()
val outputDir = tempDir()

val htmlWriter = new ScoverageHtmlWriter(new File(dir), outputDir)
htmlWriter.write(coverage)

val htmls = List("overview.html", "coverage.sample.html")

for (html <- htmls) {
val xml = XML.loadString(Source.fromFile(new File(outputDir, html)).getLines.mkString)
val links = for (node <- xml \\ "a") yield {
node.attribute("href") match {
case Some(url) => url.toString
case None => fail()
}
}

assert( links.toSet == Set("Class1.scala.html", "subdir/Class2.scala.html") )
}
}
}