Supplying Command Input from a Test Runner
A test can launch a real command with controlled input bytes, working directory, environment, and arguments.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Choose a format-sensitive fixture
Send a short report containing an accented label and a final line without a terminator. Verify the output and error stream. Encoding round trips and end-of-file handling describe the observed rules.
Keep the run independent
Use a fresh temporary location rather than a file left by an earlier test. Track which environment settings are required for reproduction. Independent fixtures define that starting state.[1]
Deliver identical input bytes and close the input stream
A command summing one integer per line can receive "5\n9\n" through a captured child process. Closing its input lets a reader waiting for end-of-file finish. The test should observe output fourteen and final success under that contract. See standard input.
Pass encoded bytes 35 0A 39 0A
Close input
Wait while collecting output
Check stdout represents 14 and exit status indicates success
Exercise malformed input without assigning it to a shell string
Use the process runner's input APIs so quoting does not modify fixture bytes. Apply a timeout and capture stderr independently. Include a blank line and an invalid number where they matter.