Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Migrating content assist tests to Xpect possible?
Migrating content assist tests to Xpect possible? [message #1777704] Fri, 01 December 2017 18:48 Go to next message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 337
Registered: July 2009
Senior Member
I am currently migrating several tests to Xpect, but fail with the content assist.

These work fine if I use something like:

@RunWith(XtextRunner)
@InjectWith(MyDslUiInjectorProvider)
class SimpleContentAssistTest extends AbstractContentAssistTest {

    @Test
    def void testSomething() {
        newBuilder
            .assertCount(123)
            .assertText('foo', 'bar')
    }
}


Now I tried to achieve the same with Xpect, inspired by https://github.com/eclipse/Xpect/issues/79 which references an (obsolete) example.

Here is what I have at the moment:

@RunWith(XpectRunner)
@XpectImport(#[XtextStandaloneSetup, XtextWorkspaceSetup])
@XpectTestFiles(relativeTo = FileRoot.PROJECT, baseDir = "model/testcases/contentassist", fileExtensions="xt")
class MyDslContentAssistTest extends AbstractContentAssistTest {

    @ParameterParser(syntax = "('at' arg2=OFFSET)?")
    @Xpect
    def void proposedElements(
        @CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation,
        @ThisResource XtextResource resource,
        int offset
    ) throws Exception {
        setUp
        val content = resource.parseResult.rootNode.text
        val fixture = newBuilder.append(content)
        val proposals = fixture.computeCompletionProposals(offset).toList.map[displayString]
        expectation.assertEquals(proposals)
        tearDown
    }
}


The setUp and tearDown calls are due to https://github.com/eclipse/Xpect/issues/204

The tests result in exceptions like:

!ENTRY org.apache.log4j 4 0 2017-12-01 19:42:29.876
!MESSAGE org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory  - java.lang.NullPointerException

!STACK 0
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.doCreateContexts(ContentAssistContextFactory.java:180)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.create(ContentAssistContextFactory.java:130)
	at org.eclipse.xtext.ui.editor.contentassist.antlr.DelegatingContentAssistContextFactory$StatefulFactory.doCreateContexts(DelegatingContentAssistContextFactory.java:92)
	at org.eclipse.xtext.ui.editor.contentassist.antlr.DelegatingContentAssistContextFactory$StatefulFactory.create(DelegatingContentAssistContextFactory.java:78)
	at org.eclipse.xtext.ui.editor.contentassist.antlr.DelegatingContentAssistContextFactory.create(DelegatingContentAssistContextFactory.java:55)
	at org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer.createContentAssistContexts(CompletionProposalComputer.java:67)
	at org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer.exec(CompletionProposalComputer.java:49)
	at org.eclipse.xtext.ui.editor.contentassist.CompletionProposalComputer.exec(CompletionProposalComputer.java:1)
	at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:91)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.internalReadOnly(XtextDocument.java:520)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.priorityReadOnly(XtextDocument.java:485)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.priorityReadOnly(XtextDocument.java:142)
	at org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor.computeCompletionProposals(XtextContentAssistProcessor.java:69)
	at org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:509)
	at org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:500)
	at org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:490)
	at org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:478)
	at org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder.computeCompletionProposals(ContentAssistProcessorTestBuilder.java:559)
	at org.example.mydsl.ui.tests.contentassist.MyDslContentAssistTest.proposedElements(MyDslContentAssistTest.java:44)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.xpect.runner.TestExecutor.runTest(TestExecutor.java:150)
	at org.xpect.runner.XpectTestRunner.runInternal(XpectTestRunner.java:67)
	at org.xpect.runner.AbstractTestRunner.run(AbstractTestRunner.java:59)
	at org.xpect.runner.XpectFileRunner.run(XpectFileRunner.java:142)
	at org.xpect.runner.XpectRunner.runChild(XpectRunner.java:208)
	at org.xpect.runner.XpectRunner.runChild(XpectRunner.java:1)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.xpect.runner.XpectRunner.run(XpectRunner.java:194)
	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:539)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:181)
	at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness.lambda$0(PlatformUITestHarness.java:43)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:37)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:182)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4497)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4110)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
	at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:52)
	at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:43)
	at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:46)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)
Caused by: java.lang.NullPointerException
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:342)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:337)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:331)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.AbstractContentAssistParser.getFollowElements(AbstractContentAssistParser.java:381)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.handleLastCompleteNodeIsAtEndOfDatatypeNode(ContentAssistContextFactory.java:229)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$2.call(ContentAssistContextFactory.java:160)
	at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory$2.call(ContentAssistContextFactory.java:157)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)


Am I doing something obviously wrong? Or should I just avoid using Xpect for that?

Interestingly testing the outline view using Xpect works like a charm. So I thought it should be possible for other subclasses of AbstractEditorTest, too.

[Updated on: Sun, 03 December 2017 17:30]

Report message to a moderator

Re: Migrating content assist tests to Xpect possible? [message #1778482 is a reply to message #1777704] Thu, 14 December 2017 17:24 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Unfortunately I do not have the time to look into your code in detail. I assume that in the last 4 years, a lot of things were changed in Xpect...
We have also implemented some Content Assist related Xpect tests in N4JS, and you can find the code here:

https://github.com/eclipse/n4js/blob/master/plugins/org.eclipse.n4js.xpect.ui/src/org/eclipse/n4js/xpect/ui/methods/contentassist/ContentAssistXpectMethod.java
and examples of how we use that at
https://github.com/eclipse/n4js/tree/master/tests/org.eclipse.n4js.xpect.ui.tests/testdata_nonvalidating/proposal/contentassist

The Xpect method uses some helper classes (N4JSOffsetAdapter etc.), but I think neither the method nor these helper are not really depending on or specific to N4JS.
Re: Migrating content assist tests to Xpect possible? [message #1778549 is a reply to message #1778482] Sat, 16 December 2017 17:34 Go to previous message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 337
Registered: July 2009
Senior Member
Thank you very much for the pointer!
Going to take a closer look at your repository soon.
Previous Topic:Restrict references scope to objects declared before (including objects from imports)
Next Topic:XtextGenerator unexpected package name for generated UI.Activator
Goto Forum:
  


Current Time: Sat Jul 21 15:49:56 GMT 2018

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

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

Back to the top