geirm       01/03/23 07:59:18

  Modified:    src/java/org/apache/velocity/test BaseTestCase.java
  Log:
  More helpful contributions from Sam :
  
  This normalizes the isMatch() check to make the varied-newline issue
  of Macs, DOS-boxen, and Yoonicks moot.
  
  Revision  Changes    Path
  1.10      +31 -5     
jakarta-velocity/src/java/org/apache/velocity/test/BaseTestCase.java
  
  Index: BaseTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/BaseTestCase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BaseTestCase.java 2001/03/20 01:11:36     1.9
  +++ BaseTestCase.java 2001/03/23 15:59:17     1.10
  @@ -74,17 +74,23 @@
   import org.apache.velocity.app.FieldMethodizer;
   
   import junit.framework.TestCase;
  +import org.apache.oro.text.perl.Perl5Util;
   
   /**
    * Base test case that provides a few utility methods for
    * the rest of the tests.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
  - * @version $Id: BaseTestCase.java,v 1.9 2001/03/20 01:11:36 jon Exp $
  + * @version $Id: BaseTestCase.java,v 1.10 2001/03/23 15:59:17 geirm Exp $
    */
   public class BaseTestCase extends TestCase
   {
       /**
  +     *  used for nomalization of output and compare data
  +     */
  +    private Perl5Util perl = new Perl5Util();    
  +
  +    /**
        * Default constructor.
        */
       public BaseTestCase(String name)
  @@ -131,12 +137,27 @@
           }
       }
   
  +
       /**
  -     * Returns whether the processed template matches the content of the 
  -     * provided comparison file.
  +     * Normalizes lines to account for platform differences.  Macs use
  +     * a single \r, DOS derived operating systems use \r\n, and Unix
  +     * uses \n.  Replace each with a single \n.
        *
  -     * @return Whether the output matches the contents of the comparison file.
  +     * @author <a href="mailto:[EMAIL PROTECTED]">Sam Ruby</a>
  +     * @return source with all line terminations changed to Unix style
  +     */
  +    protected String normalizeNewlines (String source)
  +    {
  +        return perl.substitute("s/\r[\n]/\n/g", source);
  +    }
  +
  +    /**
  +     * Returns whether the processed template matches the 
  +     * content of the provided comparison file.
        *
  +     * @return Whether the output matches the contents 
  +     *         of the comparison file.
  +     *
        * @exception Exception Test failure condition.
        */
       protected boolean isMatch (String resultsDir,
  @@ -151,8 +172,13 @@
               
           String compare = StringUtils.fileContentsToString
                (getFileName(compareDir, baseFileName, compareExt));
  +
  +        /*
  +         *  normalize each wrt newline
  +         */
   
  -        return result.equals(compare);
  +        return normalizeNewlines(result).equals( 
  +                           normalizeNewlines( compare ) );
       }
   
       /**
  
  
  

Reply via email to