Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » org.junit.ComparisonFailure when unittesting my language
org.junit.ComparisonFailure when unittesting my language [message #997302] Sat, 05 January 2013 05:38 Go to next message
Damien Martin-Guillerez is currently offline Damien Martin-Guillerez
Messages: 10
Registered: December 2012
Junior Member
Hello when unit testing my language I got into a weird error. When trying to isolate it I ends up with the same error for this language:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model: (typeImports+=IHT | typeDefines+=ED )*;

IHT returns ST:
  {IHT} 'imp' name=ID ';'
;

ED returns ST:
	{ED} 'enum' name=ID ';'
;


The error is:
org.junit.ComparisonFailure: expected:<[enum Y; imp X];> but was:<[imp X;enum Y];>
	at org.junit.Assert.assertEquals(Assert.java:123)
	at org.junit.Assert.assertEquals(Assert.java:145)
	at org.eclipse.xtext.junit4.serializer.SerializerTester.assertSerializeWithNodeModel(SerializerTester.java:96)
	at org.eclipse.xtext.junit4.AbstractXtextTests.getResourceAndExpect(AbstractXtextTests.java:271)
	at org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:244)
	at org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:219)
	at org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:190)
	at org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:186)
	at org.xtext.example.mydsl.tests.TestXTextBug.test(TestXTextBug.java:15)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


And the tester is:
package org.xtext.example.mydsl.tests;

import org.eclipse.xtext.junit4.AbstractXtextTests;
import org.eclipse.xtext.junit4.InjectWith;
import org.junit.Test;
import org.xtext.example.mydsl.MyDslInjectorProvider;
import org.xtext.example.mydsl.MyDslStandaloneSetup;

@InjectWith(MyDslInjectorProvider.class)
public class TestXTextBug extends AbstractXtextTests {

    @Test
    public void test() throws Exception {
        with(MyDslStandaloneSetup.class);
        getModel("enum Y; imp X;");
    }

}


If we remove both ';' in the grammar it works, if we remove only the one in 'enum' it still fails, if we remove the "returns ST" type conversion it still fails. My Xtext version is 2.3.1.v201208210947.

