Documentation ¶
Overview ¶
Package osexit mocks the os.Exit function.
To use, first set a package-specific exit function, e.g.
var exit = os.Exit
Then use it instead of a direct call to os.Exit, e.g.
if somethingFatal { exit(1) return }
Make sure to return immediately after the call to exit, so that testing code will match real code as closely as possible.
You can now use the utility functions provided by this package to override exit for testing purposes, e.g.
exit = osexit.Set() invokeCodeCallingExit() if !osexit.Called() { t.Fatalf("os.Exit was not called as expected") }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Func ¶
func Func(code int)
Func provides a mock for the os.Exit function. Special care must be taken when testing os.Exit to make sure no code runs after the call to Exit. It's recommended to put a return statement after Exit calls so that the behaviour of the mock matches that of the real function as much as possible.
Types ¶
This section is empty.