Build tests with cmake, and run them in their own tmp dirs.

More prep for #219.