Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to catch abnormal system exits #24

Open
dasteg opened this issue Sep 9, 2021 · 1 comment
Open

Allow to catch abnormal system exits #24

dasteg opened this issue Sep 9, 2021 · 1 comment

Comments

@dasteg
Copy link

dasteg commented Sep 9, 2021

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 ?

@stefanbirkner
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants