From bb23f0df317e576dad9e6154166be3ac0c662714 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
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:
+ +
+/*
+ * 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 logLevel == Project.MSG_ERR.
+ */
+ public String getErrLog();
+ /**
+ * All messages with logLevel == Project.MSG_WARN or
+ * more severe.
+ */
+ public String getWarnLog();
+ /**
+ * All messages with logLevel == Project.MSG_INFO or
+ * more severe.
+ */
+ public String getInfoLog();
+ /**
+ * All messages with logLevel == Project.MSG_VERBOSE or
+ * more severe.
+ */
+ public String getVerboseLog();
+ /**
+ * All messages with logLevel == Project.MSG_DEBUG or
+ * more severe.
+ */
+ public String getDebugLog();
+}
+
+
This task doesn't support any attributes.
diff --git a/src/etc/testcases/antunit/base.xml b/src/etc/testcases/antunit/base.xml index 73d9a66..f4df687 100644 --- a/src/etc/testcases/antunit/base.xml +++ b/src/etc/testcases/antunit/base.xml @@ -45,6 +45,10 @@This class captures all messaged generated during the build and
+ * adds itself as project reference to the project using the id
+ * ant.antunit.log.
logLevel == Project.MSG_ERR.
+ */
+ public String getErrLog() {
+ return err.toString();
+ }
+ /**
+ * All messages with logLevel == Project.MSG_WARN or
+ * more severe.
+ */
+ public String getWarnLog() {
+ return warn.toString();
+ }
+ /**
+ * All messages with logLevel == Project.MSG_INFO or
+ * more severe.
+ */
+ public String getInfoLog() {
+ return info.toString();
+ }
+ /**
+ * All messages with logLevel == Project.MSG_VERBOSE or
+ * more severe.
+ */
+ public String getVerboseLog() {
+ return verbose.toString();
+ }
+ /**
+ * All messages with logLevel == Project.MSG_DEBUG 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
diff --git a/src/testcases/org/apache/ant/antunit/AntUnitTest.java b/src/testcases/org/apache/ant/antunit/AntUnitTest.java
index 411b3e4..21f2b45 100644
--- a/src/testcases/org/apache/ant/antunit/AntUnitTest.java
+++ b/src/testcases/org/apache/ant/antunit/AntUnitTest.java
@@ -37,7 +37,7 @@ public class AntUnitTest extends BuildFileTest {
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 @@ public class AntUnitTest extends BuildFileTest {
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);