- added a new version checking test

- updates to the docs
This commit is contained in:
Ceki Gulcu 2008-10-03 17:56:46 +00:00
parent 61f63d36fc
commit f4e21dc7e0
6 changed files with 152 additions and 32 deletions

View File

@ -1,5 +1,14 @@
<project name="integration" default="testAll" basedir=".">
<!--
This build file is usually run indirectly via Maven.
When running this build file through Ant diretly, you must
define the currentVersion property on the command line, e.g.:
ant -DcurrentVersion=1.5.4-SNAPSHOT
-->
<echo message="compile classpath: ${compile_classpath}" />
<echo message="runtime classpath: ${runtime_classpath}" />
<echo message="test classpath: ${test_classpath}" />
@ -12,27 +21,41 @@
<pathelement location="./lib/slf4j-simple-1.5.0.jar" />
</path >
<path id="pathCurrent">
<pathelement location="xtarget/classes/" />
<pathelement location="target/test-classes/" />
<pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" />
<pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" />
</path >
<!-- this is really very ugly, but it's the only way to circumvent
http://jira.codehaus.org/browse/MANTRUN-95
-->
<taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
<target name="testAll">
<echo>Running unit tests via Ant</echo>
<echo>basedir=${basedir}</echo>
<echo>user.home=${user.home}</echo>
<target name="init">
<mkdir dir="target/unit-reports" />
</target>
<target name="testAll" depends="init,
testPre154,
testMatch">
</target>
<target name="testPre154">
<junit printsummary="yes" fork="no" haltonfailure="yes">
<classpath refid="path150" />
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.VersionTest" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.Pre154VersionMismatchTest" />
</junit>
</target>
<target name="testMatch">
<junit printsummary="yes" fork="no" haltonfailure="yes">
<classpath refid="pathCurrent" />
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.VersionMatchTest" />
</junit>
</target>
</project>

View File

@ -0,0 +1,43 @@
package org.slf4j;
import java.io.PrintStream;
import java.util.Random;
import junit.framework.TestCase;
public class Pre154VersionMismatchTest extends TestCase {
StringPrintStream sps = new StringPrintStream(System.err);
PrintStream old = System.err;
int diff = 1024 + new Random().nextInt(10000);
public Pre154VersionMismatchTest(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
System.setErr(sps);
}
protected void tearDown() throws Exception {
super.tearDown();
System.setErr(old);
}
public void test() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
String msg = "hello world "+diff;
logger.info(msg);
String s0 = (String) sps.stringList.get(0);
assertTrue(s0.startsWith("SLF4J: The version of your slf4j-binding is probably older than 1.5.4"));
String s1 = (String) sps.stringList.get(1);
assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH));
String s2 = (String) sps.stringList.get(2);
assertTrue(s2.contains(msg));
}
}

View File

@ -0,0 +1,34 @@
package org.slf4j;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
public class StringPrintStream extends PrintStream {
public static final String LINE_SEP = System.getProperty("line.separator");
PrintStream other;
List stringList = new ArrayList();
public StringPrintStream(PrintStream ps) {
super(ps);
other = ps;
}
public void print(String s) {
other.print(s);
stringList.add(s);
}
public void println(String s) {
other.println(s);
stringList.add(s);
}
public void println(Object o) {
other.println(o);
stringList.add(o);
}
}

View File

@ -0,0 +1,38 @@
package org.slf4j;
import java.io.PrintStream;
import java.util.Random;
import junit.framework.TestCase;
public class VersionMatchTest extends TestCase {
StringPrintStream sps = new StringPrintStream(System.err);
PrintStream old = System.err;
int diff = 1024 + new Random().nextInt(10000);
public VersionMatchTest(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
System.setErr(sps);
}
protected void tearDown() throws Exception {
super.tearDown();
System.setErr(old);
}
public void test() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
String msg = "hello world "+diff;
logger.info(msg);
assertEquals(1, sps.stringList.size());
String s0 = (String) sps.stringList.get(0);
assertTrue(s0.contains(msg));
}
}

View File

@ -1,24 +0,0 @@
package org.slf4j;
import junit.framework.TestCase;
public class VersionTest extends TestCase {
public VersionTest(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void test() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.info("hello world");
}
}

View File

@ -37,6 +37,11 @@ prefix='';
href="http://bugzilla.slf4j.org/show_bug.cgi?id=102">packaging
problems</a> related to <em>slf4j-ext</em> module.
</p>
<p>At initialization time, LoggerFactory will check that the version
of the slf4j-binding matches that of slf4j-api. If there is a
mismatch a warning will be issued on the console. This should help
our users identify SLF4J related problems more quickly.</p>
<p>We now say that markers contain <em>references</em> to other
markers. We no longer talk about child markers. The javadocs of the
@ -47,6 +52,7 @@ prefix='';
</p>
<hr noshade="noshade" size="1"/>
<h3>September 12th, 2008 - Release of SLF4J 1.5.3</h3>