@@ -89,9 +89,7 @@ pub trait Mutator {
8989 fn mutate < ' a > (
9090 self ,
9191 config : & ' a mut WasmMutate ,
92- ) -> Result < Box < dyn Iterator < Item = Result < Module > > + ' a > >
93- where
94- Self : Copy ;
92+ ) -> Result < Box < dyn Iterator < Item = Result < Module > > + ' a > > ;
9593
9694 /// What is this mutator's name?
9795 ///
@@ -107,7 +105,7 @@ pub type OperatorAndByteOffset<'a> = (Operator<'a>, usize);
107105#[ cfg( test) ]
108106fn match_mutation < T > ( original : & str , mutator : T , expected : & str )
109107where
110- T : Mutator + Copy ,
108+ T : Mutator + Clone ,
111109{
112110 WasmMutate :: default ( ) . match_mutation ( original, mutator, expected)
113111}
@@ -116,11 +114,13 @@ impl WasmMutate<'_> {
116114 #[ cfg( test) ]
117115 fn match_mutation < T > ( & mut self , original : & str , mutator : T , expected : & str )
118116 where
119- T : Mutator + Copy ,
117+ T : Mutator + Clone ,
120118 {
121119 use crate :: ErrorKind ;
122120 use wasmparser:: WasmFeatures ;
123121
122+ drop ( env_logger:: try_init ( ) ) ;
123+
124124 let original = & wat:: parse_str ( original) . unwrap ( ) ;
125125
126126 let expected = & wat:: parse_str ( expected) . unwrap ( ) ;
@@ -134,13 +134,16 @@ impl WasmMutate<'_> {
134134 assert ! ( can_mutate) ;
135135
136136 let attempts = 100 ;
137+ let mut last_mutation = None ;
137138
138139 for _ in 0 ..attempts {
139140 let mutation = match mutator
141+ . clone ( )
140142 . mutate ( & mut config)
141- . and_then ( |mut mutation| mutation. next ( ) . unwrap ( ) )
143+ . map ( |mut mutation| mutation. next ( ) )
142144 {
143- Ok ( mutation) => mutation,
145+ Ok ( Some ( mutation) ) => mutation. unwrap ( ) ,
146+ Ok ( None ) => continue ,
144147 Err ( e) if matches ! ( e. kind( ) , ErrorKind :: NoMutationsApplicable ) => continue ,
145148 Err ( e) => panic ! ( "mutation error: {}" , e) ,
146149 } ;
@@ -157,13 +160,27 @@ impl WasmMutate<'_> {
157160 // If it fails, it is probably an invalid
158161 // reformatting expected
159162 let text = wasmprinter:: print_bytes ( mutation_bytes) . unwrap ( ) ;
160- assert_eq ! ( text. trim( ) , expected_text. trim( ) ) ;
161- return ;
163+ if text. trim ( ) == expected_text. trim ( ) {
164+ return ;
165+ }
166+ log:: debug!( "skipping mutation {}" , text) ;
167+ last_mutation = Some ( text) ;
162168 }
163169
164- panic ! (
165- "never found any applicable mutations after {} attempts" ,
166- attempts
167- ) ;
170+ match last_mutation {
171+ Some ( mutation) => {
172+ panic ! (
173+ "after {} attempts the last mutation:\n {:?}\n \n \
174+ did not match the expected mutation\n {:?}",
175+ attempts, mutation, expected_text
176+ ) ;
177+ }
178+ None => {
179+ panic ! (
180+ "never found any applicable mutations after {} attempts" ,
181+ attempts
182+ ) ;
183+ }
184+ }
168185 }
169186}
0 commit comments