Author: nbubna
Date: Thu Oct 16 14:24:33 2008
New Revision: 705364
URL: http://svn.apache.org/viewvc?rev=705364&view=rev
Log:
standardize line/col testing for exception messages
Modified:
velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity627TestCase.java
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity629TestCase.java
Modified:
velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java?rev=705364&r1=705363&r2=705364&view=diff
==============================================================================
---
velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
(original)
+++
velocity/engine/trunk/src/test/org/apache/velocity/test/BaseEvalTestCase.java
Thu Oct 16 14:24:33 2008
@@ -124,6 +124,25 @@
return null;
}
+ protected Exception assertEvalExceptionAt(String evil, int line, int col)
+ {
+ String loc = "[line "+line+", column "+col+"]";
+ if (DEBUG)
+ {
+ engine.getLog().info("Expectation: Exception at "+loc);
+ }
+ Exception e = assertEvalException(evil, null);
+ if (e.getMessage().indexOf(loc) < 1)
+ {
+ fail("Was expecting exception at "+loc+" instead of
"+e.getMessage());
+ }
+ else if (DEBUG)
+ {
+ engine.getLog().info("Result: "+e.getMessage());
+ }
+ return e;
+ }
+
protected String evaluate(String template)
{
StringWriter writer = new StringWriter();
Modified:
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity627TestCase.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity627TestCase.java?rev=705364&r1=705363&r2=705364&view=diff
==============================================================================
---
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity627TestCase.java
(original)
+++
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity627TestCase.java
Thu Oct 16 14:24:33 2008
@@ -42,8 +42,7 @@
public void test627()
{
- Exception e = assertEvalException("##\n##\n#foreach($i in
\"junk\")blaa#end");
- // Make sure the error ouput contains "line 3" if not throw
- assertTrue(e.getMessage().indexOf("[line 3, column 16]") == -1);
+ // Make sure the error ouput contains "line 3, column 16"
+ assertEvalExceptionAt("##\n##\n#foreach($i in \"junk\")blaa#end", 3,
16);
}
}
Modified:
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity629TestCase.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity629TestCase.java?rev=705364&r1=705363&r2=705364&view=diff
==============================================================================
---
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity629TestCase.java
(original)
+++
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity629TestCase.java
Thu Oct 16 14:24:33 2008
@@ -41,22 +41,17 @@
"#set($list=[1])#set($x=\"\n"+
"$list.get(1)\n"+
"\")";
- Exception e = assertEvalException(template);
- // Make sure the error ouput contains "line 4" if not throw
- assertTrue(e.getMessage().indexOf("[line 4, column 7]") > -1);
+ // Make sure the error ouput contains "line 4, column 7" if not throw
+ assertEvalExceptionAt(template, 4, 7);
template = "##\n"+
"##\n"+
"#set($x=\"#if\")";
- e = assertEvalException(template);
- // Make sure the error ouput contains "line 3" if not throw
- assertTrue(e.getMessage().indexOf("[line 3, column 9]") > -1);
+ assertEvalExceptionAt(template, 3, 9);
template = "##\n"+
"##\n"+
"#macro(test
$i)$i#end#set($list=[1])#test(\"$list.get(1)\")";
- e = assertEvalException(template);
- // Make sure the error ouput contains "line 3" if not throw
- assertTrue(e.getMessage().indexOf("[line 3, column 50]") > -1);
+ assertEvalExceptionAt(template, 3, 50);
}
}