Skip to content

Commit c6ae6e2

Browse files
committed
Merge pull request #92 from Kwestor/bugfix/locale-dependent-tests
Bugfix/locale dependent tests
2 parents fb264df + 9cd568f commit c6ae6e2

File tree

13 files changed

+58
-59
lines changed

13 files changed

+58
-59
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/IOUtils.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package scoverage
22

33
import java.io._
44

5-
import scoverage.report.ScoverageXmlMerger
6-
75
import scala.collection.{Set, mutable}
86
import scala.io.Source
97

scalac-scoverage-plugin/src/main/scala/scoverage/coverage.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,11 @@ object ClassType {
113113
}
114114
}
115115

116-
117-
118-
119116
case class ClassRef(name: String) {
120117
lazy val simpleName = name.split(".").last
121118
lazy val getPackage = name.split(".").dropRight(1).mkString(".")
122119
}
120+
123121
object ClassRef {
124122
def fromFilepath(path: String) = ClassRef(path.replace('/', '.'))
125123
def apply(_package: String, className: String): ClassRef = ClassRef(_package.replace('/', '.') + "." + className)

scalac-scoverage-plugin/src/main/scala/scoverage/plugin.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ScoveragePlugin(val global: Global) extends Plugin {
3131
}
3232
}
3333
if (!opts.exists(_.startsWith("dataDir:")))
34-
throw new RuntimeException("Cannot invoke plugin without specifiying <dataDir>")
34+
throw new RuntimeException("Cannot invoke plugin without specifying <dataDir>")
3535
instrumentationComponent.setOptions(options)
3636
}
3737

@@ -315,7 +315,7 @@ class ScoverageInstrumentationComponent(val global: Global)
315315
c
316316
}
317317

318-
// scalac generated classes, we just instrument the enclosed methods/statments
318+
// scalac generated classes, we just instrument the enclosed methods/statements
319319
// the location would stay as the source class
320320
case c: ClassDef if c.symbol.isAnonymousClass || c.symbol.isAnonymousFunction =>
321321
if (isFileIncluded(c.pos.source) && isClassIncluded(c.symbol))
@@ -336,7 +336,7 @@ class ScoverageInstrumentationComponent(val global: Global)
336336
case DefDef(mods, _, _, _, _, _) if mods.isMacro => tree
337337

338338
// this will catch methods defined as macros, eg def test = macro testImpl
339-
// it will not catch macro implemenations
339+
// it will not catch macro implementations
340340
case d: DefDef if d.symbol != null
341341
&& d.symbol.annotations.size > 0
342342
&& d.symbol.annotations.toString() == "macroImpl" =>
@@ -415,13 +415,13 @@ class ScoverageInstrumentationComponent(val global: Global)
415415

416416
// the If statement itself doesn't need to be instrumented, because instrumenting the condition is
417417
// enough to determine if the If statement was executed.
418-
// The two procedures (then and else) are instrumented seperately to determine if we entered
418+
// The two procedures (then and else) are instrumented separately to determine if we entered
419419
// both branches.
420420
case i: If =>
421421
treeCopy.If(i,
422422
process(i.cond),
423-
instrument(process(i.thenp), i.thenp, true),
424-
instrument(process(i.elsep), i.elsep, true))
423+
instrument(process(i.thenp), i.thenp, branch = true),
424+
instrument(process(i.elsep), i.elsep, branch = true))
425425

426426
case _: Import => tree
427427

@@ -533,9 +533,12 @@ class ScoverageInstrumentationComponent(val global: Global)
533533
// This AST node corresponds to the following Scala code: expr: tpt
534534
case t: Typed => super.transform(tree)
535535

536-
// instrument trys, catches and finally as seperate blocks
536+
// instrument trys, catches and finally as separate blocks
537537
case Try(t: Tree, cases: List[CaseDef], f: Tree) =>
538-
treeCopy.Try(tree, instrument(process(t), t, true), transformCases(cases), instrument(process(f), f, true))
538+
treeCopy.Try(tree,
539+
instrument(process(t), t, branch = true),
540+
transformCases(cases),
541+
instrument(process(f), f, branch = true))
539542

