Skip to content

Conversation

@Mikadore
Copy link
Contributor

This PR adds a bunch of useful functions & byte/string getters for the CmdResult struct.
It also adds methods to rw+ items in an AtPath.

Now, we need to refactor tests to use this API (together with stdout_is for example instead of manual asserts, and succeeds instead of assert!(result.success). Once that is done, we can

  1. Change the type of stderr/stdout in CmdResult to Vec<u8>
  2. Make the fields private (to avoid this whole mess in the future)
  3. Finally be able to test our utils for non-utf8 reliance! Will close Tests: Replace String with Vec<u8> for stdout (stderr?) #1916

@Mikadore
Copy link
Contributor Author

The checks failing here are actually an apparent bug in the tests.
Due to #1970, the contents of UTF_8_tests.txt read are an empty string.

@Mikadore
Copy link
Contributor Author

Mikadore commented Mar 31, 2021

Manually invoking wc also confirms this

./target/debug/coreutils wc -lwmcL ./tests/fixtures/wc/UTF_8_test.txt
   300  4969 22781 22213    79 ./tests/fixtures/wc/UTF_8_test.txt

Copy link
Collaborator

@Arcterus Arcterus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the typo. The other comment is more of a suggestion.

self.code.expect("Program must be run first")
}

/// Retunrs the program's TempDir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns

/// whose bytes equal those of the passed in slice
pub fn stderr_is_bytes<T: AsRef<[u8]>>(&self, msg: T) -> Box<&CmdResult> {
assert_eq!(self.stderr.as_bytes(), msg.as_ref());
Box::new(self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to remove the Boxes? I think they must be a remnant of a change from long ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing

@Mikadore
Copy link
Contributor Author

@Arcterus should I also remove the Boxes in UCommand? Same case as with CmdResult, i.e. totally unnecessary

@Arcterus
Copy link
Collaborator

Yeah, please do.

pub stdout: String,
/// captured utf-8 standard error after running the Command
/// captured standard error after running the Command
pub stderr: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be stored as Vec<u8>? Same for stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be stored as Vec<u8>? Same for stdout.

That's the big problem. A lot of tests depend on the fields of CmdResult.
Changing this right now would break the whole build. So, as mentioned in the original PR comment,
for now, we just add a bunch of public methods.
After we have refactored the tests to only use these functions, we can make the fields private and change the type.

The refactor shouldn't take more than 1-2 days.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I somehow missed your steps in the original comment. I suppose that's fine then.

@Arcterus Arcterus merged commit a57f17a into uutils:master Mar 31, 2021
@Mikadore Mikadore mentioned this pull request Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: Replace String with Vec<u8> for stdout (stderr?)

2 participants