Skip to content

Commit

Permalink
Added cobertura code coverage and started to clean up some cruftiness…
Browse files Browse the repository at this point in the history
… in the io package
  • Loading branch information
aslakhellesoy committed May 1, 2012
1 parent a85cfde commit b4fbfb9
Show file tree
Hide file tree
Showing 23 changed files with 371 additions and 189 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ chromedriver.log
nexus.properties
pom.xml.releaseBackup
release.properties
*.ser

# OS generated files
.DS_Store*
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ mvn --batch-mode -P release-sign-artifacts release:prepare -DautoVersionSubmodul
mvn -P release-sign-artifacts release:perform
```

## Code Coverage

Code coverage is collected mainly to identify code that can be deleted or needs to be tested better.
To generate a report, run:

```
COBERTURA_HOME=/some/where ./coverage.sh
```

This technique to collect coverage for a multi-module Maven project is based on a
[blog post](http://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/) by Thomas Sundberg.

## Migration from Cuke4Duke

Expand Down
121 changes: 64 additions & 57 deletions clojure/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -13,63 +14,69 @@
<name>Cucumber-JVM: Clojure</name>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<namespaces>
<namespace>cucumber.*</namespace>
</namespaces>
<sourceDirectories>
<sourceDirectory>src/main/clj</sourceDirectory>
</sourceDirectories>
<compileDeclaredNamespaceOnly>true</compileDeclaredNamespaceOnly>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.10</version>
<configuration>
<namespaces>
<namespace>cucumber.*</namespace>
</namespaces>
<sourceDirectories>
<sourceDirectory>src/main/clj</sourceDirectory>
</sourceDirectories>
<compileDeclaredNamespaceOnly>true</compileDeclaredNamespaceOnly>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions cobertura.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

if [ -z "$COBERTURA_HOME" ]; then
echo "You need to define COBERTURA_HOME"
exit 1
fi

mvn clean compile
ant -f cobertura.xml instrument
mvn test
ant -f cobertura.xml report
91 changes: 91 additions & 0 deletions cobertura.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<project>
<target name="instrument">
<!-- we don't bother with the clojure and scala modules -->
<antcall target="instrumentAModule">
<param name="module" value="core"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="groovy"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="guice"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="ioke"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="java"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="jruby"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="junit"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="jython"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="openejb"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="picocontainer"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="rhino"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="spring"/>
</antcall>
<antcall target="instrumentAModule">
<param name="module" value="weld"/>
</antcall>
</target>

<target name="report" depends="merge">
<property name="src.dir" value="src/main/java/"/>
<cobertura-report datafile="sum.ser"
format="html"
destdir="./target/report">
<fileset dir="./core/${src.dir}"/>
<fileset dir="./groovy/${src.dir}"/>
<fileset dir="./guice/${src.dir}"/>
<fileset dir="./ioke/${src.dir}"/>
<fileset dir="./java/${src.dir}"/>
<fileset dir="./jruby/${src.dir}"/>
<fileset dir="./junit/${src.dir}"/>
<fileset dir="./jython/${src.dir}"/>
<fileset dir="./picocontainer/${src.dir}"/>
<fileset dir="./rhino/${src.dir}"/>
<fileset dir="./spring/${src.dir}"/>
<fileset dir="./weld/${src.dir}"/>
</cobertura-report>
</target>

<target name="merge">
<cobertura-merge datafile="sum.ser">
<fileset dir=".">
<include name="**/cobertura.ser"/>
</fileset>
</cobertura-merge>
</target>

<target name="instrumentAModule">
<property name="classes.dir" value="target/classes"/>
<cobertura-instrument todir="${module}/${classes.dir}">
<fileset dir="${module}/target/classes">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
</target>

<property environment="env"/>
<property name="cobertura.dir" value="${env.COBERTURA_HOME}"/>
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar"/>
<include name="lib/**/*.jar"/>
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
</project>
6 changes: 5 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
<artifactId>js</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/io/FileResourceIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import static java.util.Arrays.asList;

public class FileResourceIterator implements Iterator<Resource> {
private final FlatteningIterator flatteningIterator;
private final FlatteningIterator flatteningIterator = new FlatteningIterator();

public FileResourceIterator(File root, File file, final String suffix) {
FileFilter filter = new FileFilter() {
Expand All @@ -18,7 +18,7 @@ public boolean accept(File file) {
return file.isDirectory() || hasSuffix(suffix, file.getPath());
}
};
this.flatteningIterator = new FlatteningIterator(new FileIterator(root, file, filter));
flatteningIterator.push(new FileIterator(root, file, filter));
}

@Override
Expand Down
Loading

0 comments on commit b4fbfb9

Please sign in to comment.