Port test command to core

This is ugly, but working. I want to clean it before merging, but I'm not sure how to get rid of the case analysis.