Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [2.7.0] Guice errors when unit-testing the generator
[2.7.0] Guice errors when unit-testing the generator [message #1418850] Sun, 07 September 2014 19:06 Go to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
Hi there,

I've just upgraded to 2.7.0 and now get a blocking error when I try and unit-test the generator. The unit tests for the parser and the validator pass with flying colours.

From the generator test:
@Test
def void testMinimalModel(){
    val source = readFile("../myDSL.dsl/models/minimalModel.dsl",Charset.defaultCharset())
    source.assertCompilesTo(readFile("../myDSL.dsl/models/minimalModel.xml",Charset.defaultCharset()))				
}


Error:
com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for org.eclipse.xtend.lib.macro.file.MutableFileSystemSupport was bound.
  while locating org.eclipse.xtend.lib.macro.file.MutableFileSystemSupport
    for field at org.eclipse.xtext.generator.FileSystemSupportBasedFileSystemAccess.fileSystemSupport(Unknown Source)
  while locating com.google.inject.Provider<org.eclipse.xtext.xbase.compiler.RegisteringFileSystemAccess>
    for field at org.eclipse.xtext.xbase.compiler.CompilationTestHelper$Result.fileSystemAccessProvider(Unknown Source)
  while locating com.google.inject.Provider<org.eclipse.xtext.xbase.compiler.CompilationTestHelper$Result>
    for field at org.eclipse.xtext.xbase.compiler.CompilationTestHelper.resultProvider(Unknown Source)
  while locating org.eclipse.xtext.xbase.compiler.CompilationTestHelper
    for field at roadblock.xtext.ibl.tests.IblGeneratorTests._compilationTestHelper(Unknown Source)
  while locating roadblock.xtext.ibl.tests.IblGeneratorTests

1 error
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:952)
	at com.google.inject.internal.InjectorImpl.getMembersInjector(InjectorImpl.java:957)
	at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:943)
	at org.eclipse.xtext.junit4.XtextRunner.createTest(XtextRunner.java:33)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241)
	at org.eclipse.xtext.junit4.XtextRunner.superMethodBlock(XtextRunner.java:64)
	at org.eclipse.xtext.junit4.XtextRunner.methodBlock(XtextRunner.java:44)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.junit4.runtime.patch.JUnit4TestReference.run(JUnit4TestReference.java:42)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I can run the the project as an Eclipse application without this error. I'm on Juno Version: Juno Service Release 2, Build id: 20130225-0426. I've got nothing left to update.

Any ideas what could be happening here? And how to fix it?

Thank you!
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419129 is a reply to message #1418850] Mon, 08 September 2014 06:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Did you regenerate the language? how do you use xbase? The xbase generator Fragment in your workflow should have generated in your abstractruntimemodule

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419198 is a reply to message #1419129] Mon, 08 September 2014 08:36 Go to previous messageGo to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
thank you for looking into this!

I did regenerate the language (Generate Xtext Artefacts) and still get the error, even with my generator consisting in a single println command.

I don't think I'm using xbase, or at least not knowingly.


