system-lambda icon indicating copy to clipboard operation
system-lambda copied to clipboard

Allow to catch abnormal system exits

Open dasteg opened this issue 4 years ago • 1 comments
trafficstars

at the moment it is possible to catch System.exit and assert on that. My code (some kind of script) only calls System.exit(1) if anything weird happened but does not call System.exit(0) if everything worked fine.

At the moment i can't test abnormal executions since i always get an AssertionError if no System.exit was called at all. It would be nice to have a method like SystemLambda.catchSystemExitOrDefault(Statement statement, int defaultValue) which returns the defaultValue if no System.exit was called at all. Then i could just assert for exit code 0 which happens normally and still fail if anything else happened.

does this make senses ?

dasteg avatar Sep 09 '21 12:09 dasteg

I would like to better understand your use case. Can you explain me why you use catchSystemExit in tests that are not expected to call System.exit.

A workaround is to call System.exit(0) at the end of the main method.

stefanbirkner avatar Nov 24 '21 18:11 stefanbirkner