Skip to content

Document or Fix oddities in the test utilities #1970

@Mikadore

Description

@Mikadore

I'm working on #1916 right now.

I've encountered some oddities with the utilities, for example:

pub fn read_size(child: &mut Child, size: usize) -> String {
    let mut output = Vec::new();
    output.resize(size, 0);
    sleep(Duration::from_secs(1));
    child
        .stdout
        .as_mut()
        .unwrap()
        .read(output.as_mut_slice())
        .unwrap();
    String::from_utf8(output).unwrap()
}

The API of this function implies that size bytes are read from the Child, however .read doesn't make such a guarantee.
This should be documented, or another function such as read_exact should be used to guarantee this property.

In other places errors are simply ignored

 pub fn read(&self, name: &str) -> String {
        let mut f = self.open(name);
        let mut contents = String::new();
        let _ = f.read_to_string(&mut contents);
        contents
    }

This code should crash on error ^, but it just goes on.

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