Refactor out some stuff to CMake tests