Skip to content

Commit

Permalink
Fix windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Sep 16, 2024
1 parent 3cb10c8 commit 7bee865
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 11 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ on:

jobs:
scala:
runs-on: ubuntu-latest
strategy:
fail-fast: false # remove when PR is finished, just to make sure we don't make regression
matrix:
JDK: [ 8, 17 ]
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}

steps:
- name: Ignore line ending differences in git
if: contains(runner.os, 'windows')
shell: bash
run: git config --global core.autocrlf false

- name: checkout the repo
uses: actions/checkout@v4
with:
Expand Down
20 changes: 15 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
name := "sbt-coveralls"

import sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts

import scala.sys.process._
lazy val generateXMLFiles =
taskKey[Unit]("Generate XML files (for test)")
generateXMLFiles := {
val log = streams.value.log
s"./src/test/resources/generate.sh" ! log
val dir = (Test / resourceDirectory).value
val pwd = (run / baseDirectory).value.absolutePath

val template = if (System.getProperty("os.name").startsWith("Windows"))
".xml.windows.template"
else
".xml.template"

dir.listFiles { (_, name) => name.endsWith(template) }.foreach {
templateFile =>
val newFile = dir / templateFile.getName.replace(template, ".xml")
val content = IO.read(templateFile)
IO.write(newFile, content.replace("{{PWD}}", pwd))
}
}

lazy val prepareScripted =
taskKey[Unit]("Update .git files to make scripted work")
lazy val prepareScripted = taskKey[Unit]("Update .git files to make scripted work")
prepareScripted := {
val log = streams.value.log
s"./src/sbt-test/prepare.sh" ! log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CoberturaMultiSourceReader(

protected def lineCoverage(sourceFile: String) = {
val filenamePath =
splitPath(new File(sourceFile))._2.replace(File.separator, "/")
splitPath(new File(sourceFile))._2

lineCoverageMap(filenamePath)
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/resources/generate.sh

This file was deleted.

43 changes: 43 additions & 0 deletions src/test/resources/test_cobertura.xml.windows.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<!DOCTYPE coverage SYSTEM "http://localhost:1/xml/coverage-04.dtd">
<coverage line-rate="0.87">
<sources>
<source>--source</source>
<source>{{PWD}}\src\test\resources\projectA\arc\main\scala</source>
<source>{{PWD}}\src\test\resources\projectA\arc\main\scala-2.12</source>
<source>{{PWD}}\src\test\resources\projectB\arc\main\scala</source>
</sources>
<packages>
<package line-rate="0.87" name="org.scoverage.coveralls">
<classes>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="2"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
</lines>
</class>
<class line-rate="0" name="TestSourceScala212" filename="bar\foo\TestSourceScala212.scala">
<methods/>
<lines/>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
corrupted file content
43 changes: 43 additions & 0 deletions src/test/resources/test_cobertura_dtd.xml.windows.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<!DOCTYPE coverage SYSTEM "http://localhost:1/xml/coverage-04.dtd">
<coverage line-rate="0.87">
<sources>
<source>--source</source>
<source>{{PWD}}\src\test\resources\projectA\src\main\scala</source>
<source>{{PWD}}\src\test\resources\projectA\src\main\scala-2.12</source>
<source>{{PWD}}\src\test\resources\projectB\src\main\scala</source>
</sources>
<packages>
<package line-rate="0.87" name="org.scoverage.coveralls">
<classes>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="2"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
</lines>
</class>
<class line-rate="0" name="TestSourceScala212" filename="bar\foo\TestSourceScala212.scala">
<methods/>
<lines/>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
41 changes: 41 additions & 0 deletions src/test/resources/test_cobertura_multisource.xml.windows.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<coverage line-rate="0.87">
<sources>
<source>--source</source>
<source>{{PWD}}\src\test\resources\projectA\src\main\scala</source>
<source>{{PWD}}\src\test\resources\projectA\src\main\scala-2.12</source>
<source>{{PWD}}\src\test\resources\projectB\src\main\scala</source>
</sources>
<packages>
<package line-rate="0.87" name="org.scoverage.coveralls">
<classes>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="2"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="bar\foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
</lines>
</class>
<class line-rate="0" name="TestSourceScala212" filename="bar\foo\TestSourceScala212.scala">
<methods/>
<lines/>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="foo\TestSourceFile.scala">
<methods/>
<lines>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class CoberturaMultiSourceReaderTest
Seq("bar", "foo", "TestSourceFile.scala")
)
val fileReport = reader.reportForSource(sourceFile.getCanonicalPath)
println(s"fileReport.file: ${fileReport.file}")
println(s"Seq(\"foo\", \"TestSourceFile.scala\").mkString(File.separator): ${Seq("foo", "TestSourceFile.scala").mkString(File.separator)}")

fileReport.file should endWith(
Seq("foo", "TestSourceFile.scala").mkString(File.separator)
)
Expand Down

0 comments on commit 7bee865

Please sign in to comment.