@@ -5,10 +5,7 @@ mod visitor;
5
5
// Generate mutants then run tests (reuse the whole unit test flow for now, including compilation to
6
6
// select mutants) Use Solar:
7
7
use solar_parse:: {
8
- ast:: {
9
- interface:: { source_map:: FileName , Session } ,
10
- ContractKind , ItemKind ,
11
- } ,
8
+ ast:: interface:: { source_map:: FileName , Session } ,
12
9
Parser ,
13
10
} ;
14
11
use std:: sync:: Arc ;
@@ -35,8 +32,8 @@ impl MutationHandler {
35
32
pub fn new (
36
33
contract_to_mutate : PathBuf ,
37
34
config : Arc < foundry_config:: Config > ,
38
- ) -> MutationHandler {
39
- MutationHandler {
35
+ ) -> Self {
36
+ Self {
40
37
contract_to_mutate,
41
38
src : Arc :: default ( ) ,
42
39
mutations : vec ! [ ] ,
@@ -109,7 +106,7 @@ impl MutationHandler {
109
106
let src_path = & self . contract_to_mutate ;
110
107
111
108
self . mutations . iter ( ) . for_each ( |mutant| {
112
- self . generate_mutant ( & mutant, src_path) ;
109
+ self . generate_mutant ( mutant, src_path) ;
113
110
} ) ;
114
111
115
112
self . mutations
@@ -125,7 +122,7 @@ impl MutationHandler {
125
122
}
126
123
127
124
/// Copy the src, cache, out and test folders to one of the mutant temp folder
128
- fn copy_origin ( path : & PathBuf , src_contract_path : & PathBuf , config : Arc < Config > ) {
125
+ fn copy_origin ( path : & Path , src_contract_path : & Path , config : Arc < Config > ) {
129
126
let cache_src = & config. cache_path ;
130
127
let out_src = & config. out ;
131
128
let contract_src = & config. src ;
@@ -141,13 +138,13 @@ impl MutationHandler {
141
138
std:: fs:: create_dir_all ( & contract_dest) . expect ( "Failed to create temp src directory" ) ;
142
139
std:: fs:: create_dir_all ( & test_dest) . expect ( "Failed to create temp src directory" ) ;
143
140
144
- Self :: copy_dir_except ( & cache_src, & cache_dest, src_contract_path)
141
+ Self :: copy_dir_except ( cache_src, cache_dest, src_contract_path)
145
142
. expect ( "Failed to copy in temp cache" ) ;
146
- Self :: copy_dir_except ( & out_src, & out_dest, src_contract_path)
143
+ Self :: copy_dir_except ( out_src, out_dest, src_contract_path)
147
144
. expect ( "Failed to copy in temp out directory" ) ;
148
- Self :: copy_dir_except ( & contract_src, & contract_dest, src_contract_path)
145
+ Self :: copy_dir_except ( contract_src, contract_dest, src_contract_path)
149
146
. expect ( "Failed to copy in temp src directory" ) ;
150
- Self :: copy_dir_except ( & test_src, & test_dest, src_contract_path)
147
+ Self :: copy_dir_except ( test_src, test_dest, src_contract_path)
151
148
. expect ( "Failed to copy in temp src directory" ) ;
152
149
}
153
150
@@ -156,7 +153,7 @@ impl MutationHandler {
156
153
fn copy_dir_except (
157
154
src : impl AsRef < Path > ,
158
155
dst : impl AsRef < Path > ,
159
- except : & PathBuf ,
156
+ except : & Path ,
160
157
) -> std:: io:: Result < ( ) > {
161
158
std:: fs:: create_dir_all ( & dst) ?;
162
159
@@ -166,24 +163,22 @@ impl MutationHandler {
166
163
167
164
if ty. is_dir ( ) {
168
165
Self :: copy_dir_except (
169
- & entry. path ( ) ,
170
- & dst. as_ref ( ) . join ( entry. file_name ( ) ) ,
166
+ entry. path ( ) ,
167
+ dst. as_ref ( ) . join ( entry. file_name ( ) ) ,
171
168
except,
172
169
) ?;
173
- } else {
174
- if entry. file_name ( ) != except. file_name ( ) . unwrap_or_default ( ) {
170
+ } else if entry. file_name ( ) != except. file_name ( ) . unwrap_or_default ( ) {
175
171
// std::os::unix::fs::symlink(entry.path(),
176
172
// &dst.as_ref().join(entry.file_name()))?; // and for windows, would be
177
173
// std::os::windows::fs::symlink_file
178
- std:: fs:: copy ( entry. path ( ) , & dst. as_ref ( ) . join ( entry. file_name ( ) ) ) ?;
179
- }
174
+ std:: fs:: copy ( entry. path ( ) , dst. as_ref ( ) . join ( entry. file_name ( ) ) ) ?;
180
175
}
181
176
}
182
177
Ok ( ( ) )
183
178
}
184
179
185
180
/// Based on a given mutation, emit the corresponding mutated solidity code and write it to disk
186
- fn generate_mutant ( & self , mutation : & Mutant , src_contract_path : & PathBuf ) {
181
+ fn generate_mutant ( & self , mutation : & Mutant , src_contract_path : & Path ) {
187
182
let temp_dir_path = & mutation. path ;
188
183
189
184
let span = mutation. span ;
@@ -214,7 +209,7 @@ impl MutationHandler {
214
209
dbg ! ( & new_content) ;
215
210
216
211
std:: fs:: write ( & target_path, new_content)
217
- . expect ( & format ! ( "Failed to write to target file {:?}" , & target_path) ) ;
212
+ . unwrap_or_else ( |_| panic ! ( "Failed to write to target file {:?}" , & target_path) ) ;
218
213
}
219
214
220
215
/// Compile a directory and get the compilation output
0 commit comments