Which still has a crash, but only at the very end after executing everything.

I've fixed both issues with:

commit 8f9f8d1c4452f8d9291ae530f3720511fd203aef
Author: Milian Wolff <mail@milianw.de>
Date: Sun Oct 21 20:12:37 2018 +0200
Fix crashes when document gets destroyed directly after load
This fixes the clang code completion unit test, which used to
crash on exit since the event loop wasn't run between loading
a document and destroying it again.
To guard against this, we need to jump through a QPointer hoop,
which requires some lambda boiler plate but otherwise isn't too bad.

This should work for all unit tests and doesn't require such a hackish disconnect.