How to reset language reference and usage tests.

I have some Unit Tests which I wrote following the instructions at https://www.jetbrains.org/intellij/sdk/docs/tutorials/writing_tests_for_plugins.html

They all work when run individually but if I run them with "run -> all tests" from the IDE or in a gradle build, they fail, because it looks to me if some context has not been cleared. I suspect this is something to do with my ParserDefinition. In the parser tests the ParsingTest case always creates a new ParserDefinition, but I haven't seen how to do this in the Reference or Usage tests, which I am executing using 

LightPlatformCodeInsightFixtureTestCase

When debugging I do see different ParserDefinition objects (references are different), but there must be some static stuff which I am not clearing (properly).

0
正式评论

Please add a trace how tests fail otherwise it's absolutely not clear what can be wrong.

Thanks,

Anna

Avatar
Permanently deleted user

What sort of trace? The tests don't fail with an exception.

I've investigated further and the tests which are derived from 

LightPlatformCodeInsightFixtureTestCase

All use the same ParserDefinition, which seems to be a singleton in the context of the fixture factory. The parser tests derived from ParserTestCase use a different method way of constructing the ParserDefinition.

If I run the ParserTestCases as part of my build, none of the tests derived from 

LightPlatformCodeInsightFixtureTestCase

Work, if I skip the parser tests all these tests succeed.

Is there a way to run the parser tests so they use 

LightPlatformCodeInsightFixtureTestCase
0

Still I don't understand how your parser tests fail. But `ParserDefinition`s are extensions and must be stateless thus there must be no side effects in tests because of them

0
Avatar
Permanently deleted user

So I found the issue. It's because the language is a singleton (I'm following instructions from here https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/language_and_filetype.html).

ParsingTestCase

sets the ASTFactory of the language to the Default.

This means that when

LightPlatformCodeInsightFixtureTestCase

tries to set set the ASTFactory to my custom ASTFactory implementation (as specified in my plugin.xml) using

Language.putUserDataIfAbsent

Then it can't because it is already there with the Default. This doesn't happen for any of the other custom things, as they have not been set. I'll try work around this by explicitly setting the ASTFactory to my custom class in the tests

0
Avatar
Permanently deleted user
class ParsingTest : ParsingTestCase("parsing", "sample", pd) {

override fun setUp() {
super.setUp()
LanguageASTFactory.INSTANCE.addExplicitExtension(Sample.INSTANCE,SampleASTFactory())
}

fun testSimple() {
doTest(true)
}

override fun getTestDataPath() = "src/test/resources"

companion object {
val pd = ParserDefinition()
}
}
0

请先登录再写评论。