How to write test which invokes compilation?

I wrote a custom Compiler and I want to write a test that proves that my compiler is called and produces the correct output, when the user clicks Make or Compile or Rebuild.

I'm using CompilerManager.compile, but it looks like compilation does not start until some runnables are run on the event queue thread, which is the same thread that the test is running in. So, there's no way to get compilation to finish while the test is still running.

JetBrains guys, how do you test this code? Is there some trick or secret flag?

Has anyone else found a way to get this working?