cvs commit: jakarta-log4j/tests/witness xmlLayout.2

[email protected] 29 Apr 2002 14:41:23 -0000
Newsgroups gmane.comp.jakarta.log4j.cvs
Message-ID <[email protected]>
ceki        02/04/29 07:41:23

  Modified:    tests/src/java/org/apache/log4j/util Compare.java
               tests/src/java/org/apache/log4j/xml XMLLayoutTestCase.java
               tests/witness xmlLayout.2
  Added:       tests/src/java/org/apache/log4j/util
                        XMLLineAttributeFilter.java
  Log:
  Improved error reporting in Compare.
  
  Added new filter for to transform the line attribute in XML output
  to a fixed value.
  
  Revision  Changes    Path
  1.4       +18 -9     jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java
  
  Index: Compare.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Compare.java	25 Apr 2002 21:17:36 -0000	1.3
  +++ Compare.java	29 Apr 2002 14:41:23 -0000	1.4
  @@ -9,23 +9,33 @@
   
   import java.io.InputStream;
   import java.io.FileInputStream;
  +import java.io.FileReader;
  +import java.io.BufferedReader;
   import java.io.FileNotFoundException;
   import java.io.IOException;
   
   public class Compare {
   
  +  static final int B1_NULL = -1;
  +  static final int B2_NULL = -2;
  +  
     static 
     public
     boolean compare(String file1, String file2) throws FileNotFoundException, 
                                                               IOException {
  -    InputStream in1 = new FileInputStream(file1);
  -    InputStream in2 = new FileInputStream(file2);
  +    BufferedReader in1 = new BufferedReader(new FileReader(file1));
  +    BufferedReader in2 = new BufferedReader(new FileReader(file2));
       
  -    int b1;
  -    while((b1 = in1.read()) != -1) {
  -      int b2 = in2.read();
  -      if(b2 != b1) {
  -	System.out.println("Files ["+file1+"] and ["+file2+"] differ.");
  +    String s1;
  +    int lineCounter = 0;
  +    while((s1 = in1.readLine()) != null) {
  +      lineCounter++;
  +      String s2 = in2.readLine();
  +      if(!s1.equals(s2)) {
  +	System.out.println("Files ["+file1+"] and ["+file2+"] differ on line " 
  +			   +lineCounter);
  +	System.out.println("One  reads: ["+s1+"].");
  +	System.out.println("Other reads:["+s2+"].");
   	return false;
         }
       }
  @@ -36,8 +46,7 @@
         return false;
       }
       
  -
       return true;
     }
  -
  +  
   }
  
  
  
  1.1                  jakarta-log4j/tests/src/java/org/apache/log4j/util/XMLLineAttributeFilter.java
  
  Index: XMLLineAttributeFilter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.txt file.  */
  
  package org.apache.log4j.util;
  
  import java.io.*;
  
  import org.apache.oro.text.perl.Perl5Util;
  
  public class XMLLineAttributeFilter implements Filter {
  
    Perl5Util util = new Perl5Util();
  
    public 
    String filter(String in) {
      if(util.match("/line=\"\\d{1,3}\"/", in)) {
        return util.substitute("s/line=\"\\d{1,3}\"/line=\"X\"/", in);
      } else if(util.match("/line=\"?\"/", in)) {
        return util.substitute("s/line=\"?\"/line=\"X\"/", in);
      } else {
        return in;
      }
    }
  }
  
  
  
  1.2       +4 -1      jakarta-log4j/tests/src/java/org/apache/log4j/xml/XMLLayoutTestCase.java
  
  Index: XMLLayoutTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/xml/XMLLayoutTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLLayoutTestCase.java	25 Apr 2002 21:17:36 -0000	1.1
  +++ XMLLayoutTestCase.java	29 Apr 2002 14:41:23 -0000	1.2
  @@ -12,6 +12,7 @@
   import org.apache.log4j.util.Filter;
   import org.apache.log4j.util.ControlFilter;
   import org.apache.log4j.util.XMLTimestampFilter;
  +import org.apache.log4j.util.XMLLineAttributeFilter;
   import org.apache.log4j.util.LineNumberFilter;
   import org.apache.log4j.util.Transformer;
   import org.apache.log4j.util.Compare;
  @@ -51,7 +52,9 @@
       xmlLayout.setLocationInfo(true);
       root.addAppender(new FileAppender(xmlLayout, TEMP, false));
       common();
  -    Transformer.transform(TEMP, FILTERED, new XMLTimestampFilter());
  +    Transformer.transform(TEMP, FILTERED, new Filter[] {new LineNumberFilter(),
  +                                                        new XMLTimestampFilter(),
  +                                                        new XMLLineAttributeFilter()});
       assertTrue(Compare.compare(FILTERED, "witness/xmlLayout.2"));
     }
   
  
  
  
  1.2       +63 -63    jakarta-log4j/tests/witness/xmlLayout.2
  
  Index: xmlLayout.2
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/witness/xmlLayout.2,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- xmlLayout.2	25 Apr 2002 21:17:36 -0000	1.1
  +++ xmlLayout.2	29 Apr 2002 14:41:23 -0000	1.2
  @@ -1,135 +1,135 @@
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase$X" timestamp="XXX" level="INFO" thread="main">
   <log4j:message><![CDATA[in X() constructor]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase$X" method="&lt;init&gt;" file="XMLLayoutTestCase.java" line="98"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase$X" method="&lt;init&gt;" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="DEBUG" thread="main">
   <log4j:message><![CDATA[Message 0]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="63"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="DEBUG" thread="main">
   <log4j:message><![CDATA[Message 0]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="64"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="INFO" thread="main">
   <log4j:message><![CDATA[Message 1]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="66"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="INFO" thread="main">
   <log4j:message><![CDATA[Message 1]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="67"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="WARN" thread="main">
   <log4j:message><![CDATA[Message 2]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="69"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="WARN" thread="main">
   <log4j:message><![CDATA[Message 2]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="70"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="ERROR" thread="main">
   <log4j:message><![CDATA[Message 3]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="72"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="ERROR" thread="main">
   <log4j:message><![CDATA[Message 3]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="73"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="FATAL" thread="main">
   <log4j:message><![CDATA[Message 4]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="75"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="FATAL" thread="main">
   <log4j:message><![CDATA[Message 4]]></log4j:message>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="76"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="DEBUG" thread="main">
   <log4j:message><![CDATA[Message 5]]></log4j:message>
   <log4j:throwable><![CDATA[java.lang.Exception: Just testing
  -	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:78)
  -	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:53)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:XXX)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:XXX)
   	at java.lang.reflect.Method.invoke(Native Method)
  -	at junit.framework.TestCase.runTest(TestCase.java:166)
  -	at junit.framework.TestCase.runBare(TestCase.java:140)
  -	at junit.framework.TestResult$1.protect(TestResult.java:106)
  -	at junit.framework.TestResult.runProtected(TestResult.java:124)
  -	at junit.framework.TestResult.run(TestResult.java:109)
  -	at junit.framework.TestCase.run(TestCase.java:131)
  -	at junit.framework.TestSuite.runTest(TestSuite.java:173)
  -	at junit.framework.TestSuite.run(TestSuite.java:168)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)
  +	at junit.framework.TestCase.runTest(TestCase.java:XXX)
  +	at junit.framework.TestCase.runBare(TestCase.java:XXX)
  +	at junit.framework.TestResult$1.protect(TestResult.java:XXX)
  +	at junit.framework.TestResult.runProtected(TestResult.java:XXX)
  +	at junit.framework.TestResult.run(TestResult.java:XXX)
  +	at junit.framework.TestCase.run(TestCase.java:XXX)
  +	at junit.framework.TestSuite.runTest(TestSuite.java:XXX)
  +	at junit.framework.TestSuite.run(TestSuite.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX)
   ]]></log4j:throwable>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="79"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="DEBUG" thread="main">
   <log4j:message><![CDATA[Message 5]]></log4j:message>
   <log4j:throwable><![CDATA[java.lang.Exception: Just testing
  -	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:78)
  -	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:53)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:XXX)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:XXX)
   	at java.lang.reflect.Method.invoke(Native Method)
  -	at junit.framework.TestCase.runTest(TestCase.java:166)
  -	at junit.framework.TestCase.runBare(TestCase.java:140)
  -	at junit.framework.TestResult$1.protect(TestResult.java:106)
  -	at junit.framework.TestResult.runProtected(TestResult.java:124)
  -	at junit.framework.TestResult.run(TestResult.java:109)
  -	at junit.framework.TestCase.run(TestCase.java:131)
  -	at junit.framework.TestSuite.runTest(TestSuite.java:173)
  -	at junit.framework.TestSuite.run(TestSuite.java:168)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)
  +	at junit.framework.TestCase.runTest(TestCase.java:XXX)
  +	at junit.framework.TestCase.runBare(TestCase.java:XXX)
  +	at junit.framework.TestResult$1.protect(TestResult.java:XXX)
  +	at junit.framework.TestResult.runProtected(TestResult.java:XXX)
  +	at junit.framework.TestResult.run(TestResult.java:XXX)
  +	at junit.framework.TestCase.run(TestCase.java:XXX)
  +	at junit.framework.TestSuite.runTest(TestSuite.java:XXX)
  +	at junit.framework.TestSuite.run(TestSuite.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX)
   ]]></log4j:throwable>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="80"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX" level="ERROR" thread="main">
   <log4j:message><![CDATA[Message 6]]></log4j:message>
   <log4j:throwable><![CDATA[java.lang.Exception: Just testing
  -	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:78)
  -	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:53)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:XXX)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:XXX)
   	at java.lang.reflect.Method.invoke(Native Method)
  -	at junit.framework.TestCase.runTest(TestCase.java:166)
  -	at junit.framework.TestCase.runBare(TestCase.java:140)
  -	at junit.framework.TestResult$1.protect(TestResult.java:106)
  -	at junit.framework.TestResult.runProtected(TestResult.java:124)
  -	at junit.framework.TestResult.run(TestResult.java:109)
  -	at junit.framework.TestCase.run(TestCase.java:131)
  -	at junit.framework.TestSuite.runTest(TestSuite.java:173)
  -	at junit.framework.TestSuite.run(TestSuite.java:168)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)
  +	at junit.framework.TestCase.runTest(TestCase.java:XXX)
  +	at junit.framework.TestCase.runBare(TestCase.java:XXX)
  +	at junit.framework.TestResult$1.protect(TestResult.java:XXX)
  +	at junit.framework.TestResult.runProtected(TestResult.java:XXX)
  +	at junit.framework.TestResult.run(TestResult.java:XXX)
  +	at junit.framework.TestCase.run(TestCase.java:XXX)
  +	at junit.framework.TestSuite.runTest(TestSuite.java:XXX)
  +	at junit.framework.TestSuite.run(TestSuite.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX)
   ]]></log4j:throwable>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="82"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>
   
   <log4j:event category="root" timestamp="XXX" level="ERROR" thread="main">
   <log4j:message><![CDATA[Message 6]]></log4j:message>
   <log4j:throwable><![CDATA[java.lang.Exception: Just testing
  -	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:78)
  -	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:53)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.common(XMLLayoutTestCase.java:XXX)
  +	at org.apache.log4j.xml.XMLLayoutTestCase.locationInfo(XMLLayoutTestCase.java:XXX)
   	at java.lang.reflect.Method.invoke(Native Method)
  -	at junit.framework.TestCase.runTest(TestCase.java:166)
  -	at junit.framework.TestCase.runBare(TestCase.java:140)
  -	at junit.framework.TestResult$1.protect(TestResult.java:106)
  -	at junit.framework.TestResult.runProtected(TestResult.java:124)
  -	at junit.framework.TestResult.run(TestResult.java:109)
  -	at junit.framework.TestCase.run(TestCase.java:131)
  -	at junit.framework.TestSuite.runTest(TestSuite.java:173)
  -	at junit.framework.TestSuite.run(TestSuite.java:168)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:231)
  -	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:409)
  +	at junit.framework.TestCase.runTest(TestCase.java:XXX)
  +	at junit.framework.TestCase.runBare(TestCase.java:XXX)
  +	at junit.framework.TestResult$1.protect(TestResult.java:XXX)
  +	at junit.framework.TestResult.runProtected(TestResult.java:XXX)
  +	at junit.framework.TestResult.run(TestResult.java:XXX)
  +	at junit.framework.TestCase.run(TestCase.java:XXX)
  +	at junit.framework.TestSuite.runTest(TestSuite.java:XXX)
  +	at junit.framework.TestSuite.run(TestSuite.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:XXX)
  +	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:XXX)
   ]]></log4j:throwable>
  -<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="83"/>
  +<log4j:locationInfo class="org.apache.log4j.xml.XMLLayoutTestCase" method="common" file="XMLLayoutTestCase.java" line="X"/>
   </log4j:event>