Skip to content

Refactor tests #1982

@Mikadore

Description

@Mikadore

We want the CmdResult struct to hold Vec<u8>s instead of Strings so that we can run tests with non-utf8 output,
#1977 Defined a public API, but unfortunately, many tests still access fields of CmdResult directly.

E.g.

fn test_multiple_formats() {
    let input = "abcdefghijklmnopqrstuvwxyz\n";
    let result = new_ucmd!()
        .arg("-c")
        .arg("-b")
        .run_piped_stdin(input.as_bytes());

    assert_empty_stderr!(result);
    assert!(result.success);
    assert_eq!(
        result.stdout,
        unindent(
            "
            0000000   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p
                    141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160
            0000020   q   r   s   t   u   v   w   x   y   z  \\n
                    161 162 163 164 165 166 167 170 171 172 012
            0000033
            "
        )
    );
}

Is to be re-written as

fn test_multiple_formats() {
    let input = "abcdefghijklmnopqrstuvwxyz\n";
    new_ucmd!()
        .arg("-c")
        .arg("-b")
        .run_piped_stdin(input.as_bytes())
        .success()
        .no_stderr()
        .stdout_is(unindent(
            "
            0000000   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o   p
                    141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160
            0000020   q   r   s   t   u   v   w   x   y   z  \\n
                    161 162 163 164 165 166 167 170 171 172 012
            0000033
            "
        ));
}

I'll start work on od & ls for now. If you're interested in doing some, please comment so we don't do the same work twice!
It's not very hard; some tips:

  • use the find/replace functionality of your IDE (or sed even)
  • take a look at tests/common/util.rs to see all the functions a CmdResult has
  • you can locally make these fields private (but please don't commit this!) and fix the resulting errors
    Lastly, please make sure you're not changing the tests' functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions