@@ -197,6 +197,103 @@ fn prepare_for_2018() {
197
197
. contains( "let x = crate::foo::FOO;" ) ) ;
198
198
}
199
199
200
+ #[ cargo_test]
201
+ fn fix_tests_with_edition ( ) {
202
+ let p = project ( )
203
+ . file (
204
+ "Cargo.toml" ,
205
+ r#"
206
+ [package]
207
+ name = "foo"
208
+ version = "0.1.0"
209
+ edition = "2018"
210
+ "# ,
211
+ )
212
+ . file (
213
+ "src/lib.rs" ,
214
+ r#"
215
+ #![allow(ellipsis_inclusive_range_patterns)]
216
+ pub fn foo() {}
217
+
218
+ #[cfg(test)]
219
+ mod tests {
220
+ #[test]
221
+ fn it_works() {
222
+ f();
223
+ }
224
+ fn f() -> bool {
225
+ let x = 123;
226
+ match x {
227
+ 0...100 => true,
228
+ _ => false,
229
+ }
230
+ }
231
+ }
232
+ "# ,
233
+ )
234
+ . build ( ) ;
235
+
236
+ p. cargo ( "fix --edition --allow-no-vcs" )
237
+ . with_stderr_data ( str![ [ r#"
238
+ [MIGRATING] Cargo.toml from 2018 edition to 2021
239
+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
240
+ [MIGRATING] src/lib.rs from 2018 edition to 2021
241
+ [FIXED] src/lib.rs (1 fix)
242
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
243
+
244
+ "# ] ] )
245
+ . with_stdout_data ( "" )
246
+ . run ( ) ;
247
+ // Check that the test is fixed.
248
+ assert ! ( p. read_file( "src/lib.rs" ) . contains( r#"0..=100 => true,"# ) ) ;
249
+ }
250
+
251
+ #[ cargo_test]
252
+ fn fix_tests_with_edition_idioms ( ) {
253
+ let p = project ( )
254
+ . file (
255
+ "Cargo.toml" ,
256
+ r#"
257
+ [package]
258
+ name = 'foo'
259
+ version = '0.1.0'
260
+ edition = '2018'
261
+ "# ,
262
+ )
263
+ . file (
264
+ "src/lib.rs" ,
265
+ r#"
266
+ pub fn foo() {}
267
+
268
+ #[cfg(test)]
269
+ mod tests {
270
+ #[test]
271
+ fn it_works() {
272
+ f();
273
+ }
274
+
275
+ use std::any::Any;
276
+ pub fn f() {
277
+ let _x: Box<Any> = Box::new(3);
278
+ }
279
+ }
280
+ "# ,
281
+ )
282
+ . build ( ) ;
283
+
284
+ p. cargo ( "fix --edition-idioms --allow-no-vcs" )
285
+ . with_stderr_data ( str![ [ r#"
286
+ [CHECKING] foo v0.1.0 ([ROOT]/foo)
287
+ [FIXED] src/lib.rs (1 fix)
288
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
289
+
290
+ "# ] ] )
291
+ . with_stdout_data ( "" )
292
+ . run ( ) ;
293
+ // Check that the test is fixed.
294
+ assert ! ( p. read_file( "src/lib.rs" ) . contains( "Box<dyn Any>" ) ) ;
295
+ }
296
+
200
297
#[ cargo_test]
201
298
fn local_paths ( ) {
202
299
let p = project ( )
@@ -708,7 +805,7 @@ fn does_not_warn_about_dirty_ignored_files() {
708
805
}
709
806
710
807
#[ cargo_test]
711
- fn fix_all_targets_by_default ( ) {
808
+ fn do_not_fix_tests_by_default ( ) {
712
809
let p = project ( )
713
810
. file ( "src/lib.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
714
811
. file ( "tests/foo.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
@@ -717,7 +814,7 @@ fn fix_all_targets_by_default() {
717
814
. env ( "__CARGO_FIX_YOLO" , "1" )
718
815
. run ( ) ;
719
816
assert ! ( !p. read_file( "src/lib.rs" ) . contains( "let mut x" ) ) ;
720
- assert ! ( ! p. read_file( "tests/foo.rs" ) . contains( "let mut x" ) ) ;
817
+ assert ! ( p. read_file( "tests/foo.rs" ) . contains( "let mut x" ) ) ;
721
818
}
722
819
723
820
#[ cargo_test]
@@ -1330,7 +1427,6 @@ fn fix_to_broken_code() {
1330
1427
p. cargo ( "fix --allow-no-vcs --broken-code" )
1331
1428
. cwd ( "bar" )
1332
1429
. env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
1333
- . with_status ( 101 )
1334
1430
. with_stderr_data ( str![ [ r#"
1335
1431
...
1336
1432
[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
0 commit comments