Clean up if a test run is curtailed. (Fixes #1)

This can happen if a debugger is closed, for example.