Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Synthetic line numbers for ValidationTestHelper errors
Synthetic line numbers for ValidationTestHelper errors [message #1715072] Wed, 18 November 2015 23:10 Go to next message
Larry LeBron is currently offline Larry LeBronFriend
Messages: 124
Registered: October 2015
Senior Member
I'm working through Bettini's XText Book, and, see some interesting behavior in his use of ValidationTestHelper for detecting parse errors in JUnit tests.

In the example, he is parsing and testing the syntax of a code string constructed from an XTend multi-line template.

'''
entity MyEntity {
   MyEntity ent
}
'''.parse.assertNoErrors


In this code, there is a parser error, since there is no semicolon after "ent". When I run this test, the assert error prints with references to offsets and length, whereas in his example, the error references a synthetic line number, which more clearly points to the place in the code where the error exists (e.g. __synthetic0.entities line : 2)

If you'd like to see the example in the book, it's at ebook location 2190, at the end of the section titled "Testing the Parser" in the testing chapter.

How can I activate the same behavior, as it seems handy. Thanks!
Re: Synthetic line numbers for ValidationTestHelper errors [message #1715094 is a reply to message #1715072] Thu, 19 November 2015 08:12 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 19/11/2015 00:10, Larry LeBron wrote:
> I'm working through Bettini's XText Book, and, see some interesting
> behavior in his use of ValidationTestHelper for detecting parse errors
> in JUnit tests.
>
> In the example, he is parsing and testing the syntax of a code string
> constructed from an XTend multi-line template.
>
> '''
> entity MyEntity {
> MyEntity ent
> }
> '''.parse.assertNoErrors
>
>
> In this code, there is a parser error, since there is no semicolon after
> "ent". When I run this test, the assert error prints with references to
> offsets and length, whereas in his example, the error references a
> synthetic line number, which more clearly points to the place in the
> code where the error exists (e.g. __synthetic0.entities line : 2)
>
> If you'd like to see the example in the book, it's at ebook location
> 2190, at the end of the section titled "Testing the Parser" in the
> testing chapter.
>
> How can I activate the same behavior, as it seems handy. Thanks!

Hi Larry

I'm afraid the behavior has changed in the validation test helper in the
new versions of Xtext, and it now prints the offset and length (and I
guess I'm the one who contributed to change that :)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=455181; in the end, the
new information is actually more handy, since if you want to assert a
validation error, it's easier to assert where the error marker will be
actually placed.

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:Can't find CompilationTestHelper
Next Topic:Using more than one grammar
Goto Forum:
  


Current Time: Fri Apr 26 01:10:01 GMT 2024

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

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

Back to the top