From 06cd391845c0039dc70bd8dd972bdaf36b454872 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Fri, 7 Jan 2022 03:08:22 -0700 Subject: [PATCH] Change test_opposing to be less flaky. Make it resilient to the different invocations returning results in different orders. --- tests/testenv/mod.rs | 21 ++++++++++++++------- tests/tests.rs | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/testenv/mod.rs b/tests/testenv/mod.rs index cc439bc..510a7b2 100644 --- a/tests/testenv/mod.rs +++ b/tests/testenv/mod.rs @@ -203,6 +203,19 @@ impl TestEnv { output } + pub fn assert_success_and_get_normalized_output>( + &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. pub fn assert_output(&self, args: &[&str], expected: &str) { self.assert_output_subdirectory(".", args, expected) @@ -224,15 +237,9 @@ impl TestEnv { args: &[&str], expected: &str, ) { - let output = self.assert_success_and_get_output(path, args); - // Normalize both expected and actual output. let expected = normalize_output(expected, true, self.normalize_line); - let actual = normalize_output( - &String::from_utf8_lossy(&output.stdout), - false, - self.normalize_line, - ); + let actual = self.assert_success_and_get_normalized_output(path, args); // Compare actual output to expected output. if expected != actual { diff --git a/tests/tests.rs b/tests/tests.rs index e6cee6c..fb0535c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1970,8 +1970,8 @@ fn test_opposing(flag: &str, opposing_flags: &[&str]) { let mut flags = vec![flag]; flags.extend_from_slice(opposing_flags); - let out_no_flags = te.assert_success_and_get_output(".", &[]); - let out_opposing_flags = te.assert_success_and_get_output(".", &flags); + let out_no_flags = te.assert_success_and_get_normalized_output(".", &[]); + let out_opposing_flags = te.assert_success_and_get_normalized_output(".", &flags); assert_eq!( out_no_flags,