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 |
Ruud Goossens 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 |
|
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
|
|
| | |
Goto Forum:
Current Time: Mon Sep 23 05:27:30 GMT 2024
Powered by FUDForum. Page generated in 0.03179 seconds
|