test: make cmd testable
This commit is contained in:
29
compiler/internal/mockable/mockable.go
Normal file
29
compiler/internal/mockable/mockable.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user