This commit changes the way `os.Stderr` is mocked so that higher level consumes of the libary can use helpers can replace os.Stderr (like `testutil.CaptureStdio()` is doing). The existing approach assigns the "real" os.Stderr to osStderr so early that it cannot be changed later.
35 lines
621 B
Go
35 lines
621 B
Go
package progress
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type (
|
|
TerminalProgressBar = terminalProgressBar
|
|
DebugProgressBar = debugProgressBar
|
|
VerboseProgressBar = verboseProgressBar
|
|
)
|
|
|
|
func MockOsStderr(w io.Writer) (restore func()) {
|
|
saved := osStderr
|
|
osStderr = func() io.Writer { return w }
|
|
return func() {
|
|
osStderr = saved
|
|
}
|
|
}
|
|
|
|
func MockIsattyIsTerminal(fn func(uintptr) bool) (restore func()) {
|
|
saved := isattyIsTerminal
|
|
isattyIsTerminal = fn
|
|
return func() {
|
|
isattyIsTerminal = saved
|
|
}
|
|
}
|
|
|
|
func MockOsbuildCmd(s string) (restore func()) {
|
|
saved := osbuildCmd
|
|
osbuildCmd = s
|
|
return func() {
|
|
osbuildCmd = saved
|
|
}
|
|
}
|