@@ -198,7 +198,7 @@ fn prepare_for_2018() {
198
198
}
199
199
200
200
#[ cargo_test]
201
- fn fix_tests ( ) {
201
+ fn do_not_fix_tests ( ) {
202
202
let p = project ( )
203
203
. file (
204
204
"src/lib.rs" ,
@@ -220,21 +220,108 @@ fn fix_tests() {
220
220
p. cargo ( "fix --allow-no-vcs" )
221
221
. with_stderr_data ( str![ [ r#"
222
222
[CHECKING] foo v0.0.1 ([ROOT]/foo)
223
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
224
+
225
+ "# ] ] )
226
+ . with_stdout_data ( "" )
227
+ . run ( ) ;
228
+ }
229
+
230
+ #[ cargo_test]
231
+ fn fix_tests_with_edition ( ) {
232
+ let p = project ( )
233
+ . file (
234
+ "Cargo.toml" ,
235
+ r#"
236
+ [package]
237
+ name = "foo"
238
+ version = "0.1.0"
239
+ edition = "2018"
240
+ "# ,
241
+ )
242
+ . file (
243
+ "src/lib.rs" ,
244
+ r#"
245
+ #![allow(ellipsis_inclusive_range_patterns)]
246
+ pub fn foo() {}
247
+
248
+ #[cfg(test)]
249
+ mod tests {
250
+ #[test]
251
+ fn it_works() {
252
+ f();
253
+ }
254
+ fn f() -> bool {
255
+ let x = 123;
256
+ match x {
257
+ 0...100 => true,
258
+ _ => false,
259
+ }
260
+ }
261
+ }
262
+ "# ,
263
+ )
264
+ . build ( ) ;
265
+
266
+ p. cargo ( "fix --edition --allow-no-vcs" )
267
+ . with_stderr_data ( str![ [ r#"
268
+ [MIGRATING] Cargo.toml from 2018 edition to 2021
269
+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
270
+ [MIGRATING] src/lib.rs from 2018 edition to 2021
223
271
[FIXED] src/lib.rs (1 fix)
224
- [WARNING] path statement with no effect
225
- --> src/lib.rs:9:25
226
- |
227
- 9 | x;
228
- | ^^
229
- |
230
- = [NOTE] `#[warn(path_statements)]` on by default
272
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
273
+
274
+ "# ] ] )
275
+ . with_stdout_data ( "" )
276
+ . run ( ) ;
277
+ // Check that the test is fixed.
278
+ assert ! ( p. read_file( "src/lib.rs" ) . contains( r#"0..=100 => true,"# ) ) ;
279
+ }
280
+
281
+ #[ cargo_test]
282
+ fn fix_tests_with_edition_idioms ( ) {
283
+ let p = project ( )
284
+ . file (
285
+ "Cargo.toml" ,
286
+ r#"
287
+ [package]
288
+ name = 'foo'
289
+ version = '0.1.0'
290
+ edition = '2018'
291
+ "# ,
292
+ )
293
+ . file (
294
+ "src/lib.rs" ,
295
+ r#"
296
+ pub fn foo() {}
297
+
298
+ #[cfg(test)]
299
+ mod tests {
300
+ #[test]
301
+ fn it_works() {
302
+ f();
303
+ }
304
+
305
+ use std::any::Any;
306
+ pub fn f() {
307
+ let _x: Box<Any> = Box::new(3);
308
+ }
309
+ }
310
+ "# ,
311
+ )
312
+ . build ( ) ;
231
313
232
- [WARNING] `foo` (lib test) generated 1 warning
314
+ p. cargo ( "fix --edition-idioms --allow-no-vcs" )
315
+ . with_stderr_data ( str![ [ r#"
316
+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
317
+ [FIXED] src/lib.rs (1 fix)
233
318
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
234
319
235
320
"# ] ] )
236
321
. with_stdout_data ( "" )
237
322
. run ( ) ;
323
+ // Check that the test is fixed.
324
+ assert ! ( p. read_file( "src/lib.rs" ) . contains( "Box<dyn Any>" ) ) ;
238
325
}
239
326
240
327
#[ cargo_test]
@@ -747,19 +834,6 @@ fn does_not_warn_about_dirty_ignored_files() {
747
834
p. cargo ( "fix" ) . run ( ) ;
748
835
}
749
836
750
- #[ cargo_test]
751
- fn fix_all_targets_by_default ( ) {
752
- let p = project ( )
753
- . file ( "src/lib.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
754
- . file ( "tests/foo.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
755
- . build ( ) ;
756
- p. cargo ( "fix --allow-no-vcs" )
757
- . env ( "__CARGO_FIX_YOLO" , "1" )
758
- . run ( ) ;
759
- assert ! ( !p. read_file( "src/lib.rs" ) . contains( "let mut x" ) ) ;
760
- assert ! ( !p. read_file( "tests/foo.rs" ) . contains( "let mut x" ) ) ;
761
- }
762
-
763
837
#[ cargo_test]
764
838
fn prepare_for_unstable ( ) {
765
839
// During the period where a new edition is coming up, but not yet stable,
@@ -1367,7 +1441,7 @@ fn fix_to_broken_code() {
1367
1441
p. cargo ( "build" ) . cwd ( "foo" ) . run ( ) ;
1368
1442
1369
1443
// Attempt to fix code, but our shim will always fail the second compile
1370
- p. cargo ( "fix --allow-no-vcs --broken-code" )
1444
+ p. cargo ( "fix --all-targets -- allow-no-vcs --broken-code" )
1371
1445
. cwd ( "bar" )
1372
1446
. env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
1373
1447
. with_status ( 101 )
0 commit comments