Setting SDK for ParsingTestCase


I need to set the SDK (and be able to retrieve it in my parser) during tests derived from com.intellij.testFramework.ParsingTestCase, so I can check the SDK version and emulate the Elixir version behavior accordingly.  (Specifcally, this change  When I used the recommended ( code to retrieve or set the SDK: `ProjectRootManager.getInstance(project)` I get that the  ProjectRootManage is null from inside the PsiElement methods called during the tests.  How do I setup the ProjectRootManager so it is available in a ParsingTestCase?

Official comment

Hi Luke,

Take a look at ParsingTestCase#setUp method, it registers a lot of services and extensions, you just do the same for all services your parser requires.

Also, you can always use LightFixturePlatformTestCase for parsing test, it registers all serves and components. It's slower though

I debugged further the tests and it looks like the PorjectRootManager is null because 

ProjectRootManager service = ServiceManager.getService(project, ProjectRootManager.class);

is null, so now my question becomes, how do I get the ServiceManager to return a ProjectRootManager?


Please sign in to leave a comment.