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).
请先登录再写评论。
Please add a trace how tests fail otherwise it's absolutely not clear what can be wrong.
Thanks,
Anna
What sort of trace? The tests don't fail with an exception.
I've investigated further and the tests which are derived from
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
Work, if I skip the parser tests all these tests succeed.
Is there a way to run the parser tests so they use
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
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).
sets the ASTFactory of the language to the Default.
This means that when
tries to set set the ASTFactory to my custom ASTFactory implementation (as specified in my plugin.xml) using
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
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()
}
}