Unit Test cross reference from one DSL to another DSL [message #1436114] |
Thu, 02 October 2014 12:30 |
|
Hey,
I have a junit test for my DSL that should test a specific part where I can reference an element from another DSL. How would I be able to come up with something I could reference? I.e. I'm inside a unit test for DSL 'b', and need an element of DSL 'a' that I can reference to test whether referencing & validating works...
Edit: I already tried putting a test.a file with an element of DSL 'a' next to the source file for the test, with no effect...
Cheers,
Markus
[Updated on: Thu, 02 October 2014 12:32] Report message to a moderator
|
|
|
|
Re: Unit Test cross reference from one DSL to another DSL [message #1436148 is a reply to message #1436124] |
Thu, 02 October 2014 13:26 |
|
What is "standalone mode" in the context of a junit test? I think my question was not so general, right?
- I have a unit test for one DSL
- I want to test a reference to another DSL
- How can come up with a model element for the "other DSL"
- either programmatically (EMF Factory)
- by loading a resource of that type.
do i really need to call standalone setups in junit tests? I see there is a whole lot of infrastructure for Xtext junit tests, that does much to setup for one DSL. Do I have to manually do everything again? Or is it enough to just create a fake URI with the correct ending and feed that to the resource set?
|
|
|
|
|
Re: Unit Test cross reference from one DSL to another DSL [message #1436166 is a reply to message #1436148] |
Thu, 02 October 2014 13:52 |
|
[Edit]: THANKS for the pointers, I will check those too.
based on your suggestion, I tried this now:
private def createWDLPersistent() {
val fake = URI.createFileURI("/some/where/over/the/rainbow.wdl")
val rs = resourceSetProvider.get()
val wdlInjector = new WDLStandaloneSetup().createInjector
val resourceFactory = wdlInjector.getInstance(IResourceFactory)
val r = resourceFactory.createResource(fake);
rs.resources.add(r)
try {
r.load(
new LazyStringInputStream(
'''
package tests;
persistent TestPersistent {
}
'''), null)
for(e : r.errors) {
System.err.println(e)
}
} catch (IOException e) {
throw new WrappedException(e)
}
}
and call that in the test:
@Test
def void parseDefaultOrdering() {
createWDLPersistent()
val m = parseAndValidate(
'''
parameter TestPara1 {
default "Something";
persistent-type tests.TestPersistent;
}
''')
val p = m.elements.head as Parameter
assertThat(p.^default.value, is(equalTo("Something")))
assertThat((p.type as EntityRefDecl).type, is(any(Persistent)))
}
to no effect. i still get java.lang.AssertionError: Expected no errors, but got :ERROR (org.eclipse.xtext.diagnostics.Diagnostic.Linking) 'Couldn't resolve reference to Persistent 'tests.TestPersistent'.' on EntityRefDecl
I also tried to pass the resource set out of the createWDLPersistent method and use that with ParseHelper to load the resource with the reference - no success
[Updated on: Thu, 02 October 2014 13:54] Report message to a moderator
|
|
|
Re: Unit Test cross reference from one DSL to another DSL [message #1436171 is a reply to message #1436166] |
Thu, 02 October 2014 14:04 |
|
with your suggestions, I'm now able to load the resource for the second DSL without tricks, just by calling rs.createResource with an appropriate URI.
I've put this in the createWDLPersistent method to verify:
val root = r.contents.get(0) as ModelFragment
val p = root.elements.head as Persistent
System.err.println(p)
and that works (so loading the resource did what i expect, and i get this output:)
com.wamas.wdl.wDL.impl.PersistentImpl@1735af2d (name: TestPersistent) (category: UNSET)
I also test-wise tried to call a QualifiedNameProvider for the second DSL to see whether i misspelled the reference, the result is tests.TestPersistent, which is exactly what i reference (i checked and copy paste replaced the name to be really, really sure).
Still; i get the error that it is not able to resolve... more hints?
[Updated on: Thu, 02 October 2014 14:04] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03175 seconds