Files
llgo/compiler/internal/mockable/mockable.go
2025-02-01 14:11:45 +08:00

30 lines
408 B
Go

package mockable
import (
"os"
)
var (
exitFunc = os.Exit
exitCode int
)
// EnableMock enables mocking of os.Exit
func EnableMock() {
exitCode = 0
exitFunc = func(code int) {
exitCode = code
panic("exit")
}
}
// Exit calls the current exit function
func Exit(code int) {
exitFunc(code)
}
// ExitCode returns the last exit code from a mocked Exit call
func ExitCode() int {
return exitCode
}