cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java
bodewig 2005/03/17 00:21:21 Modified:src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java Log: Don't die if Test.getName returns null, PR 29407 Revision ChangesPath 1.39 +8 -3 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java Index: XMLJUnitResultFormatter.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- XMLJUnitResultFormatter.java 22 Nov 2004 09:23:34 - 1.38 +++ XMLJUnitResultFormatter.java 17 Mar 2005 08:21:21 - 1.39 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-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. @@ -49,6 +49,9 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants { +/** constant for unnnamed testsuites/cases */ +private static final String UNKNOWN = unknown; + private static DocumentBuilder getDocumentBuilder() { try { return DocumentBuilderFactory.newInstance().newDocumentBuilder(); @@ -103,7 +106,8 @@ public void startTestSuite(JUnitTest suite) { doc = getDocumentBuilder().newDocument(); rootElement = doc.createElement(TESTSUITE); -rootElement.setAttribute(ATTR_NAME, suite.getName()); +String n = suite.getName(); +rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); //add the timestamp final String timestamp = DateUtils.format(new Date(), @@ -190,8 +194,9 @@ Element currentTest = null; if (!failedTests.containsKey(test)) { currentTest = doc.createElement(TESTCASE); +String n = JUnitVersionHelper.getTestCaseName(test); currentTest.setAttribute(ATTR_NAME, - JUnitVersionHelper.getTestCaseName(test)); + n == null ? UNKNOWN : n); // a TestSuite can contain Tests from multiple classes, // even tests with the same name - disambiguate them. currentTest.setAttribute(ATTR_CLASSNAME, - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java
bodewig 2005/03/17 00:21:46 Modified:src/main/org/apache/tools/ant/taskdefs/optional/junit Tag: ANT_16_BRANCH XMLJUnitResultFormatter.java Log: merge Revision ChangesPath No revision No revision 1.30.2.6 +8 -3 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java Index: XMLJUnitResultFormatter.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v retrieving revision 1.30.2.5 retrieving revision 1.30.2.6 diff -u -r1.30.2.5 -r1.30.2.6 --- XMLJUnitResultFormatter.java 9 Mar 2004 17:01:50 - 1.30.2.5 +++ XMLJUnitResultFormatter.java 17 Mar 2005 08:21:46 - 1.30.2.6 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-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. @@ -45,6 +45,9 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants { +/** constant for unnnamed testsuites/cases */ +private static final String UNKNOWN = unknown; + private static DocumentBuilder getDocumentBuilder() { try { return DocumentBuilderFactory.newInstance().newDocumentBuilder(); @@ -99,7 +102,8 @@ public void startTestSuite(JUnitTest suite) { doc = getDocumentBuilder().newDocument(); rootElement = doc.createElement(TESTSUITE); -rootElement.setAttribute(ATTR_NAME, suite.getName()); +String n = suite.getName(); +rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); // Output properties Element propsElement = doc.createElement(PROPERTIES); @@ -173,8 +177,9 @@ Element currentTest = null; if (!failedTests.containsKey(test)) { currentTest = doc.createElement(TESTCASE); +String n = JUnitVersionHelper.getTestCaseName(test); currentTest.setAttribute(ATTR_NAME, - JUnitVersionHelper.getTestCaseName(test)); + n == null ? UNKNOWN : n); // a TestSuite can contain Tests from multiple classes, // even tests with the same name - disambiguate them. currentTest.setAttribute(ATTR_CLASSNAME, - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java
stevel 2004/11/11 04:09:01 Modified:src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java Log: factor out close logic Revision ChangesPath 1.37 +2 -7 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java Index: XMLJUnitResultFormatter.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- XMLJUnitResultFormatter.java 14 Apr 2004 15:19:13 - 1.36 +++ XMLJUnitResultFormatter.java 11 Nov 2004 12:09:01 - 1.37 @@ -35,6 +35,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.DOMElementWriter; import org.apache.tools.ant.util.DateUtils; +import org.apache.tools.ant.util.FileUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; @@ -158,13 +159,7 @@ throw new BuildException(Unable to write log file, exc); } finally { if (out != System.out out != System.err) { -if (wri != null) { -try { -wri.close(); -} catch (IOException e) { -// ignore -} -} +FileUtils.close(wri); } } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java XMLConstants.java
stevel 2004/04/14 08:19:13 Modified:src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java XMLConstants.java Log: new attributes for the tests: hostname and timestamp. Revision ChangesPath 1.36 +23 -0 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java Index: XMLJUnitResultFormatter.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- XMLJUnitResultFormatter.java 9 Mar 2004 16:48:31 - 1.35 +++ XMLJUnitResultFormatter.java 14 Apr 2004 15:19:13 - 1.36 @@ -25,12 +25,16 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import java.util.Date; +import java.net.InetAddress; +import java.net.UnknownHostException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import junit.framework.AssertionFailedError; import junit.framework.Test; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.DOMElementWriter; +import org.apache.tools.ant.util.DateUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; @@ -100,6 +104,13 @@ rootElement = doc.createElement(TESTSUITE); rootElement.setAttribute(ATTR_NAME, suite.getName()); +//add the timestamp +final String timestamp = DateUtils.format(new Date(), +DateUtils.ISO8601_DATETIME_PATTERN); +rootElement.setAttribute(TIMESTAMP,timestamp); +//and the hostname. +rootElement.setAttribute(HOSTNAME,getHostname()); + // Output properties Element propsElement = doc.createElement(PROPERTIES); rootElement.appendChild(propsElement); @@ -113,6 +124,18 @@ propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); propsElement.appendChild(propElement); } +} +} + +/** + * get the local hostname + * @return the name of the local host, or localhost if we cannot work it out + */ +private String getHostname() { +try { +return InetAddress.getLocalHost().getHostName(); +} catch (UnknownHostException e) { +return localhost; } } 1.12 +9 -0 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.java Index: XMLConstants.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLConstants.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- XMLConstants.java 9 Mar 2004 16:48:31 - 1.11 +++ XMLConstants.java 14 Apr 2004 15:19:13 - 1.12 @@ -86,4 +86,13 @@ /** classname attribute for testcase elements */ String ATTR_CLASSNAME = classname; +/** + * timestamp of test cases + */ +String TIMESTAMP = timestamp; + +/** + * name of host running the tests + */ +String HOSTNAME = hostname; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java
bodewig 2003/03/28 04:20:51 Modified:.WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional/junit XMLJUnitResultFormatter.java Log: The xml formatter for JUnit will now honor test case names set with setName PR: 17040 Revision ChangesPath 1.379 +3 -0 ant/WHATSNEW Index: WHATSNEW === RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.378 retrieving revision 1.379 diff -u -r1.378 -r1.379 --- WHATSNEW 28 Mar 2003 08:28:15 - 1.378 +++ WHATSNEW 28 Mar 2003 12:20:50 - 1.379 @@ -195,6 +195,9 @@ * Copy has a new outputencoding attribute that can be used to change the encoding while copying files. Bugzilla Report 18217. +* The xml formatter for JUnit will now honor test case names set with + setName. Bugzilla Report 17040. + Changes from Ant 1.5.2 to Ant 1.5.3 === 1.27 +18 -11 ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java Index: XMLJUnitResultFormatter.java === RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- XMLJUnitResultFormatter.java 7 Mar 2003 11:23:06 - 1.26 +++ XMLJUnitResultFormatter.java 28 Mar 2003 12:20:51 - 1.27 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -104,6 +104,10 @@ */ private Hashtable testElements = new Hashtable(); /** + * tests that failed. + */ +private Hashtable failedTests = new Hashtable(); +/** * Timing helper. */ private Hashtable testStarts = new Hashtable(); @@ -186,12 +190,6 @@ */ public void startTest(Test t) { testStarts.put(t, new Long(System.currentTimeMillis())); - -Element currentTest = doc.createElement(TESTCASE); -currentTest.setAttribute(ATTR_NAME, - JUnitVersionHelper.getTestCaseName(t)); -rootElement.appendChild(currentTest); -testElements.put(t, currentTest); } /** @@ -200,16 +198,24 @@ * pA Test is finished. */ public void endTest(Test test) { -Element currentTest = (Element) testElements.get(test); - // Fix for bug #5637 - if a junit.extensions.TestSetup is // used and throws an exception during setUp then startTest // would never have been called -if (currentTest == null) { +if (!testStarts.containsKey(test)) { startTest(test); +} + +Element currentTest = null; +if (!failedTests.containsKey(test)) { +currentTest = doc.createElement(TESTCASE); +currentTest.setAttribute(ATTR_NAME, + JUnitVersionHelper.getTestCaseName(test)); +rootElement.appendChild(currentTest); +testElements.put(test, currentTest); +} else { currentTest = (Element) testElements.get(test); } - + Long l = (Long) testStarts.get(test); currentTest.setAttribute(ATTR_TIME, + ((System.currentTimeMillis() - l.longValue()) / 1000.0)); @@ -245,6 +251,7 @@ private void formatError(String type, Test test, Throwable t) { if (test != null) { endTest(test); +failedTests.put(test, test); } Element nested = doc.createElement(type);