public class CompilationTestHelper
extends java.lang.Object
@RunWith(XtextRunner)
@InjectWith(MyLanguageInjectorProvider)
class CompilerTest {
@Rule @Inject public TemporaryFolder temporaryFolder
@Inject extension CompilationTestHelper
@Test def void myTest() {
'''
// DSL code
Foo bla
'''.assertCompilesTo('''
class Foo {
String bla
}
'''
}
}
| Modifier and Type | Class and Description |
|---|---|
static class |
CompilationTestHelper.Result
A result contains information about various aspects of a compiled piece of code.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
PROJECT_NAME |
| Constructor and Description |
|---|
CompilationTestHelper() |
| Modifier and Type | Method and Description |
|---|---|
void |
assertCompilesTo(java.lang.CharSequence source,
java.lang.CharSequence expected)
Asserts that the expected code is generated for the given source.
|
void |
compile(java.lang.CharSequence source,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
Parses, validates and compiles the given source.
|
void |
compile(java.lang.Iterable<? extends java.lang.CharSequence> sources,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
Parses, validates and compiles the given sources.
|
void |
compile(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
Parses, validates and compiles the given source.
|
void |
configureFreshWorkspace()
creates a fresh temp directory and sets it as the workspace root.
|
org.eclipse.emf.common.util.URI |
copyToWorkspace(java.lang.String workspacefilePath,
java.lang.CharSequence contents)
Physically copies the given files to the currently used workspace root (a temporary folder).
|
protected java.io.File |
createFreshTempDir() |
protected org.eclipse.xtext.validation.CheckMode |
getCheckMode() |
protected java.lang.Iterable<? extends org.eclipse.xtext.generator.OutputConfiguration> |
getOutputConfigurations() |
protected java.lang.String |
getSourceFolderPath() |
org.eclipse.emf.ecore.resource.ResourceSet |
resourceSet(org.eclipse.xtext.xbase.lib.Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
creates a fresh resource set with the given resources
|
void |
setJavaCompilerClassPath(java.lang.Class<?>... classes)
Add the class path entries of the given classes to the java compiler's class path.
|
void |
setJavaCompilerClassPath(java.lang.ClassLoader classLoader) |
void |
setJavaVersion(org.eclipse.xtext.util.JavaVersion javaVersion)
Sets the Java version both for the DSL generator, for example, Xbase
compiler, and for the Java compiler.
|
org.eclipse.emf.ecore.resource.ResourceSet |
unLoadedResourceSet(org.eclipse.xtext.xbase.lib.Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
same as
resourceSet(Pair...) but without actually loading the created resources. |
public static final java.lang.String PROJECT_NAME
public void configureFreshWorkspace()
protected java.lang.String getSourceFolderPath()
protected java.io.File createFreshTempDir()
public void setJavaCompilerClassPath(java.lang.Class<?>... classes)
public void setJavaCompilerClassPath(java.lang.ClassLoader classLoader)
public void setJavaVersion(org.eclipse.xtext.util.JavaVersion javaVersion)
public void assertCompilesTo(java.lang.CharSequence source,
java.lang.CharSequence expected)
throws java.io.IOException
source - some valid source code written in the language under testexpected - the expected Java source code.java.io.IOException - if the resource loading failspublic void compile(java.lang.CharSequence source,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
throws java.io.IOException
source - some code written in the language under test.acceptor - gets called once for each file generated in IGeneratorjava.io.IOException - if the resource loading failspublic void compile(java.lang.Iterable<? extends java.lang.CharSequence> sources,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
throws java.io.IOException
sources - some inputs written in the language under test.acceptor - gets called once for each file generated in IGeneratorjava.io.IOException - if the resource loading failspublic void compile(org.eclipse.emf.ecore.resource.ResourceSet resourceSet,
org.eclipse.xtext.util.IAcceptor<CompilationTestHelper.Result> acceptor)
resourceSet - - the ResourceSet to useacceptor - gets called once for each file generated in IGeneratorprotected org.eclipse.xtext.validation.CheckMode getCheckMode()
protected java.lang.Iterable<? extends org.eclipse.xtext.generator.OutputConfiguration> getOutputConfigurations()
public org.eclipse.emf.ecore.resource.ResourceSet resourceSet(org.eclipse.xtext.xbase.lib.Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
throws java.io.IOException
resources - - pairs of file names and their contentsjava.io.IOException - if the resource loading failspublic org.eclipse.emf.common.util.URI copyToWorkspace(java.lang.String workspacefilePath,
java.lang.CharSequence contents)
workspacefilePath - the workspace relative pathcontents - the file contentspublic org.eclipse.emf.ecore.resource.ResourceSet unLoadedResourceSet(org.eclipse.xtext.xbase.lib.Pair<java.lang.String,? extends java.lang.CharSequence>... resources)
throws java.io.IOException
resourceSet(Pair...) but without actually loading the created resources.java.io.IOException