Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to test global scoping / xtext index
How to test global scoping / xtext index [message #1064736] Thu, 20 June 2013 17:32 Go to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 295
Registered: July 2009
Senior Member

I have implemented an Xtext based language with custom global scoping,
e.g., with a custom implementation of IResourceDescription.Manager etc.
While I can easily test local scoping using @RunWith(XtextRunner) and
things like the ParseHelper, I'm not sure how to best test global
scoping related issues, e.g., which things are exported. Since this
seems a common task, I was wondering if there is something like a
pattern for that or/and some helper classes available in Xtext already?

Re: How to test global scoping / xtext index [message #1064832 is a reply to message #1064736] Fri, 21 June 2013 09:47 Go to previous message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 295
Registered: July 2009
Senior Member

well, I can answer that myself:

First, let's test if everything is correctly exported:

class MyLangScopingTest {
extension ParseHelper<Program>

ResourceDescriptionsProvider resourceDescriptionsProvider;

def void testExport() {
val program =
my program with some exported elements

// syntax ok?

val IResourceDescriptions resDescr =

// do something, e.g.

Note that the resource's URI is a synthetic one similar to
Also see
However, it is possible to explicitly set the URI in the parse method,
as shown in the next setup.

This first example only checked the exported elements. Now, let's test a
cross link between different files (in a new test method, test class
is the one of the first example):

def void testImportExport() {
// use one resource set
val rs = new XtextResourceSet();

val supplier =
program exporting something
'''.parse(URI.createURI("Supplier.mylang"), rs)

val someExportedElement =

val client =
// program importing the Supplier, e.g
import Supplier;
// and accessing the exported element, e.g.
'''.parse(URI.createURI("Client.mylang"), rs)

// trigger linking

val reference = client.eAllContents.filter(ReferenceType).head;
assertEquals(someExportedElement, reference.element);

Of course, you have to ensure that your global scoping (including naming
and URI resolving) can work with the test setup (e.g., neither a
classpath nor an Eclipse project is available in the sample setup).

Previous Topic:Xtext Grammar - Exclusion of a specific Rule
Next Topic:Expression Grammar [fatal] Error
Goto Forum:

Current Time: Sun Oct 04 11:23:06 GMT 2015

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

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