@@ -115,6 +115,8 @@ pub struct Config {
115115pub struct Assert {
116116 pub output : SanitizedOutput ,
117117 redactions : Redactions ,
118+ sort_stdout : bool ,
119+ sort_stderr : bool ,
118120}
119121
120122impl Assert {
@@ -133,7 +135,12 @@ impl Assert {
133135 ( "[MULTI_ARCH_I]" , Cow :: Borrowed ( MULTI_ARCH1 ) ) ,
134136 ] )
135137 . expect ( "invalid redactions detected" ) ;
136- Self { output, redactions }
138+ Self {
139+ output,
140+ redactions,
141+ sort_stdout : false ,
142+ sort_stderr : false ,
143+ }
137144 }
138145
139146 /// Extends the redaction rules used in the current assertion with new values.
@@ -157,6 +164,18 @@ impl Assert {
157164 self
158165 }
159166
167+ /// Sort stdout lines to gloss over platform-specific sort orders
168+ pub fn sort_stdout ( & mut self , yes : bool ) -> & mut Self {
169+ self . sort_stdout = yes;
170+ self
171+ }
172+
173+ /// Sort stderr lines to gloss over platform-specific sort orders
174+ pub fn sort_stderr ( & mut self , yes : bool ) -> & mut Self {
175+ self . sort_stderr = yes;
176+ self
177+ }
178+
160179 /// Performs the redaction based on the existing rules.
161180 pub fn redact ( & self , input : & str ) -> String {
162181 self . redactions . redact ( input)
@@ -176,7 +195,12 @@ impl Assert {
176195
177196 /// Asserts that the command exited with the given `expected` stdout pattern.
178197 pub fn with_stdout ( & self , expected : impl IntoData ) -> & Self {
179- let stdout = self . redact ( & self . output . stdout ) ;
198+ let mut stdout = self . redact ( & self . output . stdout ) ;
199+ if self . sort_stdout {
200+ let mut lines = stdout. lines ( ) . collect :: < Vec < _ > > ( ) ;
201+ lines. sort ( ) ;
202+ stdout = lines. join ( "\n " ) ;
203+ }
180204 assert_data_eq ! ( & stdout, expected) ;
181205 self
182206 }
@@ -192,7 +216,12 @@ impl Assert {
192216
193217 /// Asserts that the command exited with the given `expected` stderr pattern.
194218 pub fn with_stderr ( & self , expected : impl IntoData ) -> & Self {
195- let stderr = self . redact ( & self . output . stderr ) ;
219+ let mut stderr = self . redact ( & self . output . stderr ) ;
220+ if self . sort_stderr {
221+ let mut lines = stderr. lines ( ) . collect :: < Vec < _ > > ( ) ;
222+ lines. sort ( ) ;
223+ stderr = lines. join ( "\n " ) ;
224+ }
196225 assert_data_eq ! ( & stderr, expected) ;
197226 self
198227 }
0 commit comments