Did I missed something?
Re: org.junit.ComparisonFailure when unittesting my language [message #997613 is a reply to message #997302] Sat, 05 January 2013 07:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25999
Registered: July 2009
Senior Member
Damien,

In each case, how is the inferred Ecore model different? Just glancing
at it, I imagine Model has two references and so there's nothing in the
Model instance that would preserve the mixed ordering of IHT and ED so
serialization will put all the things from the first reference before
all the things for the second reference...


On 05/01/2013 11:39 AM, Damien Martin-Guillerez wrote:
> Hello when unit testing my language I got into a weird error. When
> trying to isolate it I ends up with the same error for this language:
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model: (typeImports+=IHT | typeDefines+=ED )*;
>
> IHT returns ST:
> {IHT} 'imp' name=ID ';'
> ;
>
> ED returns ST:
> {ED} 'enum' name=ID ';'
> ;
>
>
> The error is:
>
> org.junit.ComparisonFailure: expected:<[enum Y; imp X];> but was:<[imp
> X;enum Y];>
> at org.junit.Assert.assertEquals(Assert.java:123)
> at org.junit.Assert.assertEquals(Assert.java:145)
> at
> org.eclipse.xtext.junit4.serializer.SerializerTester.assertSerializeWithNodeModel(SerializerTester.java:96)
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResourceAndExpect(AbstractXtextTests.java:271)
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:244)
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:219)
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:190)
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:186)
> at
> org.xtext.example.mydsl.tests.TestXTextBug.test(TestXTextBug.java:15)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
> And the tester is:
>
> package org.xtext.example.mydsl.tests;
>
> import org.eclipse.xtext.junit4.AbstractXtextTests;
> import org.eclipse.xtext.junit4.InjectWith;
> import org.junit.Test;
> import org.xtext.example.mydsl.MyDslInjectorProvider;
> import org.xtext.example.mydsl.MyDslStandaloneSetup;
>
> @InjectWith(MyDslInjectorProvider.class)
> public class TestXTextBug extends AbstractXtextTests {
>
> @Test
> public void test() throws Exception {
> with(MyDslStandaloneSetup.class);
> getModel("enum Y; imp X;");
> }
>
> }
>
>
> If we remove both ';' in the grammar it works, if we remove only the
> one in 'enum' it still fails, if we remove the "returns ST" type
> conversion it still fails. My Xtext version is 2.3.1.v201208210947.
>
> Did I missed something?
Re: org.junit.ComparisonFailure when unittesting my language [message #997811 is a reply to message #997613] Tue, 08 January 2013 14:42 Go to previous messageGo to next message
Damien Martin-Guillerez is currently offline Damien Martin-Guillerez
Messages: 10
Registered: December 2012
Junior Member
Yep I understand that (and I figure it out myself).

However, I don't think the getModel() function from AbstractXtextTests should fails in any way. So either I do things in the wrong way in the Xtext grammar (in which case IMHO, it should be signalled outside the tests) or there is a bug.

I do that (conversion of IHT/ED to ST) in order to do cross-refs to type definition.
Re: org.junit.ComparisonFailure when unittesting my language [message #998144 is a reply to message #997302] Wed, 09 January 2013 07:42 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1321
Registered: July 2009
Senior Member
If I remember correctly (I stopped using AbstractXtextTests and switched
to the 'new way' of writing Junit tests with Xtend) you can disable the
tests for the serializer (I had similar problems, and I don't remember
whether it was a bug) by redefining a method of AbstractXtextTests

On 01/05/2013 11:39 AM, Damien Martin-Guillerez wrote:
> Hello when unit testing my language I got into a weird error. When
> trying to isolate it I ends up with the same error for this language:
>
> grammar org.xtext.example.mydsl.MyDsl with
> org.eclipse.xtext.common.Terminals
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> Model: (typeImports+=IHT | typeDefines+=ED )*;
>
> IHT returns ST:
> {IHT} 'imp' name=ID ';'
> ;
>
> ED returns ST:
> {ED} 'enum' name=ID ';'
> ;
>
>
> The error is:
>
> org.junit.ComparisonFailure: expected:<[enum Y; imp X];> but was:<[imp
> X;enum Y];>
> at org.junit.Assert.assertEquals(Assert.java:123)
> at org.junit.Assert.assertEquals(Assert.java:145)
> at
> org.eclipse.xtext.junit4.serializer.SerializerTester.assertSerializeWithNodeModel(SerializerTester.java:96)
>
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResourceAndExpect(AbstractXtextTests.java:271)
>
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:244)
>
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getResource(AbstractXtextTests.java:219)
>
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:190)
>
> at
> org.eclipse.xtext.junit4.AbstractXtextTests.getModel(AbstractXtextTests.java:186)
>
> at
> org.xtext.example.mydsl.tests.TestXTextBug.test(TestXTextBug.java:15)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
>
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>
>
>
> And the tester is:
>
> package org.xtext.example.mydsl.tests;
>
> import org.eclipse.xtext.junit4.AbstractXtextTests;
> import org.eclipse.xtext.junit4.InjectWith;
> import org.junit.Test;
> import org.xtext.example.mydsl.MyDslInjectorProvider;
> import org.xtext.example.mydsl.MyDslStandaloneSetup;
>
> @InjectWith(MyDslInjectorProvider.class)
> public class TestXTextBug extends AbstractXtextTests {
>
> @Test
> public void test() throws Exception {
> with(MyDslStandaloneSetup.class);
> getModel("enum Y; imp X;");
> }
>
> }
>
>
> If we remove both ';' in the grammar it works, if we remove only the one
> in 'enum' it still fails, if we remove the "returns ST" type conversion
> it still fails. My Xtext version is 2.3.1.v201208210947.
>
> Did I missed something?


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Re: org.junit.ComparisonFailure when unittesting my language [message #1020439 is a reply to message #998144] Mon, 18 March 2013 03:09 Go to previous messageGo to next message
anudeep arya is currently offline anudeep arya
Messages: 29
Registered: March 2013
Junior Member
can i get the location of xtext.junit jar which contains AbstractXtextTests class..
Re: org.junit.ComparisonFailure when unittesting my language [message #1021172 is a reply to message #1020439] Tue, 19 March 2013 11:47 Go to previous message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1321
Registered: July 2009
Senior Member
On 03/18/2013 07:12 PM, anudeep arya wrote:
> can i get the location of xtext.junit jar which contains
> AbstractXtextTests class..

I don't understand...

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Previous Topic:Xtext scoping with two models
Next Topic:Script editing without the actual editor
Goto Forum:
  


Current Time: Thu Aug 21 14:10:48 EDT 2014

Powered by FUDForum. Page generated in 0.10285 seconds