helper: stub helper for tests

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-09-29 14:40:01 +09:00
parent 0e7849fac2
commit d530a9e9f9
3 changed files with 108 additions and 2 deletions

18
helper/export_test.go Normal file
View File

@@ -0,0 +1,18 @@
package helper
import (
"os"
"os/exec"
"testing"
)
// replace execCommand to have the resulting *exec.Cmd launch TestHelperChildStub
func ReplaceExecCommand(t *testing.T) {
t.Cleanup(func() {
execCommand = exec.Command
})
execCommand = func(name string, arg ...string) *exec.Cmd {
return exec.Command(os.Args[0], append([]string{"-test.run=TestHelperChildStub", "--", name}, arg...)...)
}
}