Remove at_exit and favour inline exiting

The at_exit was causing the return status of the task to be zero. Moving
it inline means the correct exit code gets returned and the tests
correctly fail if there is a failure.