selftest.run: Factor out expand_command_run.