You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2005/07/04 15:35:26 UTC
svn commit: r209073 - in /ant/sandbox/antlibs/antunit/trunk: docs/
src/etc/testcases/antunit/ src/main/org/apache/ant/antunit/
src/testcases/org/apache/ant/antunit/
Author: bodewig
Date: Mon Jul 4 06:35:24 2005
New Revision: 209073
URL: http://svn.apache.org/viewcvs?rev=209073&view=rev
Log:
Make log output available to test runs
Added:
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java (with props)
Modified:
ant/sandbox/antlibs/antunit/trunk/docs/antunit.html
ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/antunit/base.xml
ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
Modified: ant/sandbox/antlibs/antunit/trunk/docs/antunit.html
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/docs/antunit.html?rev=209073&r1=209072&r2=209073&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/docs/antunit.html (original)
+++ ant/sandbox/antlibs/antunit/trunk/docs/antunit.html Mon Jul 4 06:35:24 2005
@@ -36,6 +36,61 @@
Currently only a single implementation of this interface is
provided with this ant library.</p>
+ <p>Log output during each antunit test case is captured by an
+ instance of the LogCapturer class that is available via a project
+ reference named ant.antunit.log. The published interface of that
+ class is:</p>
+
+ <pre>
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ant.antunit;
+
+public class LogCapturer {
+ public static final String REFERENCE_ID = "ant.antunit.log";
+
+ /**
+ * All messages with <code>logLevel == Project.MSG_ERR</code>.
+ */
+ public String getErrLog();
+ /**
+ * All messages with <code>logLevel == Project.MSG_WARN</code> or
+ * more severe.
+ */
+ public String getWarnLog();
+ /**
+ * All messages with <code>logLevel == Project.MSG_INFO</code> or
+ * more severe.
+ */
+ public String getInfoLog();
+ /**
+ * All messages with <code>logLevel == Project.MSG_VERBOSE</code> or
+ * more severe.
+ */
+ public String getVerboseLog();
+ /**
+ * All messages with <code>logLevel == Project.MSG_DEBUG</code> or
+ * more severe.
+ */
+ public String getDebugLog();
+}
+</pre>
+
<h3>Parameters</h3>
<p>This task doesn't support any attributes.</p>
Modified: ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/antunit/base.xml
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/antunit/base.xml?rev=209073&r1=209072&r2=209073&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/antunit/base.xml (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/etc/testcases/antunit/base.xml Mon Jul 4 06:35:24 2005
@@ -45,6 +45,10 @@
<fail message="test5 exits with error"/>
</target>
+ <target name="testLogCaptureActive">
+ <au:assertReferenceSet refid="ant.antunit.log"/>
+ </target>
+
<target name="tearDown">
<echo>tearDown</echo>
</target>
Modified: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java?rev=209073&r1=209072&r2=209073&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/AntUnit.java Mon Jul 4 06:35:24 2005
@@ -107,6 +107,7 @@
v.add(SETUP);
}
v.add(name);
+ LogCapturer lc = new LogCapturer(newProject);
try {
newProject.executeTargets(v);
} catch (AssertionFailedException e) {
Added: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java?rev=209073&view=auto
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java (added)
+++ ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java Mon Jul 4 06:35:24 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.ant.antunit;
+
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildListener;
+import org.apache.tools.ant.Project;
+
+/**
+ * Captures log messages generated during an antunit task run and
+ * makes it available to tasks via a project reference.
+ *
+ * <p>This class captures all messaged generated during the build and
+ * adds itself as project reference to the project using the id
+ * <code>ant.antunit.log</code>.</p>
+ */
+public class LogCapturer implements BuildListener {
+ public static final String REFERENCE_ID = "ant.antunit.log";
+
+ private StringBuffer err = new StringBuffer();
+ private StringBuffer warn = new StringBuffer();
+ private StringBuffer info = new StringBuffer();
+ private StringBuffer verbose = new StringBuffer();
+ private StringBuffer debug = new StringBuffer();
+ private Project p;
+
+ public LogCapturer(Project p) {
+ this.p = p;
+ p.addBuildListener(this);
+ p.addReference(REFERENCE_ID, this);
+ }
+
+ /**
+ * All messages with <code>logLevel == Project.MSG_ERR</code>.
+ */
+ public String getErrLog() {
+ return err.toString();
+ }
+ /**
+ * All messages with <code>logLevel == Project.MSG_WARN</code> or
+ * more severe.
+ */
+ public String getWarnLog() {
+ return warn.toString();
+ }
+ /**
+ * All messages with <code>logLevel == Project.MSG_INFO</code> or
+ * more severe.
+ */
+ public String getInfoLog() {
+ return info.toString();
+ }
+ /**
+ * All messages with <code>logLevel == Project.MSG_VERBOSE</code> or
+ * more severe.
+ */
+ public String getVerboseLog() {
+ return verbose.toString();
+ }
+ /**
+ * All messages with <code>logLevel == Project.MSG_DEBUG</code> or
+ * more severe.
+ */
+ public String getDebugLog() {
+ return debug.toString();
+ }
+
+ /**
+ * Empty.
+ */
+ public void buildStarted(BuildEvent event) {}
+ /**
+ * Empty.
+ */
+ public void targetStarted(BuildEvent event) {}
+ /**
+ * Empty.
+ */
+ public void targetFinished(BuildEvent event) {}
+ /**
+ * Empty.
+ */
+ public void taskStarted(BuildEvent event) {}
+ /**
+ * Empty.
+ */
+ public void taskFinished(BuildEvent event) {}
+
+ /**
+ * De-register.
+ */
+ public void buildFinished(BuildEvent event) {
+ if (p != null && event.getProject() == p) {
+ p.removeBuildListener(this);
+ p.getReferences().remove(REFERENCE_ID);
+ p = null;
+ }
+ }
+ /**
+ * Record the message.
+ */
+ public void messageLogged(BuildEvent event) {
+ if (event.getPriority() <= Project.MSG_ERR) {
+ err.append(event.getMessage());
+ }
+ if (event.getPriority() <= Project.MSG_WARN) {
+ warn.append(event.getMessage());
+ }
+ if (event.getPriority() <= Project.MSG_INFO) {
+ info.append(event.getMessage());
+ }
+ if (event.getPriority() <= Project.MSG_VERBOSE) {
+ verbose.append(event.getMessage());
+ }
+ if (event.getPriority() <= Project.MSG_DEBUG) {
+ debug.append(event.getMessage());
+ }
+ }
+}
\ No newline at end of file
Propchange: ant/sandbox/antlibs/antunit/trunk/src/main/org/apache/ant/antunit/LogCapturer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java
URL: http://svn.apache.org/viewcvs/ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java?rev=209073&r1=209072&r2=209073&view=diff
==============================================================================
--- ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java (original)
+++ ant/sandbox/antlibs/antunit/trunk/src/testcases/org/apache/ant/antunit/AntUnitTest.java Mon Jul 4 06:35:24 2005
@@ -37,7 +37,7 @@
index = log.indexOf("sandbox/antlibs/antunit/trunk/src/etc/testcases/"
+ "antunit/base.xml", index);
assertTrue("file name", index > -1);
- index = log.indexOf("Tests run: 4, Failures: 1, Errors: 1, Time "
+ index = log.indexOf("Tests run: 5, Failures: 1, Errors: 1, Time "
+ "elapsed: ", index);
assertTrue("summary", index > -1);
assertTrue("test1", log.indexOf("test1", index) > -1);
@@ -45,6 +45,8 @@
assertTrue("test3", log.indexOf("test3", index) == -1);
assertTrue("test4", log.indexOf("test4", index) > -1);
assertTrue("test5", log.indexOf("test5", index) > -1);
+ assertTrue("testLogCaptureActive",
+ log.indexOf("testLogCaptureActive", index) > -1);
int index2 = log.indexOf("Caused an ERROR", index);
assertTrue("test5 error", index2 > -1
&& log.indexOf("test5 exits with error", index2) > -1);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org