From 7bee8654b5fe594c74db1ffd1a6826cc7189e687 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Sat, 14 Sep 2024 11:14:10 +0200 Subject: [PATCH] Fix windows support --- .github/workflows/ci.yml | 11 ++++- build.sbt | 20 ++++++--- .../CoberturaMultiSourceReader.scala | 2 +- src/test/resources/generate.sh | 4 -- .../test_cobertura.xml.windows.template | 43 +++++++++++++++++++ ...t_cobertura_corrupted.xml.windows.template | 1 + .../test_cobertura_dtd.xml.windows.template | 43 +++++++++++++++++++ ...cobertura_multisource.xml.windows.template | 41 ++++++++++++++++++ .../CoberturaMultiSourceReaderTest.scala | 3 ++ 9 files changed, 157 insertions(+), 11 deletions(-) delete mode 100755 src/test/resources/generate.sh create mode 100644 src/test/resources/test_cobertura.xml.windows.template create mode 100644 src/test/resources/test_cobertura_corrupted.xml.windows.template create mode 100644 src/test/resources/test_cobertura_dtd.xml.windows.template create mode 100644 src/test/resources/test_cobertura_multisource.xml.windows.template 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..42cd200 100644 --- a/build.sbt +++ b/build.sbt @@ -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 diff --git a/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala b/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala index 084871b..259a314 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) } 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/CoberturaMultiSourceReaderTest.scala b/src/test/scala/org/scoverage/coveralls/CoberturaMultiSourceReaderTest.scala index dd85bae..26e7abb 100644 --- a/src/test/scala/org/scoverage/coveralls/CoberturaMultiSourceReaderTest.scala +++ b/src/test/scala/org/scoverage/coveralls/CoberturaMultiSourceReaderTest.scala @@ -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) )