Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/KentBeck/junit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Glick committed Sep 19, 2011
2 parents cb69050 + 0a23cd6 commit e0f84b7
Show file tree
Hide file tree
Showing 53 changed files with 1,474 additions and 177 deletions.
33 changes: 33 additions & 0 deletions acknowledgements.txt
Expand Up @@ -104,9 +104,18 @@
Samuel Le Berrigaud (sleberrigaud@github): Report for GH-248:
protected BlockJUnit4ClassRunner#rules method removed from 4.8.2

2011 Jun 24
Daniel Rothmaler (drothmaler@github):
#299: random temp file/folder creation
#300: ErrorCollector.checkThat overload

2011 Jul 06
Stefan Birkner: Fixed wrong documentation of ClassRule (github#254).

2011 Jul 08
Paul Holser (pholser@alumni.rice.edu): Beginnings of fix for GH-64:
Theories doesn't honor parameterized types

2011 Jul 09
Nigel Charman: Reported Rules bugs github#257 and gihub#258.

Expand All @@ -116,11 +125,35 @@
2011 Jul 09
Stefan Birkner: Fixed rules bugs (github#257, gihub#258, github#260).

2011 Jul 16
Rob Dawson: Submitted a patch that makes Results serlializable.

2011 Jul 20
Asaf Ary, Stefan Birkner: Fixed FailOnTimeout class (github#265).

2011 Jul 22
Andreas Köhler, Stefan Birkner: Fixed wrong documentation of Parameterized (github#89).

2011 Jul 28
electrickery, Stefan Birkner: Fixed typo in JavaDoc (github#134).

2011 Aug 07
Esko Luontola: Fixed TemporaryFolder creating files in the current working directory (github#278).

2011 Aug 09
Stefan Birkner: Fixed JavaDoc links.

2011 Aug 10
rodolfoliviero@github and JoseRibeiro@github: feature to create recursive temporary folders.

2011 Aug 12
Esko Luontola: Fixed syntax error in Parameterized's usage example (github#285).

2011 Sep 09
Robert Munteanu, Stefan Birkner:
TestWatcher and TestWatchman don't call failed when assumption is violated (github#296).
digulla@github, Stefan Birkner: Removed useless code (github#289).

== NOTE: as of September 2011, we have stopped recording contributions here.
For a full list of everyone who has contributed great bug reports and code, please see
http://github.com/KentBeck/junit
81 changes: 59 additions & 22 deletions build.xml
@@ -1,13 +1,14 @@
<project name="junit" default="dist" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<tstamp />
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

<property file="${user.home}/.junit.properties" />
<property name="src" value="src/main/java" />
<property name="target" location="target" />
<property name="bin" location="${target}/main" />
<property name="version-base" value="4.9" />
<property name="version-status" value="" />
<property name="version-base" value="4.10" />
<property name="version-status" value="-SNAPSHOT" />
<property name="version" value="${version-base}${version-status}" />
<property name="dist" value="junit${version}" />
<property name="versionfile" value="${src}/junit/runner/Version.java" />
Expand Down Expand Up @@ -132,7 +133,7 @@

<target name="release-notes">
<property name="basename" value="doc/ReleaseNotes${version-base}" />
<exec executable="build/Markdown.pl">
<exec executable="build/Markdown.pl" failonerror="true">
<arg file="${basename}.txt"/>
<redirector output="${basename}.html" />
</exec>
Expand Down Expand Up @@ -218,19 +219,18 @@

<!-- to do automatic build upload, you need the maven ant tasks jar. -->
<!-- therefore, you must run ant as ant -lib build/lib stage.maven -->
<macrodef name="stage.maven.jar">
<macrodef name="push.maven.jar">
<attribute name="jar" />
<attribute name="pom" />
<attribute name="url" />
<attribute name="repo.id" />
<element name="artifact.args" implicit="true" optional="true" />
<sequential>
<property name="maven-repository-url"
value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
<property name="maven-repository-id" value="sonatype-nexus-staging" />
<echo message="Staging to maven: @{jar}" />
<echo message="Pushing to maven: @{jar} -> @{url}" />
<artifact:mvn failonerror="true">
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.1:sign-and-deploy-file" />
<arg value="-Durl=${maven-repository-url}" />
<arg value="-DrepositoryId=${maven-repository-id}" />
<arg value="-Durl=@{url}" />
<arg value="-DrepositoryId=@{repo.id}" />
<arg value="-DpomFile=@{pom}" />
<arg value="-Dfile=@{jar}" />
<artifact.args />
Expand All @@ -239,40 +239,77 @@
</sequential>
</macrodef>

<macrodef name="stage.maven.artifactId">
<macrodef name="push.maven.artifact">
<attribute name="artifactId" />
<attribute name="url" />
<attribute name="repo.id" />
<attribute name="is.snapshot" default="false" />
<sequential>
<local name="m.prefix" />
<property name="m.prefix" value="${dist}/@{artifactId}-${version}" />
<local name="m.jar" />
<property name="m.jar" value="${m.prefix}.jar" />
<local name="m.sources.jar" />
<property name="m.sources.jar" value="${m.prefix}-src.jar" />
<local name="m.javadoc.jar" />
<property name="m.javadoc.jar" value="${m.prefix}-javadoc.jar" />
<local name="m.pom" />
<property name="m.pom" value="${dist}/pom-@{artifactId}.xml" />

<filter token="version" value="${version}" />
<filter token="artifactId" value="@{artifactId}" />

<copy
file="pom-template.xml"
file="build/maven/pom-template.xml"
tofile="${m.pom}"
filtering="on"
overwrite="true"
/>

<stage.maven.jar jar="${m.jar}" pom="${m.pom}" />

<stage.maven.jar jar="${m.sources.jar}" pom="${m.pom}" >
<arg value="-Dclassifier=sources" />
</stage.maven.jar>
<push.maven.jar jar="${m.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}" />

<if>
<equals arg1="${is.snapshot}" arg2="false" />
<then>
<push.maven.jar jar="${m.sources.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}">
<arg value="-Dclassifier=sources" />
</push.maven.jar>

<stage.maven.jar jar="${m.javadoc.jar}" pom="${m.pom}" >
<arg value="-Dclassifier=javadoc" />
</stage.maven.jar>
<push.maven.jar jar="${m.javadoc.jar}" pom="${m.pom}"
url="@{url}" repo.id="@{repo.id}">
<arg value="-Dclassifier=javadoc" />
</push.maven.jar>
</then>
</if>
</sequential>
</macrodef>

<target name="stage.maven" depends="all.maven.jars">
<stage.maven.artifactId artifactId="junit" />
<stage.maven.artifactId artifactId="junit-dep" />
<property name="stage.url"
value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
<property name="stage.repo.id" value="sonatype-nexus-staging" />

<push.maven.artifact artifactId="junit"
url="${stage.url}"
repo.id="${stage.repo.id}" />
<push.maven.artifact artifactId="junit-dep"
url="${stage.url}"
repo.id="${stage.repo.id}" />
</target>

<target name="snapshot.maven" depends="all.maven.jars">
<property name="snapshot.url"
value="https://oss.sonatype.org/content/repositories/snapshots/" />
<property name="snapshot.repo.id" value="sonatype-nexus-snapshots" />

<push.maven.artifact artifactId="junit"
url="${snapshot.url}"
repo.id="${snapshot.repo.id}" />
<push.maven.artifact artifactId="junit-dep"
url="${snapshot.url}"
repo.id="${snapshot.repo.id}" />
</target>

<target name="print.version">
Expand Down
Binary file added build/lib/ant-contrib-1.0b3.jar
Binary file not shown.
File renamed without changes.
49 changes: 49 additions & 0 deletions build/maven/post_maven_tests.sh
@@ -0,0 +1,49 @@
set -e
set -o pipefail

function TEST_junit_dep_49_plays_not_nicely_with_later_hamcrest {
# Make sure our system notices the bug (this broke because of a bad push)
! runs_with_newer_hamcrest junit-dep 4.9
}

function TEST_junit_dep_snapshot_plays_nicely_with_later_hamcrest {
runs_with_newer_hamcrest junit-dep LATEST
}

function TEST_junit_snapshot_plays_not_nicely_with_later_hamcrest {
! runs_with_newer_hamcrest junit LATEST
}

function runs_with_newer_hamcrest {
local artifact_id=$1
local version=$2
rm -rf ~/.m2/repository/junit
rm -rf uses_junit
cp -r sample_project_template uses_junit
sed -i '' -e "s/___ARTIFACT_ID___/$artifact_id/" uses_junit/pom.xml
sed -i '' -e "s/___VERSION___/$version/" uses_junit/pom.xml
in_dir uses_junit mvn test
finally rm -rf uses_junit
}

### <copied src="https://gist.github.com/1206506">
function in_dir {
local dir=$1
shift
if [ ! -e $dir ]; then
echo "$dir does not exist"
return 1
fi
pushd $dir >/dev/null
"$@"
finally popd >/dev/null
}

function finally {
local return_this=$?
"$@"
return $return_this
}
### </copied>

source ../run_tests.sh
61 changes: 61 additions & 0 deletions build/maven/sample_project_template/pom.xml
@@ -0,0 +1,61 @@
<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>

<groupId>com.example</groupId>
<artifactId>junit-dependency-test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.hamcrest>1.2.1</version.hamcrest>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>___ARTIFACT_ID___</artifactId>
<version>___VERSION___</version>
</dependency>

<!--
This dependency must be included *before* junit, because said JAR
contains an old hamcrest-core version. This is problematic at
runtime; see JunitDependencyTest.
If junit-dep has the right contents, the order should not matter.
-->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${version.hamcrest}</version>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${version.hamcrest}</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>Sonatype</id>
<url>https://oss.sonatype.org/content/groups/public</url>
<snapshots><enabled>true</enabled></snapshots>
<releases><enabled>true</enabled></releases>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,33 @@
import org.hamcrest.Matchers;
import org.junit.Test;

public final class JunitDependencyTest {
/**
* JUnit dependency test.
*
* This class has three dependencies. These can be on the classpath in
* different orders. Of the two orderings below, the first one will cause a
* NoSuchMethodError, while the second one allows the test to pass
* successfully. See the explanation below for more information.
*
* Ordering 1: junit-4.9, hamcrest-core-1.2.1, hamcrest-library-1.2.1.
* Ordering 2: hamcrest-core-1.2.1, junit-4.9, hamcrest-library-1.2.1.
*/
@Test
public void test() {
/*
* Note that we call Matchers#anyOf(Matcher<T>, Matcher<? super T>).
* This method is provided by hamcrest-library-1.2.1. Said module is
* compiled against hamcrest-core-1.2.1. Matchers#anyOf calls
* AnyOf#anyOf(Matcher<T>, Matcher<? super T>). The latter method is
* provided by hamcrest-core-1.2.1, but *not* by hamcrest-core-1.1.
*
* However, hamcrest-core-1.1 *does* contain a class called AnyOf. Now,
* since junit-4.9 incorporates hamcrest-core-1.1 we must make sure that
* hamcrest-core-1.2.1 is placed *before* junit-4.9 on the classpath.
* Failure to do so will cause the wrong AnyOf class to be used. The
* result is a NoSuchMethodError.
*/
Matchers.anyOf(Matchers.nullValue(), Matchers.notNullValue());
}
}
36 changes: 36 additions & 0 deletions build/run_tests.sh
@@ -0,0 +1,36 @@
# See maven/post_maven_tests.sh for an example use

SCRIPT_NAME=$0
TEST_NAME=${1:-ALL}

function get_tests() {
if [ $TEST_NAME == "ALL" ]; then
part1=function
part2=TEST_
grep "$part1 $part2" $SCRIPT_NAME | sed 's/.*\(TEST_[A-Za-z0-9_]*\).*/\1/'
else
echo "TEST_${TEST_NAME}"
fi
}

function run_tests() {
local exit_code=0

for t in $(get_tests); do
echo "RUNNING: $t"
if "$t"; then
echo "PASSED: $t"
else
echo "FAILED: $t"
return 1
fi
done
}

if run_tests; then
echo "ALL TESTS PASSED"
exit 0
else
echo "A TEST FAILED"
exit 1
fi

0 comments on commit e0f84b7

Please sign in to comment.