diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-09-29 14:40:01 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-09-29 14:40:01 +0900 |
| commit | d530a9e9f9bd85ea18a688d879d0558cd56fb8bd (patch) | |
| tree | ae23026d042642a01cf21b930e64f8545ce1142a /helper/export_test.go | |
| parent | 0e7849fac2fa42bc23dc97e419d8c00b06c8db37 (diff) | |
helper: stub helper for tests
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'helper/export_test.go')
| -rw-r--r-- | helper/export_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/helper/export_test.go b/helper/export_test.go new file mode 100644 index 00000000..6bf18ce3 --- /dev/null +++ b/helper/export_test.go @@ -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...)...) + } +} |
