[RFC] refactor includes + improve testing infrastructure

This will allows testing of more files and allow PR #904 to proceed.

Implements a tiny part of issue #918 in the process as well.
Yes, it could. A quick grep through the codebase doesn't show me any obvious store-a-pointer-in-an-integral-type cases though. (and if there would be, we should change that to `intptr_t` stat). Perhaps Bram meant something else...