Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error When Using Import and Mixin(Cannot run unit tests when using mixin and import)
Error When Using Import and Mixin [message #1771856] Thu, 31 August 2017 12:43 Go to next message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
I have an existing Ecore model that I want to import into a second grammar; I also want to mix in the original grammar associated with that Ecore model in the second grammar so that I don't have to copy and paste all the grammar rules in order to extend it in the second one. I am building two different editors for two grammars that are related to one another.

When I do this and run the workflow, everything seems to be generated correctly. However, when I try to run the generated parser unit test, the JUnit plugin for Eclipse generates an error saying that there are unrooted tests.

Unit testing seems to work fine when I only import the existing Ecore model, or when I only mix in the original grammar.

Does anyone have a suggestion on where to start troubleshooting this problem?

Re: Error When Using Import and Mixin [message #1771859 is a reply to message #1771856] Thu, 31 August 2017 13:05 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 602
Registered: July 2009
Location: Dortmund, Germany
Senior Member

I don't see what an unrooted test reported by JUnit relates to the grammar mixin. Would it be possible to boil it down to a minimal example that you could attach?

I would start identifying why JUnit thinks that it cannot execute tests.
Re: Error When Using Import and Mixin [message #1771864 is a reply to message #1771859] Thu, 31 August 2017 13:31 Go to previous messageGo to next message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
I'm not sure what the relationship between JUnit and the mixin is either. It was significant to me that the test works with a mixin only or an import only, but not with both. I'll work up a simple example to post.
Re: Error When Using Import and Mixin [message #1771870 is a reply to message #1771864] Thu, 31 August 2017 14:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12041
Registered: July 2009
Senior Member
are you sure the tests are correct

@Test annotation, maybe explicit void return type etc

e.g.

@Test def void testSomething() {}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error When Using Import and Mixin [message #1771878 is a reply to message #1771870] Thu, 31 August 2017 15:13 Go to previous messageGo to next message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
Yes, I have the @Test annotation on my simple test method:

/*
 * generated by Xtext 2.12.0
 */
package com.selinc.nxx.factoryblocks.tests

import com.google.inject.Inject
import com.selinc.nxx.structuredtext.structuredText.StructuredTextModel
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*
import com.selinc.nxx.factoryblocks.factoryBlocks.Library

@RunWith(XtextRunner)
@InjectWith(FactoryBlocksInjectorProvider)
class FactoryBlocksParsingTest {
	@Inject
	ParseHelper<Library> parseHelper
	
	@Test
	def void loadModel() {
		println('hello')
		val result = parseHelper.parse('''
			Hello Xtext!
		''')
                var s = "Bob"
		assertNotNull(s)
		Assert.assertTrue(result.eResource.errors.isEmpty)
	}
}

Re: Error When Using Import and Mixin [message #1771882 is a reply to message #1771878] Thu, 31 August 2017 15:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12041
Registered: July 2009
Senior Member
the then having a simple reproducing example would help

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error When Using Import and Mixin [message #1771895 is a reply to message #1771882] Thu, 31 August 2017 19:56 Go to previous messageGo to next message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
When I produce a simple example, it seems to work fine. However, in our production project, it does not. The problem with the unit test seems to be related to dependency injection. Here is what shows up in the JUnit test output:

com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 66129
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
	at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
	at com.google.inject.internal.util.$StackTraceElements.forMember(StackTraceElements.java:53)
	at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:712)
	at com.google.inject.internal.Errors.formatSource(Errors.java:684)
	at com.google.inject.internal.Errors.format(Errors.java:555)
	at com.google.inject.CreationException.getMessage(CreationException.java:48)
	at java.lang.Throwable.getLocalizedMessage(Throwable.java:391)
	at java.lang.Throwable.toString(Throwable.java:480)
	at java.lang.String.valueOf(String.java:2979)
	at java.io.PrintWriter.println(PrintWriter.java:754)
	at java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:764)
	at java.lang.Throwable.printStackTrace(Throwable.java:655)
	at java.lang.Throwable.printStackTrace(Throwable.java:721)
	at org.junit.runner.notification.Failure.getTrace(Failure.java:75)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:91)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:69)
	at org.junit.runner.notification.SynchronizedRunListener.testFailure(SynchronizedRunListener.java:63)
	at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:142)
	at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:72)
	at org.junit.runner.notification.RunNotifier.fireTestFailures(RunNotifier.java:138)
	at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:132)
	at org.junit.internal.runners.model.EachTestNotifier.addFailure(EachTestNotifier.java:23)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:369)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 66129
	at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
	at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
	at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
	at com.google.inject.internal.util.$LineNumbers.<init>(LineNumbers.java:62)
	at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:36)
	at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:33)
	at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
	... 30 more


Re: Error When Using Import and Mixin [message #1771896 is a reply to message #1771895] Thu, 31 August 2017 20:06 Go to previous messageGo to next message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
Also, it seems to be specifically related to the injection of the ParseHelper. When I comment out this line in my test, then the test will run:

@Inject
	ParseHelper<LibraryModel> parseHelper
Re: Error When Using Import and Mixin [message #1771900 is a reply to message #1771896] Thu, 31 August 2017 20:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12041
Registered: July 2009
Senior Member
I need a sample project to clone or download

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error When Using Import and Mixin [message #1771901 is a reply to message #1771900] Thu, 31 August 2017 20:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12041
Registered: July 2009
Senior Member
Maybe you have different asm versions or something like that

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error When Using Import and Mixin [message #1771923 is a reply to message #1771901] Fri, 01 September 2017 07:08 Go to previous messageGo to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 9
Registered: July 2009
Junior Member
From the stack trace I would guess that for some reason the test is failing and there is a bug related to (JUnit View | Xtend | Guice) failing to display the stack trace to you. Maybe it is worth to run the unit tests from command line to maybe get at the stack trace.

https://stackoverflow.com/questions/2235276/how-to-run-junit-test-cases-from-the-command-line

Or maybe setting a suitable breakpoint to investigate the stack trace in the debiugger. Probably at JUnit4TestListener.java:91
Re: Error When Using Import and Mixin [message #1771986 is a reply to message #1771923] Sat, 02 September 2017 16:35 Go to previous message
Greg Lusk is currently offline Greg LuskFriend
Messages: 32
Registered: February 2017
Location: USA
Member
It turns out that I needed to inject the dependencies in the runtime module of the child language. Dependency injection was failing for our custom type computers, etc. Once the dependencies could be found, everything worked. In the process of throwing the original exception, a subsequent exception was thrown when trying to format the message associated with the original one.
Previous Topic:Xtext generate visitor and traversal
Next Topic:Xtend template using a Metamodel (ecore)
Goto Forum:
  


Current Time: Sun Jun 24 03:51:52 GMT 2018

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

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

Back to the top