Change test_opposing to be less flaky.

Make it resilient to the different invocations returning results in
different orders.
This commit is contained in:
Thayne McCombs 2022-01-07 03:08:22 -07:00
parent c800c79976
commit 06cd391845
2 changed files with 16 additions and 9 deletions

View file

@ -203,6 +203,19 @@ impl TestEnv {
output output
} }
pub fn assert_success_and_get_normalized_output<P: AsRef<Path>>(
&self,
path: P,
args: &[&str],
) -> String {
let output = self.assert_success_and_get_output(path, args);
normalize_output(
&String::from_utf8_lossy(&output.stdout),
false,
self.normalize_line,
)
}
/// Assert that calling *fd* with the specified arguments produces the expected output. /// Assert that calling *fd* with the specified arguments produces the expected output.
pub fn assert_output(&self, args: &[&str], expected: &str) { pub fn assert_output(&self, args: &[&str], expected: &str) {
self.assert_output_subdirectory(".", args, expected) self.assert_output_subdirectory(".", args, expected)
@ -224,15 +237,9 @@ impl TestEnv {
args: &[&str], args: &[&str],
expected: &str, expected: &str,
) { ) {
let output = self.assert_success_and_get_output(path, args);
// Normalize both expected and actual output. // Normalize both expected and actual output.
let expected = normalize_output(expected, true, self.normalize_line); let expected = normalize_output(expected, true, self.normalize_line);
let actual = normalize_output( let actual = self.assert_success_and_get_normalized_output(path, args);
&String::from_utf8_lossy(&output.stdout),
false,
self.normalize_line,
);
// Compare actual output to expected output. // Compare actual output to expected output.
if expected != actual { if expected != actual {

View file

@ -1970,8 +1970,8 @@ fn test_opposing(flag: &str, opposing_flags: &[&str]) {
let mut flags = vec![flag]; let mut flags = vec![flag];
flags.extend_from_slice(opposing_flags); flags.extend_from_slice(opposing_flags);
let out_no_flags = te.assert_success_and_get_output(".", &[]); let out_no_flags = te.assert_success_and_get_normalized_output(".", &[]);
let out_opposing_flags = te.assert_success_and_get_output(".", &flags); let out_opposing_flags = te.assert_success_and_get_normalized_output(".", &flags);
assert_eq!( assert_eq!(
out_no_flags, out_no_flags,