@@ -197,6 +197,103 @@ fn prepare_for_2018() {
197197 . contains( "let x = crate::foo::FOO;" ) ) ;
198198}
199199
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+
200297#[ cargo_test]
201298fn local_paths ( ) {
202299 let p = project ( )
@@ -708,7 +805,7 @@ fn does_not_warn_about_dirty_ignored_files() {
708805}
709806
710807#[ cargo_test]
711- fn fix_all_targets_by_default ( ) {
808+ fn do_not_fix_tests_by_default ( ) {
712809 let p = project ( )
713810 . file ( "src/lib.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
714811 . file ( "tests/foo.rs" , "pub fn foo() { let mut x = 3; let _ = x; }" )
@@ -717,7 +814,7 @@ fn fix_all_targets_by_default() {
717814 . env ( "__CARGO_FIX_YOLO" , "1" )
718815 . run ( ) ;
719816 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" ) ) ;
721818}
722819
723820#[ cargo_test]
@@ -1330,7 +1427,6 @@ fn fix_to_broken_code() {
13301427 p. cargo ( "fix --allow-no-vcs --broken-code" )
13311428 . cwd ( "bar" )
13321429 . env ( "RUSTC" , p. root ( ) . join ( "foo/target/debug/foo" ) )
1333- . with_status ( 101 )
13341430 . with_stderr_data ( str![ [ r#"
13351431...
13361432[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
0 commit comments