Frage

I want to write some tests for my compiler but can't get past an error.

I'm following an example from 'Implementing DSL with Xtext and Xtend' by L. Bettini (great book btw). I've downloaded the code for the 'entities' DSL from https://github.com/LorenzoBettini/packtpub-xtext-book-examples and the tests in EntitiesGenerator.xtend work great.

If I write a test for the default DSL (MyDsl) using the same code, I've got an error:

  • org.eclipse.xtext.xbase.compiler.CompilationTestHelper cannot be resolved to a type.

or, if I add org.eclipse.xtext.xbase.junit (2.4.1) to the list of required plug-ins, I get

  • Discouraged access: The type CompilationTestHelper is not accessible due to restriction on required project org.xtext.example.myDsl.tests

I can allow access to it, but then get a runtime error anyway. If I try to add org.eclipse.xtext.xbase.lib as well, only org.eclipse.xtext.xbase.lib.source appears in the list. I don't know it that matters. In any case, adding it doesn't change anything.

What do I need to do to make it work?

I'm using Juno with Xtext 2.4.1., Java 1.7.

The content of the test class:

package org.xtext.example.myDsl.tests

import com.google.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper // error here
import org.xtext.example.myDsl.MyDslInjectorProvider
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(MyDslInjectorProvider))
class MyDslGeneratorTest {

    @Inject extension CompilationTestHelper

    @Test
    def void testGeneratedCode() {
        '''
    Hello some1!
    Hello some2!
        '''.assertCompilesTo(
        '''some content''')
    }
}

Thank you in advance!

War es hilfreich?

Lösung

the xtext guys mark stuff that may be changed NOT as api. this is why you get this warning. it should work anyway. (although it is meant to be used for xbase languages only)

P.S: you have to add a dependency to jdt.core too

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top