Problem: Validator/Generator cannot navigate through AST/Index/ResourceSet from Unit-Tests [message #1725978] |
Tue, 08 March 2016 14:11  |
Eclipse User |
|
|
|
Hello *,
I would like to implement unit tests for mydsl. Specifically for the validator and the generators.
Both the Validator, and the generators query the index (ResourceSet) to objects in the AST - and find nothing. Why not? (Please see attached file).
In unit test I set up a ResourceSet of three models and can navigate through the AST also. However, the validator and the generators can not access the ResourceSet (or find anything).
Why is that?
The most important code snippets (for example ValidatorTest):
Unit-Test:
@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class MyDslValidatorTest {
static val DATATYPES = '''
datatypes {
type Integer
type String
type Date
type Timestamp
}
'''
// static val CONFIGURATION = '''
// configuration ConfigX {
// }
// '''
@Inject extension ParseHelper<Model>
@Inject extension ValidationTestHelper
@Inject extension Provider<XtextResourceSet>
var resourceSet = null as XtextResourceSet
@Before
def void setup() {
resourceSet = get
resourceSet.classpathURIContext = this
DATATYPES.parse(URI.createURI("datatypes.mydsl"), resourceSet)
// TESTCASE: no config should raise an error in MyDslValidator
// val config = resourceSet.createResource(URI.createURI("config.mydsl"))
// config.load(new StringInputStream(CONFIGURATION), emptyMap)
}
@Test
def testCheckConfiguration() {
val model = '''
package foo.bar
entity MyEntity
{
Id : Integer
Name : String
ValidFrom : Timestamp
}
'''.parse(URI.createURI("model.mydsl"), resourceSet)
model.assertError(MyDslPackage.Literals.MODEL, 'ERR-CODE-0815')
}
}
Validator:
@Inject extension ResourceExtension
@Check
def checkConfiguration(Model it) {
if (eResource.allConfigurations.nullOrEmpty) {
error("no config? no cookies!", MyDslPackage.Literals.MODEL__PACKAGE, 'ERR-CODE-0815')
}
}
What's wrong in my example? *headscratch*
Please - help ;-)
Tobias
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06883 seconds