Skip to content

Commit 69f398f

Browse files
committed
test: add tests for fixing edition and edition idioms
Signed-off-by: Rustin170506 <techregister@pm.me>
1 parent bf43053 commit 69f398f

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/testsuite/fix.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
201298
fn local_paths() {
202299
let p = project()

0 commit comments

Comments
 (0)