diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7a7654a..51c998f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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:
diff --git a/build.sbt b/build.sbt
index af4c1ef..9849c32 100644
--- a/build.sbt
+++ b/build.sbt
@@ -2,19 +2,47 @@ name := "sbt-coveralls"
import sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts
-import scala.sys.process._
+import java.io.File
+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")
prepareScripted := {
val log = streams.value.log
- s"./src/sbt-test/prepare.sh" ! log
+ val pwd = (run / baseDirectory).value.absolutePath
+
+ val submodules = "git submodule status" !! log
+ val submodulePaths = submodules.split('\n').map{x =>
+ x.split(" ")(2)
+ }
+
+ submodulePaths.foreach{ subModulePath =>
+ val path = file(pwd) / ".git" / "modules" / subModulePath
+ val pathFixedForWindows = if (System.getProperty("os.name").startsWith("Windows"))
+ path.absolutePath.replace(File.separator, "/") // Git under Windows uses / for path separator
+ else
+ path.absolutePath
+ println(s"destination: ${(file(subModulePath) / ".git").absolutePath}")
+ IO.write(file(subModulePath) / ".git", s"gitdir: $pathFixedForWindows")
+ }
}
inThisBuild(
diff --git a/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala b/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala
index 084871b..aec5f57 100644
--- a/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala
+++ b/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala
@@ -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)
}
@@ -130,9 +130,7 @@ class CoberturaMultiSourceReader(
val lineHitMap = lineCoverage(source)
val fullLineHit = (0 until lineCount).map(i => lineHitMap.get(i + 1))
- val sourceNormalized = source.replace(File.separator, "/")
-
- SourceFileReport(sourceNormalized, fullLineHit.toList)
+ SourceFileReport(source, fullLineHit.toList)
}
}
diff --git a/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala b/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala
index afc1518..65f4ee7 100644
--- a/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala
+++ b/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala
@@ -95,8 +95,7 @@ class CoverallPayloadWriter(
}
def addSourceFile(report: SourceFileReport) = {
- val repoRootDirStr =
- repoRootDir.getCanonicalPath.replace(File.separator, "/") + "/"
+ val repoRootDirStr = repoRootDir.getCanonicalPath + File.separator
// create a name relative to the project root (rather than the module root)
// this is needed so that coveralls can find the file in git.
diff --git a/src/test/resources/generate.sh b/src/test/resources/generate.sh
deleted file mode 100755
index ac1bf4a..0000000
--- a/src/test/resources/generate.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash
-
-resources=src/test/resources
-for f in ${resources}/*.template; do cat ${f} | sed "s|{{PWD}}|${PWD}|" > ${resources}/$(basename ${f} .template); done
diff --git a/src/test/resources/test_cobertura.xml.windows.template b/src/test/resources/test_cobertura.xml.windows.template
new file mode 100644
index 0000000..e2f5947
--- /dev/null
+++ b/src/test/resources/test_cobertura.xml.windows.template
@@ -0,0 +1,43 @@
+
+
+
+
+ --source
+ {{PWD}}\src\test\resources\projectA\arc\main\scala
+ {{PWD}}\src\test\resources\projectA\arc\main\scala-2.12
+ {{PWD}}\src\test\resources\projectB\arc\main\scala
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/test_cobertura_corrupted.xml.windows.template b/src/test/resources/test_cobertura_corrupted.xml.windows.template
new file mode 100644
index 0000000..7b19abc
--- /dev/null
+++ b/src/test/resources/test_cobertura_corrupted.xml.windows.template
@@ -0,0 +1 @@
+corrupted file content
diff --git a/src/test/resources/test_cobertura_dtd.xml.windows.template b/src/test/resources/test_cobertura_dtd.xml.windows.template
new file mode 100644
index 0000000..72350ee
--- /dev/null
+++ b/src/test/resources/test_cobertura_dtd.xml.windows.template
@@ -0,0 +1,43 @@
+
+
+
+
+ --source
+ {{PWD}}\src\test\resources\projectA\src\main\scala
+ {{PWD}}\src\test\resources\projectA\src\main\scala-2.12
+ {{PWD}}\src\test\resources\projectB\src\main\scala
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/resources/test_cobertura_multisource.xml.windows.template b/src/test/resources/test_cobertura_multisource.xml.windows.template
new file mode 100644
index 0000000..2a0365c
--- /dev/null
+++ b/src/test/resources/test_cobertura_multisource.xml.windows.template
@@ -0,0 +1,41 @@
+
+
+ --source
+ {{PWD}}\src\test\resources\projectA\src\main\scala
+ {{PWD}}\src\test\resources\projectA\src\main\scala-2.12
+ {{PWD}}\src\test\resources\projectB\src\main\scala
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala b/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala
index 24798a5..b5d86f3 100644
--- a/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala
+++ b/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala
@@ -153,8 +153,17 @@ class CoverallPayloadWriterTest
)
payloadWriter.flush()
- writer.toString should equal(
- """{"name":"./src/test/resources/projectA/src/main/scala/bar/foo/TestSourceFile.scala","source_digest":"B77361233B09D69968F8C62491A5085F","coverage":[1,null,2]}"""
+ val output = writer.toString
+
+ val separator = if (System.getProperty("os.name").startsWith("Windows"))
+ s"""${File.separator}\\""" // Backwards slash is a special character in JSON so it needs to be escaped
+ else
+ File.separator
+
+ val name = List(".","src","test","resources","projectA","src","main","scala","bar","foo","TestSourceFile.scala")
+ .mkString(separator)
+ output should equal(
+ s"""{"name":"$name","source_digest":"B77361233B09D69968F8C62491A5085F","coverage":[1,null,2]}"""
)
}