Parser testing
Hello! I try to use hend written lexer and parser for idea https://github.com/brizjin/simple_language_plugin
And some simple lang now succusfully working. Then I try write Tests for it. In Idea tutorial says I should use ParsingTestCase class which needs all test data be saved on disk before test. And when i run test it get an exception:
ERROR: Language Language: Simple doesn't participate in view provider SingleRootFileViewProvider{myVirtualFile=LightVirtualFile: \ParsingTestData.simple, content=VirtualFileContent{size=433}}: [Language: ANY]
It seems like i have to install my plugin before testing. But tests runnig in current IDEA not in IDEA which starts for debugging. If i will install it by press Idea suggesion will I need update after rebuilding Parser or Lexer? And how I can install it manualy, not by suggestion link? And update after rebuild, and should I?
May be there is way how to write own test without using ParsingTestCase. Where Parser will get Lexer and Text from string and then compare results, for example Element by Element. Or always should i create this Idea object like happen in ParsingTestCase, and where can i find examples about how should i write it?
Thank you!
Please sign in to leave a comment.
You should pass your ParserDefition to the constructor of ParsingTestCase. You can also try debugging around ParsingTestCase#createFile and see at which moment Language.ANY is used instead of yours (possibly it's inside SingleRootFileViewProvider#calcBaseLanguage, but the reasons might be very different). Does this help?
You could try testing without ParsingTestCase, but it's difficult because a lot of stuff needs to be set up for parser to be able to work.
Thank you for answer. Yes it helps. But why tutorial example do not work i still do not reilese.
Some why this defination not working, but in all tutorials and other plugin example it is:
But this change make test work:
I can only guess. It might be that SimpleLanguage isn't registered yet when you invoke findInstance due to some JVM class initialization peculiarities.
Yes, it looks like it not registered. But for example in LexerTestCase it registered, and test works good. And in other plugins which I look, there is no spececial registration for plugin, everithing work out of box. When and where it should register, and why it not at ParsingTestCase?
A language is registered when its constructor is called. You can try to debug and see which happens first: your Language class constructor or findInstance.