mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
test: add tests for fixing edition and edition idioms
Signed-off-by: Rustin170506 <techregister@pm.me>
This commit is contained in:
parent
bf43053405
commit
69f398f647
@ -197,6 +197,103 @@ fn prepare_for_2018() {
|
||||
.contains("let x = crate::foo::FOO;"));
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn fix_tests_with_edition() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![allow(ellipsis_inclusive_range_patterns)]
|
||||
pub fn foo() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
f();
|
||||
}
|
||||
fn f() -> bool {
|
||||
let x = 123;
|
||||
match x {
|
||||
0...100 => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --edition --allow-no-vcs")
|
||||
.with_stderr_data(str![[r#"
|
||||
[MIGRATING] Cargo.toml from 2018 edition to 2021
|
||||
[CHECKING] foo v0.1.0 ([ROOT]/foo)
|
||||
[MIGRATING] src/lib.rs from 2018 edition to 2021
|
||||
[FIXED] src/lib.rs (1 fix)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
.with_stdout_data("")
|
||||
.run();
|
||||
// Check that the test is fixed.
|
||||
assert!(p.read_file("src/lib.rs").contains(r#"0..=100 => true,"#));
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn fix_tests_with_edition_idioms() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = 'foo'
|
||||
version = '0.1.0'
|
||||
edition = '2018'
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
pub fn foo() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
f();
|
||||
}
|
||||
|
||||
use std::any::Any;
|
||||
pub fn f() {
|
||||
let _x: Box<Any> = Box::new(3);
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("fix --edition-idioms --allow-no-vcs")
|
||||
.with_stderr_data(str![[r#"
|
||||
[CHECKING] foo v0.1.0 ([ROOT]/foo)
|
||||
[FIXED] src/lib.rs (1 fix)
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
.with_stdout_data("")
|
||||
.run();
|
||||
// Check that the test is fixed.
|
||||
assert!(p.read_file("src/lib.rs").contains("Box<dyn Any>"));
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn local_paths() {
|
||||
let p = project()
|
||||
|
Loading…
x
Reference in New Issue
Block a user