factor out test detection and avoid over-zaelous cleanup