CompilationTestHelper problem with generated non-java code [message #1050667] |
Sat, 27 April 2013 11:00  |
Eclipse User |
|
|
|
Hi all,
I'm using Xtext 2.4.1.
For generating both Java code and XML code from my DSL I have a subclass of JvmModelGenerator.
The generator works fine. From my DSL it produces *.java files and an XML file.
But now I want JUnit-testing my generator and run into trouble.
My Junit test looks like this
package org.xtext.example.mydsl
import com.google.inject.Inject
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.xbase.compiler.CompilationTestHelper
import org.junit.Test
import org.junit.runner.RunWith
import static org.junit.Assert.*
@RunWith(typeof(XtextRunner))
@InjectWith(typeof(MyDslInjectorProvider))
class CompilerTest {
@Inject extension CompilationTestHelper
@Test
def testEntity() {
// The DSL below produces these files:
// com/oce/example/Person.java
// com/oce/example/Address.java
// data/example-ds.xml
'''
package com.oce.example {
entity Person {
}
entity Address {
}
}
database "data/example-ds.xml" {
}
'''.compile [
val person = getCompiledClass("com.oce.example.Person").newInstance
assertNotNull(person)
]
}
}
I got the following error:
java.lang.RuntimeException: java.lang.IllegalArgumentException: Couldn't compile : ----------
1. ERROR in /tmp/otfjc26240014/data/example-d.java (at line 1)
<?xml version="1.0" encoding="UTF-8"?>
^
Syntax error on tokens, delete these tokens
[...]
Caused by: java.lang.IllegalArgumentException: Couldn't compile : ----------
1. ERROR in/tmp/otfjc26240014/data/otfjc26240014\data\example-d.java (at line 1)
<?xml version="1.0" encoding="UTF-8"?>
^
Syntax error on tokens, delete these tokens
[...]
at org.eclipse.xtext.xbase.compiler.OnTheFlyJavaCompiler.compileToClasses(OnTheFlyJavaCompiler.java:315)
at org.eclipse.xtext.xbase.compiler.CompilationTestHelper$2.getCompiledClasses(CompilationTestHelper.java:171)
at org.eclipse.xtext.xbase.compiler.CompilationTestHelper$2.getCompiledClass(CompilationTestHelper.java:223)
at org.xtext.example.mydsl.CompilerTest$1.accept(CompilerTest.java:52)
at org.xtext.example.mydsl.CompilerTest$1.accept(CompilerTest.java:1)
at org.eclipse.xtext.xbase.compiler.CompilationTestHelper.compile(CompilationTestHelper.java:164)
... 26 more
It seems the generated XML file "data/example-ds.xml" has been treated as Java source and fed into the Java compiler.
I don't know if my approach is wrong or if it is a bug of Xtext.
Regards,
Thomas
|
|
|
|
|
Re: CompilationTestHelper problem with generated non-java code [message #1051925 is a reply to message #1051919] |
Mon, 29 April 2013 07:31   |
Eclipse User |
|
|
|
On 04/29/2013 01:24 PM, Thomas Fritsch wrote:
> Jan Kohnlein wrote on Mon, 29 April 2013 10:27
>> The CompilationTestHelper belongs to Xbase and assumes Java code to be
>> generated. This is not a bug but works as designed.
>>
>> If you want to inspect the generated XML code you have to implement
>> your own helper class, e.g. by stripping the Java stuff from
>> org.eclipse.xtext.xbase.compiler.CompilationTestHelper.compile(ResourceSet,
>> IAcceptor<Result>) or using the ParseHelper and the IGenerator of your
>> language.
>
>
> Thanks for your reply.
>
> Ok, I agree. For inspecting the generated XML code I need to implement a helper class of my own. I will begin that soon.
>
> But how about inspecting/testing the generated Java code?
> For doing so it would be nice if the CompilationTestHelper just would gracefully ignore all non-Java code. May be like in attachment.
>
> ~Thomas
>
I was using CompilationTestHelper in Xtext 2.3.1 and I was able to check
also generated Xml files, besides Java files, by inspecting, manually,
all the generated files. I think the proposed modification really
makes sense :)
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.12408 seconds