Skip to content
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

Tests and project in two modules #79

Open
Kwestor opened this issue Jan 8, 2015 · 9 comments
Open

Tests and project in two modules #79

Kwestor opened this issue Jan 8, 2015 · 9 comments

Comments

@Kwestor
Copy link
Contributor

Kwestor commented Jan 8, 2015

We have following infrastructure in our company:

  • parentProject
    • projectA
    • projectA-tests
    • projectB
    • projectB-tests
    • ...

We would like to check coverage of projectA with projectA-tests etc.

Do you have any plans to support such setup? Or how could I hack such solution (or maybe implement it in scoverage)?

@maiflai
Copy link
Contributor

maiflai commented Jan 22, 2015

I think we managed to cover this in a separate thread - scoverage/gradle-scoverage#33 (comment)

If you're using Gradle, please could you test the following?

configure(subprojects.findAll { it.name.endsWith('-tests') }) {
  def mainProject = project(":${project.name.minus('-tests')}")
  dependencies {
    testCompile mainProject
  }
  scoverage {
    sources = mainProject.extensions.scoverage.sources
    dataDir = mainProject.extensions.scoverage.dataDir
    reportDir = mainProject.extensions.scoverage.reportDir
  }
  testScoverage {
    classpath = mainProject.sourceSets.scoverage.runtimeClasspath + sourceSets.test.runtimeClasspath
  } 
}

You might also need to configure the 'main' projects to skip the testScoverage and reportScoverage tasks.

subprojects {
    testScoverage { onlyIf { project.name.endsWith('-tests') }  }
    reportScoverage { onlyIf { project.name.endsWith('-tests') } }
}

@Kwestor
Copy link
Contributor Author

Kwestor commented Jan 23, 2015

I'll test this next Friday, as I'm busy with something else till then. Thanks!

@Kwestor
Copy link
Contributor Author

Kwestor commented Jan 30, 2015

Hi,

I tested sample from https://github.com/scoverage/gradle-scoverage-sample and have some problems with generating report:

C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests>gradle reportScoverage
:a:compileJava UP-TO-DATE
:a:compileScala
:a:processResources UP-TO-DATE
:a:classes
:a:compileScoverageJava UP-TO-DATE
:a:compileScoverageScala
:a:compileTestJava UP-TO-DATE
:a:compileTestScala UP-TO-DATE
:a:processTestResources UP-TO-DATE
:a:testClasses UP-TO-DATE
:a:testScoverage SKIPPED
:a:reportScoverage SKIPPED
:a:jar
:a:processScoverageResources UP-TO-DATE
:a:scoverageClasses
:a-tests:compileJava UP-TO-DATE
:a-tests:compileScala UP-TO-DATE
:a-tests:processResources UP-TO-DATE
:a-tests:classes UP-TO-DATE
:a-tests:compileScoverageJava UP-TO-DATE
:a-tests:compileScoverageScala UP-TO-DATE
:a-tests:compileTestJava UP-TO-DATE
:a-tests:compileTestScala
[ant:scalac] Element 'C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a-tests\build\classes\main' does not exist.
[ant:scalac] Element 'C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a-tests\build\resources\main' does not exist.
:a-tests:processTestResources UP-TO-DATE
:a-tests:testClasses
:a-tests:testScoverage
:a-tests:reportScoverage
Exception in thread "main" java.io.FileNotFoundException: C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a\build\reports\scoverage\C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a\src\main\scala\Hello.scala.html (The filename, directory name, or volume label syntax is incorrect)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
        at java.io.FileWriter.<init>(FileWriter.java:90)
        at scoverage.IOUtils$.writeToFile(IOUtils.scala:39)
        at scoverage.report.ScoverageHtmlWriter.scoverage$report$ScoverageHtmlWriter$$writeFile(ScoverageHtmlWriter.scala:42)
        at scoverage.report.ScoverageHtmlWriter$$anonfun$scoverage$report$ScoverageHtmlWriter$$writePackage$1.apply(ScoverageHtmlWriter.scala:35)
        at scoverage.report.ScoverageHtmlWriter$$anonfun$scoverage$report$ScoverageHtmlWriter$$writePackage$1.apply(ScoverageHtmlWriter.scala:35)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at scoverage.report.ScoverageHtmlWriter.scoverage$report$ScoverageHtmlWriter$$writePackage(ScoverageHtmlWriter.scala:35)
        at scoverage.report.ScoverageHtmlWriter$$anonfun$write$1.apply(ScoverageHtmlWriter.scala:23)
        at scoverage.report.ScoverageHtmlWriter$$anonfun$write$1.apply(ScoverageHtmlWriter.scala:23)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at scoverage.report.ScoverageHtmlWriter.write(ScoverageHtmlWriter.scala:23)
        at org.scoverage.ScoverageReport.main(ScoverageReport.java:35)
:a-tests:reportScoverage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':a-tests:reportScoverage'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.949 secs

It looks like wrong path is generated.

testScoverage works ok.

@maiflai
Copy link
Contributor

maiflai commented Jan 30, 2015

Thanks - this appears to be a duplicate of #80. I'm not sure I agree with the diagnosis there, but I'll take a look upstream.

@Kwestor
Copy link
Contributor Author

Kwestor commented Feb 3, 2015

Maybe, but here I did not run aggregate task, only report. I'll look into that.

@Kwestor
Copy link
Contributor Author

Kwestor commented Feb 3, 2015

Problem lies in ScoverageHtmlWriter.writeFile. It calculates relative paths like this:

private def relativeSource(src: String): String =
  src.replace(sourceDirectory.getCanonicalPath + File.separator, "")

And in this case (tests in separate module) values looks like this:

src = "C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a\src\main\scala\Hello.scala"
sourceDirectory.getCanonicalPath = "C:\Users\Jerzy\Workspaces\GitHub\scoverage\gradle-scoverage-sample\separate-tests\a-tests\src\main\scala"

Second one is not a prefix of first, and this generates incorrect paths.

@Kwestor
Copy link
Contributor Author

Kwestor commented Feb 3, 2015

@sksamuel do you have some idea about how to handle this problem?

@sksamuel
Copy link
Member

sksamuel commented Feb 3, 2015

We need to handle both the location of the source and the package name
seperately when generating the statement coverage I assume.

On 3 February 2015 at 16:12, Jerzy Müller [email protected] wrote:

@sksamuel https://github.com/sksamuel do you have some idea about how
to handle this problem?


Reply to this email directly or view it on GitHub
#79 (comment)
.

@Kwestor
Copy link
Contributor Author

Kwestor commented Feb 18, 2015

@sksamuel @maiflai I now have version that work if you have all main sources in one project, and all test sources in another (this commit).

Unfortunately, as soon as you add something to main source set in test project, html report generation fails relativeSource method assumes both sourceDirectory.getAbsolutePath is a prefix of measured file path.

On windows this fails immediately, as you cannot have to c:\ in your path, on unix it just generates wrong paths to html files and report is broken (see this commit for repro).

I can fix this (we really like to include scoverage in our project) and contribute a fix, but some guidance on how you want to tackle this problem will be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants