Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testutil: support empty string args in fakecommand #244

Merged
merged 1 commit into from
Aug 1, 2023

Commits on Jun 22, 2023

  1. 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)
    flotter committed Jun 22, 2023
    Configuration menu
    Copy the full SHA
    641012b View commit details
    Browse the repository at this point in the history