Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] ValidationTestHelper - getting the correct messageParts for assertError(Help on writing a unit test for a Diagnostic.SYNTAX_DIAGNOSTIC validation error)
[SOLVED] ValidationTestHelper - getting the correct messageParts for assertError [message #1740686] Wed, 17 August 2016 09:17 Go to next message
Ruud Goossens is currently offline Ruud GoossensFriend
Messages: 2
Registered: August 2016
Junior Member
Hi,

I'm having difficulties writing tests for assertError on default validation rules using SYNTAX_DIAGNOSTIC. I'm not sure what String to use and whether or not the offset and length should be added. There should be no white space before or after the comma in a line (Record) of my DSL.

Here's what I have:
[...]
	@Inject ParseHelper<Model> parseHelper
	@Inject ValidationTestHelper validator

	@Test
	def void testParsingWhitespace1() {
		val model = parseHelper.parse('''
			FOO ,FOO,FOO.const,FOO:BAR,DEFAULT,Foo Bar
		''')
		validator.assertError(model,DacnfPackage::eINSTANCE.record,Diagnostic.SYNTAX_DIAGNOSTIC, 3, 1, "extraneous input ' ' expecting ','' on Record")
	}
[...]


I'm getting the following assertion error:
org.junit.ComparisonFailure: expected:<[extraneous input ' ' expecting ','' on Record]> but was:<[Expected ERROR 'org.eclipse.xtext.diagnostics.Diagnostic.Syntax' on Record at [11:1] but got
ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 'extraneous input ' ' expecting ','' on Record, offset 3, length 1
]>


Running the test with
validator.assertNoErrors(model)
returns the following assertion error:
java.lang.AssertionError: Expected no errors, but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Syntax) 'extraneous input ' ' expecting ','' on Record, offset 3, length 1


I've tried the entire string and several sub strings of what is returned, none seems to be working. Test is working fine without adding the messageParts (and offset and length), but I would like to match a finer granularity.


Using Eclipse DSL Tools (4.5.2) with Xtext 2.9.1


Thanks!

[Updated on: Thu, 18 August 2016 07:36]

Report message to a moderator

Re: ValidationTestHelper - getting the correct messageParts for assertError [message #1740721 is a reply to message #1740686] Wed, 17 August 2016 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

i cannot reproduce this.

@Inject
	ParseHelper<Model> parseHelper
	@Inject extension ValidationTestHelper
	

	@Test 
	def void loadModel() {
		val result = parseHelper.parse('''
			Hello Xtext !!
		''')
		Assert.assertNotNull(result)
		result.assertError(MyDslPackage.eINSTANCE.model, "org.eclipse.xtext.diagnostics.Diagnostic.Syntax", 13, 1,"extraneous input '!' expecting EOF")
	}


are you sure the message part is right? i think the "on XXXXX" should not be part of it.

you can debug

org.eclipse.xtext.junit4.validation.ValidationTestHelper.doMatchIssues(Resource, EClass, String, int, int, Severity, List<Issue>, String...)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ValidationTestHelper - getting the correct messageParts for assertError [message #1740752 is a reply to message #1740721] Thu, 18 August 2016 07:12 Go to previous messageGo to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
I confirm Christian expectation: the "on Record" is not part of the message to put in the assertError parameters. The "on ..." corresponds to another argument of assertError. Just remove the "on ...".
Re: ValidationTestHelper - getting the correct messageParts for assertError [message #1740755 is a reply to message #1740752] Thu, 18 August 2016 07:34 Go to previous message
Ruud Goossens is currently offline Ruud GoossensFriend
Messages: 2
Registered: August 2016
Junior Member
I tried the String without "on Record..." before and failed. Only after debugging DoMachIssues I noticed the extra single quote that was a remainder of copy paste....

The final working validation is:
validator.assertError(model,DacnfPackage::eINSTANCE.record,Diagnostic.SYNTAX_DIAGNOSTIC, 3, 1, "extraneous input ' ' expecting ','")


Thanks for the help!
Previous Topic:Xtext showing unwanted contents
Next Topic:left recursive error
Goto Forum:
  


Current Time: Fri Mar 29 12:28:58 GMT 2024

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

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

Back to the top