@@ -249,6 +249,7 @@ impl Module {
249
249
config : & Config ,
250
250
emission_location : & Location ,
251
251
top_level_prefix : impl fmt:: Display ,
252
+ emit_tests : bool ,
252
253
) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync + ' static > > {
253
254
if self . submodules . is_empty ( ) && !emission_location. is_top_level ( ) {
254
255
// Only output a single file
@@ -257,14 +258,18 @@ impl Module {
257
258
self . contents ( config, emission_location, top_level_prefix)
258
259
. to_string ( ) ,
259
260
) ?;
260
- fs:: write (
261
- test_path. with_extension ( "rs" ) ,
262
- self . tests ( config) . to_string ( ) ,
263
- ) ?;
261
+ if emit_tests {
262
+ fs:: write (
263
+ test_path. with_extension ( "rs" ) ,
264
+ self . tests ( config) . to_string ( ) ,
265
+ ) ?;
266
+ }
264
267
} else {
265
268
// Output an entire module
266
269
fs:: create_dir_all ( path) ?;
267
- fs:: create_dir_all ( test_path) ?;
270
+ if emit_tests {
271
+ fs:: create_dir_all ( test_path) ?;
272
+ }
268
273
269
274
// TODO: Fix this
270
275
let mut expected_files: Vec < OsString > = vec ! [ ] ;
@@ -278,6 +283,7 @@ impl Module {
278
283
config,
279
284
& emission_location. add_module ( & name) ,
280
285
"//! This file has been automatically generated by `objc2`'s `header-translator`.\n //! DO NOT EDIT\n " ,
286
+ emit_tests,
281
287
) ?;
282
288
if module. submodules . is_empty ( ) {
283
289
expected_files. push ( format ! ( "{name}.rs" ) . into ( ) ) ;
@@ -291,24 +297,28 @@ impl Module {
291
297
self . contents ( config, emission_location, top_level_prefix)
292
298
. to_string ( ) ,
293
299
) ?;
294
- fs:: write ( test_path. join ( "mod.rs" ) , self . tests ( config) . to_string ( ) ) ?;
300
+ if emit_tests {
301
+ fs:: write ( test_path. join ( "mod.rs" ) , self . tests ( config) . to_string ( ) ) ?;
302
+ }
295
303
expected_files. push ( "mod.rs" . into ( ) ) ;
296
304
297
305
// Remove previously generated files
298
- for file in path. read_dir ( ) ?. chain ( test_path. read_dir ( ) ?) {
299
- let file = file?;
300
- if expected_files. contains ( & file. file_name ( ) ) {
301
- continue ;
302
- }
303
- error ! ( "removing previous file {:?}" , file. path( ) ) ;
304
- if file. path ( ) . is_dir ( ) {
305
- fs:: remove_dir_all ( file. path ( ) ) ?;
306
- } else {
307
- fs:: remove_file ( file. path ( ) ) ?;
306
+ if let Ok ( test_dir) = test_path. read_dir ( ) {
307
+ for file in path. read_dir ( ) ?. chain ( test_dir) {
308
+ let file = file?;
309
+ if expected_files. contains ( & file. file_name ( ) ) {
310
+ continue ;
311
+ }
312
+ error ! ( "removing previous file {:?}" , file. path( ) ) ;
313
+ if file. path ( ) . is_dir ( ) {
314
+ fs:: remove_dir_all ( file. path ( ) ) ?;
315
+ } else {
316
+ fs:: remove_file ( file. path ( ) ) ?;
317
+ }
308
318
}
309
319
}
310
320
311
- if emission_location. is_top_level ( ) {
321
+ if emission_location. is_top_level ( ) && emit_tests {
312
322
let data = config. library ( emission_location) ;
313
323
let mut s = String :: new ( ) ;
314
324
writeln ! ( & mut s, "#![cfg(feature = \" test-frameworks\" )]" ) ?;
0 commit comments