Testcases

Here's a pile of commits that implements test cases for testing the various checks. I hope you don't think this is going to be a long term maintenance headache...

There are a couple of minor interdependencies with the other pull request, but I can fix them later, depending on what you want to merge.