Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problems using AbstractLanguageServerTest
Problems using AbstractLanguageServerTest [message #1791888] Fri, 06 July 2018 14:59 Go to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
I created a new DSL with the Xtext wizard. I selected language server, Gradle build and JUnit 5 support.

I added a language server test in the <mydsl>.ide project in the source folder src/test/java.

The test class sublasses the AbstractLanguageServerTest and gives the language id in the constructor.

All my tests fail because of this NPE:

java.lang.NullPointerException
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.lambda$initialize$1(AbstractLanguageServerTest.java:289)
	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initialize(AbstractLanguageServerTest.java:291)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initialize(AbstractLanguageServerTest.java:281)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initializeContext(AbstractLanguageServerTest.java:814)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.testCompletion(AbstractLanguageServerTest.java:775)
	at de.abas.screen.ls.ide.tests.completion.ScreenServiceCompletionTest.testEndCompletion(ScreenServiceCompletionTest.java:23)


I use Eclipse Photon and Xtext 2.14.0.
I fixed the build already like it is mentioned here: https://github.com/eclipse/xtext/issues/1231

My DSL is just the Greetings tutorial DSL and one of the failing tests is this:
@Test
	def void test02_openFile() {
		initialize()

		val file = 'hello.mydsl'.writeFile("")
		file.open('''
			Hello Xtext!
		''')

		Assertions.assertTrue(diagnostics.get(file).empty, "There're issues in file 'hello.mydsl'.")
	}



Everything works but not my test. What am I doing wrong?
Re: Problems using AbstractLanguageServerTest [message #1791890 is a reply to message #1791888] Fri, 06 July 2018 15:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you please give more context. i cannot reproduce.

(1) did you add the mydsl.ide project to the test project
(2) is lsp4j and lsp4j.jsonrpc on the dependencies of your test project?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791891 is a reply to message #1791890] Fri, 06 July 2018 15:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
besides that: debugging always helps to analyse

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791892 is a reply to message #1791891] Fri, 06 July 2018 15:26 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
Attached is my build.grade of the <mydsl>.ide project.
  • Attachment: build.gradle
    (Size: 1.97KB, Downloaded 89 times)
Re: Problems using AbstractLanguageServerTest [message #1791893 is a reply to message #1791892] Fri, 06 July 2018 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i miss e.g.

compile project(':de.abas.screen.ls.ide')


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791894 is a reply to message #1791893] Fri, 06 July 2018 15:29 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
I added the test to the project de.abas.screen.ls.ide itself.
Re: Problems using AbstractLanguageServerTest [message #1791895 is a reply to message #1791894] Fri, 06 July 2018 15:35 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
I added a screenshot of my project layout.
Re: Problems using AbstractLanguageServerTest [message #1791896 is a reply to message #1791895] Fri, 06 July 2018 15:42 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
When I debug I can see that the field languageServer of the class AbstractLanguageServerTest is always null. What could be the problem?
Re: Problems using AbstractLanguageServerTest [message #1791897 is a reply to message #1791894] Fri, 06 July 2018 15:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i still cannot reproduce.
are you sure you got language id and file extension correct?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791898 is a reply to message #1791897] Fri, 06 July 2018 15:45 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
Do you recommend to add an extra test project or is it ok to add the test inside the test source folder of the <mydsl>.ide project?
Re: Problems using AbstractLanguageServerTest [message #1791899 is a reply to message #1791898] Fri, 06 July 2018 15:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it is ok i tried both and it works fine

package org.xtext.example.mydsl3.tests

import org.eclipse.xtext.testing.AbstractLanguageServerTest
import org.junit.Assert
import org.junit.Test

class MyTest extends AbstractLanguageServerTest {
	new() {
		super("mydsl3")
	}
	
	@Test
	def void test02_openFile() throws Exception {
		initialize();

		val file = 'hello.mydsl3'.writeFile("")
		file.open('''
			Hello Xtext!
		''')

		Assert.assertTrue("There're issues in file 'hello.mydsl'.", diagnostics.get(file).empty)
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791900 is a reply to message #1791899] Fri, 06 July 2018 15:49 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
How does your build.gradle file look like?
Re: Problems using AbstractLanguageServerTest [message #1791901 is a reply to message #1791900] Fri, 06 July 2018 15:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no change besides the workaround for signature exception.

=> i am sure you have the wrong file extension


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791902 is a reply to message #1791901] Fri, 06 July 2018 15:55 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
I also have this test and this does not work either:

@Test
	def void testEndCompletion() {

		testCompletion[
			model = '''Hello Xtext'''
			line = 0
			column = 10
			expectedCompletionItems = '''!'''

		]
	}
Re: Problems using AbstractLanguageServerTest [message #1791903 is a reply to message #1791901] Fri, 06 July 2018 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please share your complete hello world project

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problems using AbstractLanguageServerTest [message #1791905 is a reply to message #1791903] Fri, 06 July 2018 15:59 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 48
Registered: January 2013
Member
I packed everything as ZIP archive and removed the .gradle folder.
Re: Problems using AbstractLanguageServerTest [message #1791906 is a reply to message #1791905] Fri, 06 July 2018 16:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
you use junit 5 .
abstractlanguageservertest does not support that.
please open a bug at xtext-core

workaround:

class AbstractScreenServiceLSPTest extends AbstractLanguageServerTest {
	
	new() {
		super('screenservice')
	}
	
	@Before @BeforeEach
	override void setup() {
		super.setup()
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Inheritance from non-grammar java class
Next Topic:Formatting Scientific Notation
Goto Forum:
  


Current Time: Fri Apr 19 05:43:49 GMT 2024

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

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

Back to the top