Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Assert error in FormatterTestHelper due to different whitespace in ITextRegionAccess strings.
Assert error in FormatterTestHelper due to different whitespace in ITextRegionAccess strings. [message #1783056] Wed, 07 March 2018 10:02 Go to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 15
Registered: January 2018
Junior Member
I get an Assert error in a formatting test. The error is thrown inside the FormatterTestHelper::createRegionAccess function because the two ITextRegionAccess strings nmString and serString are not equal. They differ in that the one created via NodeModel contains a bit of white space which the one created via serializer doesn't. Here's the exact failure trace of the JUnit test:
org.junit.ComparisonFailure: expected:<...ration
604         H[ " "                  Whitespace:TerminalRule'WS'
     1        Semantic VerifySpec           AssertRule:(spec=VerifySpec|) path:AssertRule/spec=Test'goodCase'/assertRules[1]=TestCase'SimpleCheckerTest'/tests[0]=IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
605  1      S "}"                  Test:'}'
           E Test'goodCase'       TestCase:tests+=Test path:TestCase'SimpleCheckerTest'/tests[0]=IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
606  0     H
606  1     S "}"                  TestCase:'}'
          E TestCase'SimpleCheckerTest' IDCUnitPackageDeclaration:testCase=TestCase path:IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
         E IDCUnitPackageDeclaration'simple.package.tests' IltisDataCheckerUnitModel:packageDeclaration=IDCUnitPackageDeclaration path:IltisDataCheckerUnitModel/packageDeclaration
        E IltisDataCheckerUnitModel IltisDataCheckerUnitModel
607]  2  H "\r\n"       ...> but was:<...ration
604         H[
     0        Semantic VerifySpec           AssertRule:(spec=VerifySpec|) path:AssertRule/spec=Test'goodCase'/assertRules[1]=TestCase'SimpleCheckerTest'/tests[0]=IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
604  1      S "}"                  Test:'}'
           E Test'goodCase'       TestCase:tests+=Test path:TestCase'SimpleCheckerTest'/tests[0]=IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
605  0     H
605  1     S "}"                  TestCase:'}'
          E TestCase'SimpleCheckerTest' IDCUnitPackageDeclaration:testCase=TestCase path:IDCUnitPackageDeclaration'simple.package.tests'/testCase=IltisDataCheckerUnitModel/packageDeclaration
         E IDCUnitPackageDeclaration'simple.package.tests' IltisDataCheckerUnitModel:packageDeclaration=IDCUnitPackageDeclaration path:IltisDataCheckerUnitModel/packageDeclaration
        E IltisDataCheckerUnitModel IltisDataCheckerUnitModel
606]  2  H "\r\n"       ...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.eclipse.xtext.testing.formatter.FormatterTestHelper.createRegionAccess(FormatterTestHelper.java:165)
	at org.eclipse.xtext.testing.formatter.FormatterTestHelper.assertFormatted(FormatterTestHelper.java:104)
	at org.eclipse.xtext.testing.formatter.FormatterTestHelper.assertFormatted(FormatterTestHelper.java:122)
	at com.siemens.mo.idp.idcunit.dsl.tests.formatting.TableFormattingTest.testCaseWithTable(TableFormattingTest.java:152)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.eclipse.xtext.testing.XtextRunner$1.evaluate(XtextRunner.java:49)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


The relevant grammar looks like this:

AssertRule:
   'assert' ('catalog' catalogCheck=[idc::CatalogCheck] | 
   			'point' pointCheck=[idc::PointCheck] | 
   			check=[idc::Check])
   			'has' ((error?='error' spec=VerifySpec) |
   				   (prompt?='prompt' spec=VerifySpec) | 
   				   (noError?='no' 'error'));

VerifySpec:
	{VerifySpec}
	('[' verifyId=XExpression ']')? ('with' verifyMessage=XExpression)?;


And the part of the snippet that produces the error is this:
toBeFormatted = ''' 
					//...
					assert    
					       SimpleCheckOK   
					                      has   
					                           no error  
					assert   SimpleCheckNOK   has   error }} // <-- this whitespace between error and }} causes the error
				'''


How the whitespace between error and the braces looks like doesn't seem to matter (new line, more spaces, etc.) all seem to produce the same kind of error.

I strongly assume this has to do with the empty VerifySpec because in a previous version, I had what is now the VerifySpec directly in AssertRule. Only after I extracted it into its own rule did I get this error. If I add text such that the VerifySpec is not empty, the test runs fine.

Is this a bug/inconsistency in the ITextRegionAccess creation methods? To me it looks like the serializer just forgets about the whitespace.
Or is there something bad with my code?

Edit: I should also add: Removing the whitespace completely also makes the test run fine.

[Updated on: Wed, 07 March 2018 10:05]

Report message to a moderator

Re: Assert error in FormatterTestHelper due to different whitespace in ITextRegionAccess strings. [message #1783065 is a reply to message #1783056] Wed, 07 March 2018 10:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12043
Registered: July 2009
Senior Member
can you create a bug at github.com/eclipse/xtext-core

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Assert error in FormatterTestHelper due to different whitespace in ITextRegionAccess strings. [message #1783075 is a reply to message #1783065] Wed, 07 March 2018 11:41 Go to previous message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 15
Registered: January 2018
Junior Member
Done: https://github.com/eclipse/xtext-core/issues/653
Previous Topic:How to disable cross-resource reference
Next Topic:Omitting root name in references
Goto Forum:
  


Current Time: Mon Jun 25 02:49:51 GMT 2018

Powered by FUDForum. Page generated in 0.01863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top