From 2689ff4d3fd55272096a5199f76536eb5e5fb25a Mon Sep 17 00:00:00 2001 From: Stu Date: Sat, 21 Jun 2014 12:13:53 +0100 Subject: [PATCH 1/2] simple acceptance test --- build.gradle | 4 +++ .../org/scoverage/PluginAcceptanceTest.groovy | 22 +++++++++++++++ src/test/happyday/build.gradle | 27 +++++++++++++++++++ .../happyday/src/main/scala/hello/World.scala | 5 ++++ .../src/test/scala/hello/WorldTest.scala | 10 +++++++ 5 files changed, 68 insertions(+) create mode 100644 src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy create mode 100644 src/test/happyday/build.gradle create mode 100644 src/test/happyday/src/main/scala/hello/World.scala create mode 100644 src/test/happyday/src/test/scala/hello/WorldTest.scala diff --git a/build.gradle b/build.gradle index 7203b1a..22575c1 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,10 @@ task sourcesJar(type: Jar) { classifier = 'sources' } +test { + dependsOn jar +} + artifacts { archives jar archives groovydocJar diff --git a/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy b/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy new file mode 100644 index 0000000..7ad5ff0 --- /dev/null +++ b/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy @@ -0,0 +1,22 @@ +package org.scoverage + +import org.gradle.tooling.GradleConnector +import org.junit.Test + +import static org.junit.Assert.assertThat +import static org.hamcrest.core.Is.is + +class PluginAcceptanceTest { + + @Test + public void testProjectWithCompleteCoverage() throws Exception { + def build = GradleConnector. + newConnector(). + forProjectDirectory(new File("src/test/happyday")). + connect().newBuild() + build.forTasks('clean', 'checkScoverage').run() + + def html = new File('src/test/happyday/build/reports/scoverage/index.html') + assertThat('an HTML file should be created at ' + html.absolutePath, html.exists(), is(true)) + } +} diff --git a/src/test/happyday/build.gradle b/src/test/happyday/build.gradle new file mode 100644 index 0000000..fa85c2b --- /dev/null +++ b/src/test/happyday/build.gradle @@ -0,0 +1,27 @@ +description = 'a project that builds successfully with 100% coverage' + +buildscript { + repositories { + // need to get up to the working directory of gradle-plugins build + flatDir dir: "${project.projectDir}/../../../build/libs" + } + dependencies { + classpath name: 'gradle-scoverage', version: '+' + } +} + +apply plugin: 'scoverage' + +repositories { + mavenCentral() +} + +dependencies { + scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:0.99.5' + compile 'org.scala-lang:scala-library:2.11.0' + testCompile 'junit:junit:4.11' +} + +checkScoverage { + minimumLineRate = 1.0 +} \ No newline at end of file diff --git a/src/test/happyday/src/main/scala/hello/World.scala b/src/test/happyday/src/main/scala/hello/World.scala new file mode 100644 index 0000000..7a1589a --- /dev/null +++ b/src/test/happyday/src/main/scala/hello/World.scala @@ -0,0 +1,5 @@ +package hello + +object World { + def say() = println("ahoy") +} \ No newline at end of file diff --git a/src/test/happyday/src/test/scala/hello/WorldTest.scala b/src/test/happyday/src/test/scala/hello/WorldTest.scala new file mode 100644 index 0000000..a087efa --- /dev/null +++ b/src/test/happyday/src/test/scala/hello/WorldTest.scala @@ -0,0 +1,10 @@ +package hello + +import org.junit.Test + +class WorldTest { + @Test + def bob() { + World.say() + } +} \ No newline at end of file From 38700ca2f9a09da1ab26bfef6581eb91b6d80910 Mon Sep 17 00:00:00 2001 From: Stu Date: Sat, 21 Jun 2014 12:14:23 +0100 Subject: [PATCH 2/2] incorrect location for report file --- .../groovy/org/scoverage/OverallCheckTask.groovy | 2 +- .../org/scoverage/ScoverageExtension.groovy | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/groovy/org/scoverage/OverallCheckTask.groovy b/src/main/groovy/org/scoverage/OverallCheckTask.groovy index 4831156..0a1bb34 100644 --- a/src/main/groovy/org/scoverage/OverallCheckTask.groovy +++ b/src/main/groovy/org/scoverage/OverallCheckTask.groovy @@ -15,7 +15,7 @@ class OverallCheckTask extends DefaultTask { void requireLineCoverage() { def extension = ScoveragePlugin.extensionIn(project) - if (cobertura == null) cobertura = new File(extension.dataDir, 'cobertura.xml') + if (cobertura == null) cobertura = new File(extension.reportDir, 'cobertura.xml') def xml = new XmlParser().parse(cobertura) def overallLineRate = xml.attribute('line-rate').toDouble() diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index ee0b596..9ffdb9c 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -21,8 +21,7 @@ class ScoverageExtension { /** a directory to write final output to */ File reportDir /** sources to highlight */ - SourceSet sourceSet - + File sources ScoverageExtension(Project project) { @@ -36,7 +35,7 @@ class ScoverageExtension { description = 'Scoverage dependencies' } - sourceSet = project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) { + project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) { def mainSourceSet = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) java.source(mainSourceSet.java) @@ -50,17 +49,16 @@ class ScoverageExtension { dependsOn(project.tasks[ScoveragePlugin.COMPILE_NAME]) } - project.tasks.create(ScoveragePlugin.CHECK_NAME, OverallCheckTask.class) { + project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) { dependsOn(project.tasks[ScoveragePlugin.TEST_NAME]) } - project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) { - dependsOn(project.tasks[ScoveragePlugin.TEST_NAME]) + project.tasks.create(ScoveragePlugin.CHECK_NAME, OverallCheckTask.class) { + dependsOn(project.tasks[ScoveragePlugin.REPORT_NAME]) } dataDir = new File(project.buildDir, 'scoverage') reportDir = new File(project.buildDir, 'reports' + File.separatorChar + 'scoverage') - } private Action configureRuntimeOptions = new Action() { @@ -69,6 +67,7 @@ class ScoverageExtension { void execute(Project t) { def extension = ScoveragePlugin.extensionIn(t) + extension.sources = t.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).scala.srcDirs.iterator().next() as File extension.dataDir.mkdirs() extension.reportDir.mkdirs() @@ -102,7 +101,7 @@ class ScoverageExtension { project.configurations[ScoveragePlugin.CONFIGURATION_NAME] main = 'org.scoverage.ScoverageReport' args = [ - extension.sourceSet.allSource.iterator().next().absolutePath, + extension.sources, extension.dataDir.absolutePath, extension.reportDir.absolutePath ]