Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testutil: support empty string args in fakecommand
FakeCommand allows unit tests to check which command-line arguments were passed, by recording a log of calls with their arguments. The following examples cannot be tested with FakeCommand: 1. shutdown -r "+0" "" 2. echo "" 3. configure --program-prefix "" The empty string argument confuses the command parser in testutil. The issue is that both the argument (\000) and command delimiter (\000\000) uses null characters, which makes the command split operation split on the first occurrence of two null chars. This is an invalid assumption for an empty string argument, which will be presented as two argument delimiters, without anything in between, appearing like a command delimiter. To add support for this: - Change the command delimiter from \000\000 => \000\f\n\r (magic sequence) - Update the Calls() function to split the lines correctly. Testutil can now be used for testing the following command, including the case where msg is an empty string for the wall message: shutdown [OPTIONS...] [TIME] [WALL...] cmd := exec.Command("shutdown", "-r", fmt.Sprintf("+%d", mins), msg)
- Loading branch information