540543
// type aliases, type parameters, abstract types
541544
case t: TypeDef => super.transform(tree)

scalac-scoverage-plugin/src/main/scala/scoverage/report/CodeGrid.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package scoverage.report
22

3-
import scala.io.Source
3+
import _root_.scoverage.MeasuredFile
44

5-
import _root_.scoverage.{MeasuredFile, Statement}
5+
import scala.io.Source
66

77
/** @author Stephen Samuel */
8-
class CodeGrid(mfile: MeasuredFile) {
8+
class CodeGrid(mFile: MeasuredFile) {
99

1010
case class Cell(char: Char, var status: StatementStatus)
1111

1212
private val lineBreak = System.getProperty("line.separator")
1313

1414
// Array of lines, each line is an array of cells, where a cell is a character + coverage info for that position
15-
// All cells defaul to NoData until the highlighted information is applied
16-
// note: we must reinclude the line sep to keep source positions correct.
17-
private val lines = source(mfile).split(lineBreak).map(line => (line.toCharArray ++ lineBreak).map(Cell(_, NoData)))
15+
// All cells default to NoData until the highlighted information is applied
16+
// note: we must re-include the line sep to keep source positions correct.
17+
private val lines = source(mFile).split(lineBreak).map(line => (line.toCharArray ++ lineBreak).map(Cell(_, NoData)))
1818

1919
// useful to have a single array to write into the cells
2020
private val cells = lines.flatten
2121

2222
// apply the instrumentation data to the cells updating their coverage info
23-
mfile.statements.foreach(stmt => {
23+
mFile.statements.foreach(stmt => {
2424
for ( k <- stmt.start until stmt.end ) {
2525
if (k < cells.size) {
2626
// if the cell is set to Invoked, then it be changed to NotInvoked, as an inner statement will override
27-
// outer containing statments. If a cell is NotInvoked then it can not be changed further.
27+
// outer containing statements. If a cell is NotInvoked then it can not be changed further.
2828
// in that block were executed
2929
cells(k).status match {
3030
case Invoked => if (!stmt.isInvoked) cells(k).status = NotInvoked

scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageHtmlWriter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
156156
def packageOverview(pack: MeasuredPackage): Node = {
157157
<html>
158158
{header}<body style="font-family: monospace;">
159-
{classesTable(pack.classes, false)}
159+
{classesTable(pack.classes, addPath = false)}
160160
</body>
161161
</html>
162162
}
@@ -417,7 +417,7 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
417417
{stats(coverage)}
418418
</div>
419419
<div>
420-
{classesTable(coverage.classes, true)}
420+
{classesTable(coverage.classes, addPath = true)}
421421
</div>
422422
</div>
423423
</body>

scalac-scoverage-plugin/src/main/scala/scoverage/report/ScoverageXmlReader.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object ScoverageXmlReader {
1616

1717
var id = 0
1818
val coverage = Coverage()
19-
(xml \\ "statement") foreach { node => {
19+
(xml \\ "statement") foreach { node =>
2020

2121
val source = node \ "@source"
2222
val pkg = node \ "@package"
@@ -55,7 +55,6 @@ object ScoverageXmlReader {
5555
count.text.toInt
5656
)
5757
}
58-
}
5958
coverage
6059
}
6160
}

scalac-scoverage-plugin/src/main/scala/scoverage/report/StatementWriter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _root_.scoverage.MeasuredFile
55
import scala.xml.Node
66

77
/** @author Stephen Samuel */
8-
class StatementWriter(mfile: MeasuredFile) {
8+
class StatementWriter(mFile: MeasuredFile) {
99

1010
val GREEN = "#AEF1AE"
1111
val RED = "#F0ADAD"
@@ -25,7 +25,7 @@ class StatementWriter(mfile: MeasuredFile) {
2525
<th>Tree</th>
2626
<th>Symbol</th>
2727
<th>Code</th>
28-
</tr>{mfile.statements.toSeq.sortBy(_.line).map(stmt => {
28+
</tr>{mFile.statements.toSeq.sortBy(_.line).map(stmt => {
2929
<tr>
3030
<td>
3131
{stmt.line}

scalac-scoverage-plugin/src/test/scala/scoverage/CoberturaXmlWriterTest.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scoverage
22

33
import java.io.File
4-
import java.util.UUID
4+
import java.util.{Locale, UUID}
55
import javax.xml.parsers.DocumentBuilderFactory
66

77
import org.scalatest.{BeforeAndAfter, FunSuite, OneInstancePerTest}
@@ -62,19 +62,16 @@ class CoberturaXmlWriterTest extends FunSuite with BeforeAndAfter with OneInstan
6262
builder.setErrorHandler(new ErrorHandler() {
6363
@Override
6464
def error(e: SAXParseException) {
65-
e.printStackTrace()
66-
assert(false)
65+
fail(e)
6766
}
6867
@Override
6968
def fatalError(e: SAXParseException) {
70-
e.printStackTrace()
71-
assert(false)
69+
fail(e)
7270
}
7371

7472
@Override
7573
def warning(e: SAXParseException) {
76-
e.printStackTrace()
77-
assert(false)
74+
fail(e)
7875
}
7976
})
8077
builder.parse(fileIn(dir))
@@ -100,8 +97,10 @@ class CoberturaXmlWriterTest extends FunSuite with BeforeAndAfter with OneInstan
10097

10198
val xml = XML.loadFile(fileIn(dir))
10299

103-
assert(xml \\ "coverage" \@ "line-rate" === "0.33", "line-rate")
104-
assert(xml \\ "coverage" \@ "branch-rate" === "0.50", "branch-rate")
100+
def formattedLocally(decimal: BigDecimal) = "%.2f".format(decimal)
101+
102+
assert(xml \\ "coverage" \@ "line-rate" === formattedLocally(0.33), "line-rate")
103+
assert(xml \\ "coverage" \@ "branch-rate" === formattedLocally(0.50), "branch-rate")
105104

106105
}
107106
}

scalac-scoverage-plugin/src/test/scala/scoverage/IOUtilsTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.scalatest.{FreeSpec, Matchers, OneInstancePerTest}
1010
class IOUtilsTest extends FreeSpec with MockitoSugar with OneInstancePerTest with Matchers {
1111

1212
"io utils" - {
13-
"should parse measurment files" in {
13+
"should parse measurement files" in {
1414
val file = File.createTempFile("scoveragemeasurementtest", "txt")
1515
val writer = new FileWriter(file)
1616
writer.write("1\n5\n9\n\n10\n")

scalac-scoverage-plugin/src/test/scala/scoverage/LocationTest.scala

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LocationTest extends FreeSpec with Matchers {
99
"for classes" in {
1010
val compiler = ScoverageCompiler.locationCompiler
1111
compiler.compile("package com.test\nclass Sammy")
12-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
12+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
1313
loc.packageName shouldBe "com.test"
1414
loc.className shouldBe "Sammy"
1515
loc.topLevelClass shouldBe "Sammy"
@@ -20,7 +20,7 @@ class LocationTest extends FreeSpec with Matchers {
2020
"for objects" in {
2121
val compiler = ScoverageCompiler.locationCompiler
2222
compiler.compile("package com.test\nobject Bammy { def foo = 'boo } ")
23-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
23+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
2424
loc.packageName shouldBe "com.test"
2525
loc.className shouldBe "Bammy"
2626
loc.topLevelClass shouldBe "Bammy"
@@ -31,7 +31,7 @@ class LocationTest extends FreeSpec with Matchers {
3131
"for traits" in {
3232
val compiler = ScoverageCompiler.locationCompiler
3333
compiler.compile("package com.test\ntrait Gammy { def goo = 'hoo } ")
34-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
34+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
3535
loc.packageName shouldBe "com.test"
3636
loc.className shouldBe "Gammy"
3737
loc.topLevelClass shouldBe "Gammy"
@@ -43,7 +43,7 @@ class LocationTest extends FreeSpec with Matchers {
4343
"should correctly process methods" in {
4444
val compiler = ScoverageCompiler.locationCompiler
4545
compiler.compile("package com.methodtest \n class Hammy { def foo = 'boo } ")
46-
val loc = compiler.locations.result.find(_._2.method == "foo").get._2
46+
val loc = compiler.locations.result().find(_._2.method == "foo").get._2
4747
loc.packageName shouldBe "com.methodtest"
4848
loc.className shouldBe "Hammy"
4949
loc.classType shouldBe ClassType.Class
@@ -52,7 +52,7 @@ class LocationTest extends FreeSpec with Matchers {
5252
"should correctly process nested methods" in {
5353
val compiler = ScoverageCompiler.locationCompiler
5454
compiler.compile("package com.methodtest \n class Hammy { def foo = { def goo = { getClass; 3 }; goo } } ")
55-
val loc = compiler.locations.result.find(_._2.method == "goo").get._2
55+
val loc = compiler.locations.result().find(_._2.method == "goo").get._2
5656
loc.packageName shouldBe "com.methodtest"
5757
loc.className shouldBe "Hammy"
5858
loc.topLevelClass shouldBe "Hammy"
@@ -63,7 +63,7 @@ class LocationTest extends FreeSpec with Matchers {
6363
"should process anon functions as inside the enclosing method" in {
6464
val compiler = ScoverageCompiler.locationCompiler
6565
compiler.compile("package com.methodtest \n class Jammy { def moo = { Option(\"bat\").map(_.length) } } ")
66-
val loc = compiler.locations.result.find(_._1 == "Function").get._2
66+
val loc = compiler.locations.result().find(_._1 == "Function").get._2
6767
loc.packageName shouldBe "com.methodtest"
6868
loc.className shouldBe "Jammy"
6969
loc.method shouldBe "moo"
@@ -74,7 +74,7 @@ class LocationTest extends FreeSpec with Matchers {
7474
"for nested classes" in {
7575
val compiler = ScoverageCompiler.locationCompiler
7676
compiler.compile("package com.methodtest \n class Jammy { class Pammy } ")
77-
val loc = compiler.locations.result.find(_._2.className == "Pammy").get._2
77+
val loc = compiler.locations.result().find(_._2.className == "Pammy").get._2
7878
loc.packageName shouldBe "com.methodtest"
7979
loc.className shouldBe "Pammy"
8080
loc.topLevelClass shouldBe "Jammy"
@@ -85,7 +85,7 @@ class LocationTest extends FreeSpec with Matchers {
8585
"for nested objects" in {
8686
val compiler = ScoverageCompiler.locationCompiler
8787
compiler.compile("package com.methodtest \n class Jammy { object Zammy } ")
88-
val loc = compiler.locations.result.find(_._2.className == "Zammy").get._2
88+
val loc = compiler.locations.result().find(_._2.className == "Zammy").get._2
8989
loc.packageName shouldBe "com.methodtest"
9090
loc.className shouldBe "Zammy"
9191
loc.topLevelClass shouldBe "Jammy"
@@ -96,7 +96,7 @@ class LocationTest extends FreeSpec with Matchers {
9696
"for nested traits" in {
9797
val compiler = ScoverageCompiler.locationCompiler
9898
compiler.compile("package com.methodtest \n class Jammy { trait Mammy } ")
99-
val loc = compiler.locations.result.find(_._2.className == "Mammy").get._2
99+
val loc = compiler.locations.result().find(_._2.className == "Mammy").get._2
100100
loc.packageName shouldBe "com.methodtest"
101101
loc.className shouldBe "Mammy"
102102
loc.topLevelClass shouldBe "Jammy"
@@ -111,7 +111,7 @@ class LocationTest extends FreeSpec with Matchers {
111111
compiler.compile("package com.a \n " +
112112
"package b \n" +
113113
"class Kammy ")
114-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
114+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
115115
loc.packageName shouldBe "com.a.b"
116116
loc.className shouldBe "Kammy"
117117
loc.topLevelClass shouldBe "Kammy"
@@ -124,7 +124,7 @@ class LocationTest extends FreeSpec with Matchers {
124124
compiler.compile("package com.a \n " +
125125
"package b \n" +
126126
"object Kammy ")
127-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
127+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
128128
loc.packageName shouldBe "com.a.b"
129129
loc.className shouldBe "Kammy"
130130
loc.method shouldBe "<none>"
@@ -136,7 +136,7 @@ class LocationTest extends FreeSpec with Matchers {
136136
compiler.compile("package com.a \n " +
137137
"package b \n" +
138138
"trait Kammy ")
139-
val loc = compiler.locations.result.find(_._1 == "Template").get._2
139+
val loc = compiler.locations.result().find(_._1 == "Template").get._2
140140
loc.packageName shouldBe "com.a.b"
141141
loc.className shouldBe "Kammy"
142142
loc.topLevelClass shouldBe "Kammy"
@@ -149,7 +149,7 @@ class LocationTest extends FreeSpec with Matchers {
149149
"for class constructor body" in {
150150
val compiler = ScoverageCompiler.locationCompiler
151151
compiler.compile("package com.b \n class Tammy { val name = 'sam } ")
152-
val loc = compiler.locations.result.find(_._1 == "ValDef").get._2
152+
val loc = compiler.locations.result().find(_._1 == "ValDef").get._2
153153
loc.packageName shouldBe "com.b"
154154
loc.className shouldBe "Tammy"
155155
loc.method shouldBe "<none>"
@@ -159,7 +159,7 @@ class LocationTest extends FreeSpec with Matchers {
159159
"for object constructor body" in {
160160
val compiler = ScoverageCompiler.locationCompiler
161161
compiler.compile("package com.b \n object Yammy { val name = 'sam } ")
162-
val loc = compiler.locations.result.find(_._1 == "ValDef").get._2
162+
val loc = compiler.locations.result().find(_._1 == "ValDef").get._2
163163
loc.packageName shouldBe "com.b"
164164
loc.className shouldBe "Yammy"
165165
loc.topLevelClass shouldBe "Yammy"
@@ -170,7 +170,7 @@ class LocationTest extends FreeSpec with Matchers {
170170
"for trait constructor body" in {
171171
val compiler = ScoverageCompiler.locationCompiler
172172
compiler.compile("package com.b \n trait Wammy { val name = 'sam } ")
173-
val loc = compiler.locations.result.find(_._1 == "ValDef").get._2
173+
val loc = compiler.locations.result().find(_._1 == "ValDef").get._2
174174
loc.packageName shouldBe "com.b"
175175
loc.className shouldBe "Wammy"
176176
loc.topLevelClass shouldBe "Wammy"
@@ -185,8 +185,8 @@ class LocationTest extends FreeSpec with Matchers {
185185
.compile(
186186
"package com.a; object A { def foo(b : B) : Unit = b.invoke }; trait B { def invoke : Unit }; class C { A.foo(new B { def invoke = () }) }")
187187
println()
188-
println(compiler.locations.result.mkString("\n"))
189-
val loc = compiler.locations.result.filter(_._1 == "Template").last._2
188+
println(compiler.locations.result().mkString("\n"))
189+
val loc = compiler.locations.result().filter(_._1 == "Template").last._2
190190
loc.packageName shouldBe "com.a"
191191
loc.className shouldBe "C"
192192
loc.topLevelClass shouldBe "C"
@@ -199,8 +199,8 @@ class LocationTest extends FreeSpec with Matchers {
199199
compiler.compile(
200200
"package com.a; object A { def foo(b : B) : Unit = b.invoke }; trait B { def invoke : Unit }; class C { A.foo(new B { def invoke = () }) }")
201201
println()
202-
println(compiler.locations.result.mkString("\n"))
203-
val loc = compiler.locations.result.filter(_._1 == "DefDef").last._2
202+
println(compiler.locations.result().mkString("\n"))
203+
val loc = compiler.locations.result().filter(_._1 == "DefDef").last._2
204204
loc.packageName shouldBe "com.a"
205205
loc.className shouldBe "C"
206206
loc.topLevelClass shouldBe "C"

0 commit comments

Comments
 (0)