Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Compiler tests for multi-DSLs?(How to write compiler tests for a super DSL?)
Compiler tests for multi-DSLs? [message #1780733] Fri, 26 January 2018 11:53 Go to next message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
I found some nice resources how to use 2 DSLs: e.g.


That also helped me to get all parsing tests working.

Example:
in project xtext-multi-dsl we have MyDslA which does not know anything about MyDslB.
MyDslB on the other hand imports MyDslA (and thus depends on MyDslA).

In this case I can write a simple compiler tests-working for the MyDslA.
But how can we write compiler tests for the MyDslB (which is dependent on MyDslA)?

e.g. I think I'd need to:

  • first load the sub-dsl model file
  • trigger the sub-dsl generator
  • put the generated files on the classpath
  • load the super-dsl model file
  • and finally generate and check the generated super-dsl files


Maybe there is already some example project for such tests?


[Updated on: Fri, 26 January 2018 12:36]

Report message to a moderator

Re: Compiler tests for multi-DSLs? [message #1780734 is a reply to message #1780733] Fri, 26 January 2018 11:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what do you means by sub and superdsl and how do the relate to each other
if these are simple dsls referencing each other simply load both files at once is the way to go.
the only thing you may need to make sure is that the standalonesetups for both dsls are called.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Compiler tests for multi-DSLs? [message #1780736 is a reply to message #1780734] Fri, 26 January 2018 12:48 Go to previous messageGo to next message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
Christian Dietrich wrote on Fri, 26 January 2018 11:56
what do you means by sub and superdsl and how do the relate to each other

Sorry, these terms were wrong. I had them from another example. I've edited the question to clarify.

Quote:

if these are simple dsls referencing each other simply load both files at once is the way to go.

And how could I do that?
e.g. currently I just pass the model as string to CompilationTestHelper.compile()


Re: Compiler tests for multi-DSLs? [message #1780738 is a reply to message #1780736] Fri, 26 January 2018 13:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
same as your other questions. have a look at the compilation test helper code and improvise ....

@RunWith(XtextRunner)
@InjectWith(DomainmodelInjectorProvider2)
class CompilerTest {
	
	static class DomainmodelInjectorProvider2 extends DomainmodelInjectorProvider {
		
		override protected internalCreateInjector() {
			XtendStandaloneSetup.doSetup
			super.internalCreateInjector()
		}
		
	}
	
	@Rule
	@Inject public TemporaryFolder temporaryFolder 
	@Inject extension CompilationTestHelper
	@Inject extension ReflectExtensions

	@Test
	def void testGeneratedJavaFromSeveralInputs() {
		resourceSet(#[
		"a.dmodel" -> '''
			entity Foo {
				bar : Bar
				op doStuff(String x) : String {
					return x + ' ' + bar.getName()
				}
			}
		''',
		"b.dmodel" ->'''
			entity Bar extends Bat {
				name : String
			}
		''',
		"Bat.xtend" -> '''
		class Bat {}'''
		]).compile [
			Assert.assertEquals(''''''.toString, singleGeneratedCode)
		]
	}
	
	
	
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Compiler tests for multi-DSLs? [message #1780739 is a reply to message #1780738] Fri, 26 January 2018 13:15 Go to previous message
Martin Trummer is currently offline Martin TrummerFriend
Messages: 17
Registered: December 2017
Junior Member
Thanks that works! I didn't think it could be that easy :)

Here's a simplistic test-project (using gradle): ex.xtext.twog Tag:CompilerTestOk

[Updated on: Sat, 27 January 2018 14:11]

Report message to a moderator

Previous Topic:Which Platform Version do you use with Xtext
Next Topic:maven mwe2Launcher for XText 2.13.0
Goto Forum:
  


Current Time: Fri Apr 26 09:05:53 GMT 2024

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

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

Back to the top