Re: [2.7.0] Guice errors when unit-testing the generator [message #1419206 is a reply to message #1419198] Mon, 08 September 2014 08:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

CompilationTestHelper is from xbase so it asumes you use an xbase language


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419255 is a reply to message #1419206] Mon, 08 September 2014 10:29 Go to previous messageGo to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
I see that xbase is used during the language generation:
243  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel '######www.eclipse.org/Xtext/Xbase/XAnnotations' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'
247  [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel '######www.eclipse.org/xtext/xbase/Xtype' from 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel'

(###### is for http etc. I can't post urls yet)

The code for the generator unit-test is:
package roadblock.xtext.ibl.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
import roadblock.xtext.ibl.IblInjectorProvider
import org.junit.Test
import org.junit.runner.RunWith
import java.io.IOException
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.ByteBuffer

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(IblInjectorProvider))

class IblGeneratorTests {
	
	@Inject extension CompilationTestHelper
	
		// read file into a string
	// from ######stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file
	def static String readFile(String path, Charset encoding)  throws IOException 
	{
		var byte[] encoded = Files.readAllBytes(Paths.get(path)) 
	 	return encoding.decode(ByteBuffer.wrap(encoded)).toString
	}

	@Test
	def void testMinimalModel(){
		val source = readFile("../roadblock.xtext.ibl/models/minimalModel.ibl",Charset.defaultCharset())
		source.assertCompilesTo(readFile("../roadblock.xtext.ibl/models/minimalModel.xml",Charset.defaultCharset()))				
	}
}


It was working fine before the upgrade to 2.7.0. I tried on Kepler as well, to the same effect.

Edit:
I just tried this:
@Test
	def testiftrue(){
		assertTrue(true)
		
	}

And got the same error. So it's not due to assertCompilesTo.

[Updated on: Mon, 08 September 2014 10:34]

Report message to a moderator

Re: [2.7.0] Guice errors when unit-testing the generator [message #1419332 is a reply to message #1419255] Mon, 08 September 2014 12:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

did you have a look at the generated code in the abstractyourdslruntimemodule.
i did not have a look at the fragment if it only generates the stuff depending on if xbase is really used.

in my xbase project i can find

	// contributed by org.eclipse.xtext.generator.xbase.XbaseGeneratorFragment
	public Class<? extends org.eclipse.xtend.lib.macro.file.MutableFileSystemSupport> bindMutableFileSystemSupport() {
		return org.eclipse.xtext.xbase.file.JavaIOFileSystemSupport.class;
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419417 is a reply to message #1419332] Mon, 08 September 2014 15:34 Go to previous messageGo to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
Ah that's interesting: there is no trace of xbase in abstractyourdslruntimemodule. Should it be there?
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419454 is a reply to message #1419417] Mon, 08 September 2014 16:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
it depends if you use xbase in your grammar. if not why do you use xbase test classes? just cause existing compilationtesthelper was convenient?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [2.7.0] Guice errors when unit-testing the generator [message #1419847 is a reply to message #1419454] Tue, 09 September 2014 07:03 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 08/09/2014 18:36, Christian Dietrich wrote:
> it depends if you use xbase in your grammar. if not why do you use xbase
> test classes? just cause existing compilationtesthelper was convenient?

I had exactly the same issue, testing a language with
CompilationTestHelper, without using Xbase... as for me, I find
CompilationTestHelper quite convenient to test that the generated code
is as expected :)

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [2.7.0] Guice errors when unit-testing the generator [message #1420216 is a reply to message #1419847] Tue, 09 September 2014 17:31 Go to previous messageGo to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
ah! I used CompilationTestHelper precisely because I'm following your (very helpful) book!

Did you find a workaround for this issue? What is an alternative for testing the generator?
Re: [2.7.0] Guice errors when unit-testing the generator [message #1420233 is a reply to message #1420216] Tue, 09 September 2014 18:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
simply add the binding ?!? or copy and paste and stip down the compilationtesthelper

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [2.7.0] Guice errors when unit-testing the generator [message #1421449 is a reply to message #1420216] Thu, 11 September 2014 11:34 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 09/09/2014 19:31, Chris L. wrote:
> ah! I used CompilationTestHelper precisely because I'm following your
> (very helpful) book!
>
> Did you find a workaround for this issue? What is an alternative for
> testing the generator?

As Christian suggested, you should add the explicit binding... I'd be
tempted to add it as a custom InjectorProvider only in the tests project
(see the domain model example tests to see how to create and use a
custom injector provider with specific bindings).

I'll try to update the example of the book and also submit an errata :)

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [2.7.0] Guice errors when unit-testing the generator [message #1425557 is a reply to message #1420216] Wed, 17 September 2014 13:28 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 09/09/2014 19:31, Chris L. wrote:
> ah! I used CompilationTestHelper precisely because I'm following your
> (very helpful) book!
>
> Did you find a workaround for this issue? What is an alternative for
> testing the generator?

Hi

I've updated the sources of examples of the book:

https://github.com/LorenzoBettini/packtpub-xtext-book-examples

on the main page you also find all the ERRATA (in the README.md), in
particular, two ways of specifying the bindings to avoid this error in
languages that use CompilationTestHelper but are not based on Xbase :)

Hope this helps
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [2.7.0] Guice errors when unit-testing the generator [message #1425561 is a reply to message #1425557] Wed, 17 September 2014 13:34 Go to previous messageGo to next message
Chris L. is currently offline Chris L.Friend
Messages: 11
Registered: September 2014
Junior Member
That looks great, I look forward to trying this out!

Thank you!
Re: [2.7.0] Guice errors when unit-testing the generator [message #1706057 is a reply to message #1425557] Fri, 21 August 2015 12:56 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 20
Registered: June 2015
Junior Member
Hi Lorenzo,

I implemented the solution given by you for using CompilationTestHelper for my DSL (inheriting from Xtype).
However, I am getting NullPointerException in CompilationTestHelper.doIndex().
I found this entry on your site; but I am unable to figure out on how to fix this NullPointerException.

Could you please help me here?

[EDIT]:
I am using Xtext 2.8.3

[Updated on: Fri, 21 August 2015 13:26]

Report message to a moderator

Re: [2.7.0] Guice errors when unit-testing the generator [message #1706095 is a reply to message #1706057] Sat, 22 August 2015 12:32 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 21/08/2015 14:56, Manisha Ghule wrote:
> Hi Lorenzo,
>
> I implemented the solution given by you for using CompilationTestHelper
> for my DSL (inheriting from Xtype).
> However, I am getting NullPointerException in
> CompilationTestHelper.doIndex().
> I found https://github.com/LorenzoBettini/xsemantics/issues/29 entry on
> your site; but I am unable to figure out on how to fix this
> NullPointerException.
>
> Could you please help me here?

Hi

if I remember correctly, you should first parse all the inputs using the
CompilationTestHelper method that takes many inputs.

Does that solve your problem?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: [2.7.0] Guice errors when unit-testing the generator [message #1706136 is a reply to message #1706095] Mon, 24 August 2015 06:51 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 20
Registered: June 2015
Junior Member
Hi,

I cannot use that method because I have two different DSLs (One DSL uses another DSL element as JvmTypeReference).
So I create and load resources for them in a single resourceSet and then pass this resourceSet to CompilationTestHelper method.

I followed this post and corresponding thread in eclipse forum, but I was getting "Couldn't resolve reference to JvmType" error with using ParseHelper.
Hence I am trying to use CompilationTestHelper.

Note: I am not directly using cross reference to another DSL, but using JvmTypeReference instead.

Any pointers to solve this?
Re: [2.7.0] Guice errors when unit-testing the generator [message #1706796 is a reply to message #1706136] Mon, 31 August 2015 08:29 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 20
Registered: June 2015
Junior Member
Hi Lorenzo,

Fixed NullPointerException.

The key was to call CompilationTestHelper method resourceSet( List<Pair<fileName, contents>> ).

I think you were talking about the same; but earlier I assumed you were suggesting CompilationTestHelper.compile(Iterable<CharSeq>) Smile

Thank you for your inputs. Smile

[Updated on: Mon, 31 August 2015 12:36]

Report message to a moderator

Re: [2.7.0] Guice errors when unit-testing the generator [message #1708070 is a reply to message #1706796] Sat, 12 September 2015 07:44 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 31/08/2015 10:29, Manisha Ghule wrote:
> Hi Lorenzo,
>
> Solved the problem.
>
> The key was to call CompilationTestHelper method resourceSet(
> List<Pair<fileName, contents>> ) because this method also copies
> resources to workspace.
>
> I think you were talking about the same; but earlier I assumed you were
> suggesting CompilationTestHelper.compile(Iterable<CharSeq>) :)
> Thank you for your inputs. :)

Sorry for the delay; but you seem to have already fixed the problem
yourself :)

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:new formatting API and Xbase inherited grammar
Next Topic:Howto xtext rcp4?
Goto Forum:
  


Current Time: Tue Apr 16 11:28:43 GMT 2024

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

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

Back to the top