grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] Testcase fails


From: Per Cederberg
Subject: Re: [Grammatica-users] Testcase fails
Date: Fri, 19 Mar 2004 22:46:56 +0100

Hi Stefan!

On Fri, 2004-03-19 at 15:54, Stefan Ukena wrote:
> Hi everyone,
> 
> I'm currently figuering out how to use Grammatica, and while doing that
> I stumbeld across this little problem with the provided test-case for
> the examples that came with Grammatica:
> 
> When I run the TestArithmeticParser-Test I get the following failure-notice:
> 
> junit.framework.AssertionFailedError: on line: 1, expected:
> 'Expression(2001)
> ', found: 'Expression(2001)
> '
>     at junit.framework.Assert.fail(Assert.java:47)
>     at
> net.percederberg.grammatica.test.ParserTestCase.validateLine(ParserTestCase.java:164)
>     at
> net.percederberg.grammatica.test.ParserTestCase.validateLines(ParserTestCase.java:143)
>     at
> net.percederberg.grammatica.test.ParserTestCase.validateTree(ParserTestCase.java:124)
>     at
> net.percederberg.grammatica.test.ParserTestCase.parse(ParserTestCase.java:74)
>     at
> net.percederberg.grammatica.test.TestArithmeticParser.testValidInput(TestArithmeticParser.java:115)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     [...]
> 
> Because the difference between the two strings wasn't so obvious I used
> the debugger to have a look at the values.
> The debugger gives me the difference more clearly:
> expected= "Expression(2001)\n"
> result= "Expression(2001)\r"
> 
> I'm running Grammatica 1.4 on Windows XP with JDK 1.4.
> 
> Now what I would like to know is:
> 1) Is this a known issue?
> 2) Am I right in assuming that this is just a problem with the test-case
> (or could it turn out to bother me later)?

Ouch... I just *knew* this test case code would cause problems
sooner or later... Thing is I'm validating the Node.printTo()
output of the parse tree to detect changes from one version to
another. Now, doing so on Windows will of course break things
due to the classical newline problem -- "\r\n" (on Windows) and
"\n" (on Linux/Unix).

I've fixed the test case by triming the strings before
comparison. Here's the fix if you're worried (it's an issue in
the C# version too, fix not included here):

--- test/src/java/net/percederberg/grammatica/test/ParserTestCase.java 
(revision 29)
+++ test/src/java/net/percederberg/grammatica/test/ParserTestCase.java 
(working copy)
@@ -160,7 +160,7 @@
      * @param result         the result obtained
      */
     private void validateLine(int line, String expected, String result)
{
-        if (!expected.equals(result)) {
+        if (!expected.trim().equals(result.trim())) {
             fail("on line: " + line + ", expected: '" + expected +
                  "', found: '" + result + "'");
         }


> Thanks everyone in advance!

Thanks for finding this little annoyance!

Cheers,

/Per






reply via email to

[Prev in Thread] Current Thread [Next in Thread]