Setting SDK for ParsingTestCase

Answered

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 https://github.com/elixir-lang/elixir/pull/4582.)  When I used the recommended (http://www.jetbrains.org/intellij/sdk/docs/reference_guide/project_model/sdk.html) 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?

2 comments
Comment actions Permalink
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

Comment actions Permalink

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?

0

Please sign in to leave a comment.