Factor out cmd testing helpers.