2018-07-22 18:01:07 +00:00
|
|
|
use std::fs::File;
|
|
|
|
|
|
|
|
use git2;
|
|
|
|
|
2018-07-21 21:17:44 +00:00
|
|
|
use support::git;
|
2018-08-28 08:24:37 +00:00
|
|
|
use support::is_nightly;
|
2018-08-28 09:20:03 +00:00
|
|
|
use support::{basic_manifest, project};
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-21 07:06:19 +00:00
|
|
|
use std::io::Write;
|
|
|
|
|
2018-07-14 01:49:26 +00:00
|
|
|
#[test]
|
|
|
|
fn do_not_fix_broken_builds() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() {
|
|
|
|
let mut x = 3;
|
|
|
|
drop(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn foo2() {
|
|
|
|
let _x: u32 = "a";
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
assert!(p.read_file("src/lib.rs").contains("let mut x = 3;"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_broken_if_requested() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
fn foo(a: &u32) -> u32 { a + 1 }
|
|
|
|
pub fn bar() {
|
|
|
|
foo(1);
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs --broken-code")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn broken_fixes_backed_out() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"foo/src/main.rs",
|
|
|
|
r##"
|
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use std::process::{self, Command};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let is_lib_rs = env::args_os()
|
|
|
|
.map(PathBuf::from)
|
|
|
|
.any(|l| l == Path::new("src/lib.rs"));
|
|
|
|
if is_lib_rs {
|
|
|
|
let path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
let path = path.join("foo");
|
|
|
|
if path.exists() {
|
|
|
|
fs::File::create("src/lib.rs")
|
|
|
|
.unwrap()
|
|
|
|
.write_all(b"not rust code")
|
|
|
|
.unwrap();
|
|
|
|
} else {
|
|
|
|
fs::File::create(&path).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let status = Command::new("rustc")
|
|
|
|
.args(env::args().skip(1))
|
|
|
|
.status()
|
|
|
|
.expect("failed to run rustc");
|
|
|
|
process::exit(status.code().unwrap_or(2));
|
|
|
|
}
|
|
|
|
"##,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'bar'
|
|
|
|
version = '0.1.0'
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("bar/build.rs", "fn main() {}")
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() {
|
|
|
|
let mut x = 3;
|
|
|
|
drop(x);
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
// Build our rustc shim
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").cwd(p.root().join("foo")).run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
// Attempt to fix code, but our shim will always fail the second compile
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.cwd(p.root().join("bar"))
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.env("RUSTC", p.root().join("foo/target/debug/foo"))
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..]not rust code[..]")
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
|
|
|
warning: failed to automatically apply fixes suggested by rustc \
|
|
|
|
to crate `bar`\n\
|
|
|
|
\n\
|
|
|
|
after fixes were automatically applied the compiler reported \
|
|
|
|
errors within these files:\n\
|
|
|
|
\n \
|
|
|
|
* src/lib.rs\n\
|
|
|
|
\n\
|
|
|
|
This likely indicates a bug in either rustc or cargo itself,\n\
|
|
|
|
and we would appreciate a bug report! You're likely to see \n\
|
|
|
|
a number of compiler warnings after this message which cargo\n\
|
|
|
|
attempted to fix but failed. If you could open an issue at\n\
|
|
|
|
https://github.com/rust-lang/cargo/issues\n\
|
|
|
|
quoting the full output of this command we'd be very appreciative!\
|
|
|
|
",
|
|
|
|
).with_stderr_does_not_contain("[..][FIXING][..]")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_path_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = 'bar' }
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs -p foo -p bar")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stdout("")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-07-14 01:49:26 +00:00
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] bar/src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_fix_non_relevant_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-24 12:59:42 +00:00
|
|
|
.no_manifest()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = '../bar' }
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("foo/src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.cwd(p.root().join("foo"))
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
assert!(p.read_file("bar/src/lib.rs").contains("mut"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prepare_for_2018() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![allow(unused)]
|
|
|
|
#![feature(rust_2018_preview)]
|
|
|
|
|
|
|
|
mod foo {
|
|
|
|
pub const FOO: &str = "fooo";
|
|
|
|
}
|
|
|
|
|
|
|
|
mod bar {
|
|
|
|
use ::foo::FOO;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = ::foo::FOO;
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (2 fixes)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition --allow-no-vcs")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
println!("{}", p.read_file("src/lib.rs"));
|
|
|
|
assert!(p.read_file("src/lib.rs").contains("use crate::foo::FOO;"));
|
2018-08-28 09:20:03 +00:00
|
|
|
assert!(
|
|
|
|
p.read_file("src/lib.rs")
|
|
|
|
.contains("let x = crate::foo::FOO;")
|
|
|
|
);
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn local_paths() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(rust_2018_preview)]
|
|
|
|
|
|
|
|
use test::foo;
|
|
|
|
|
|
|
|
mod test {
|
|
|
|
pub fn foo() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn f() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition --allow-no-vcs")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
println!("{}", p.read_file("src/lib.rs"));
|
|
|
|
assert!(p.read_file("src/lib.rs").contains("use crate::test::foo;"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn upgrade_extern_crate() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = '2018'
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = 'bar' }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
use bar::bar;
|
|
|
|
|
|
|
|
pub fn foo() {
|
|
|
|
::bar::bar();
|
|
|
|
bar();
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-14 01:49:26 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let stderr = "\
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
println!("{}", p.read_file("src/lib.rs"));
|
|
|
|
assert!(!p.read_file("src/lib.rs").contains("extern crate"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn specify_rustflags() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![allow(unused)]
|
|
|
|
#![feature(rust_2018_preview)]
|
|
|
|
|
|
|
|
mod foo {
|
|
|
|
pub const FOO: &str = "fooo";
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = ::foo::FOO;
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition --allow-no-vcs")
|
|
|
|
.env("RUSTFLAGS", "-C target-cpu=native")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn no_changes_necessary() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fixes_extra_mut() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (1 fix)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fixes_two_missing_ampersands() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
let mut y = 3;
|
|
|
|
x + y
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (2 fixes)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn tricky() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3; let mut y = 3;
|
|
|
|
x + y
|
|
|
|
}
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
2018-07-24 13:01:56 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (2 fixes)
|
2018-07-14 01:49:26 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn preserve_line_endings() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"\
|
|
|
|
fn add(a: &u32) -> u32 { a + 1 }\r\n\
|
|
|
|
pub fn foo() -> u32 { let mut x = 3; add(&x) }\r\n\
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
assert!(p.read_file("src/lib.rs").contains("\r\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_deny_warnings() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"\
|
|
|
|
#![deny(warnings)]
|
|
|
|
pub fn foo() { let mut x = 3; drop(x); }
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_deny_warnings_but_not_others() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
|
|
|
#![deny(warnings)]
|
|
|
|
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() {}
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
assert!(!p.read_file("src/lib.rs").contains("let mut x = 3;"));
|
|
|
|
assert!(p.read_file("src/lib.rs").contains("fn bar() {}"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_two_files() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
|
|
|
pub mod bar;
|
|
|
|
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"src/bar.rs",
|
|
|
|
"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stderr_contains("[FIXING] src/bar.rs (1 fix)")
|
|
|
|
.with_stderr_contains("[FIXING] src/lib.rs (1 fix)")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
assert!(!p.read_file("src/lib.rs").contains("let mut x = 3;"));
|
|
|
|
assert!(!p.read_file("src/bar.rs").contains("let mut x = 3;"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fixes_missing_ampersand() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "fn main() { let mut x = 3; drop(x); }")
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() { let mut x = 3; drop(x); }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn foo2() { let mut x = 3; drop(x); }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"tests/a.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
pub fn foo() { let mut x = 3; drop(x); }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("examples/foo.rs", "fn main() { let mut x = 3; drop(x); }")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("build.rs", "fn main() { let mut x = 3; drop(x); }")
|
2018-07-14 01:49:26 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --all-targets --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
2018-07-14 01:49:26 +00:00
|
|
|
.with_stdout("")
|
2018-07-24 13:01:56 +00:00
|
|
|
.with_stderr_contains("[COMPILING] foo v0.0.1 ([..])")
|
2018-07-14 01:49:26 +00:00
|
|
|
.with_stderr_contains("[FIXING] build.rs (1 fix)")
|
|
|
|
// Don't assert number of fixes for this one, as we don't know if we're
|
|
|
|
// fixing it once or twice! We run this all concurrently, and if we
|
|
|
|
// compile (and fix) in `--test` mode first, we get two fixes. Otherwise
|
|
|
|
// we'll fix one non-test thing, and then fix another one later in
|
|
|
|
// test mode.
|
2018-08-02 09:18:48 +00:00
|
|
|
.with_stderr_contains("[FIXING] src/lib.rs[..]")
|
|
|
|
.with_stderr_contains("[FIXING] src/main.rs (1 fix)")
|
|
|
|
.with_stderr_contains("[FIXING] examples/foo.rs (1 fix)")
|
|
|
|
.with_stderr_contains("[FIXING] tests/a.rs (1 fix)")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[FINISHED] [..]").run();
|
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo("test").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
bar = []
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[cfg(feature = "bar")]
|
|
|
|
pub fn foo() -> u32 { let mut x = 3; x }
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs").run();
|
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo("fix --features bar --allow-no-vcs").run();
|
|
|
|
p.cargo("build --features bar").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shows_warnings() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "use std::default::Default; pub fn foo() {}")
|
2018-07-14 01:49:26 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.with_stderr_contains("[..]warning: unused import[..]")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn warns_if_no_vcs_detected() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-09-21 06:47:09 +00:00
|
|
|
error: no VCS found for this package and `cargo fix` can potentially perform \
|
2018-08-28 09:20:03 +00:00
|
|
|
destructive changes; if you'd like to suppress this error pass `--allow-no-vcs`\
|
|
|
|
",
|
|
|
|
).run();
|
|
|
|
p.cargo("fix --allow-no-vcs").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn warns_about_dirty_working_directory() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-07-22 18:01:07 +00:00
|
|
|
let repo = git2::Repository::init(&p.root()).unwrap();
|
|
|
|
let mut cfg = t!(repo.config());
|
|
|
|
t!(cfg.set_str("user.email", "foo@bar.com"));
|
|
|
|
t!(cfg.set_str("user.name", "Foo Bar"));
|
|
|
|
drop(cfg);
|
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
|
|
|
File::create(p.root().join("src/lib.rs")).unwrap();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-09-21 06:47:09 +00:00
|
|
|
error: the working directory of this package has uncommitted changes, \
|
2018-08-20 10:46:29 +00:00
|
|
|
and `cargo fix` can potentially perform destructive changes; if you'd \
|
2018-08-21 06:58:08 +00:00
|
|
|
like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \
|
|
|
|
commit the changes to these files:
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-20 10:46:29 +00:00
|
|
|
* src/lib.rs (dirty)
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
|
|
|
).run();
|
|
|
|
p.cargo("fix --allow-dirty").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 07:06:19 +00:00
|
|
|
#[test]
|
|
|
|
fn warns_about_staged_working_directory() {
|
2018-08-28 23:17:39 +00:00
|
|
|
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
|
2018-08-21 07:06:19 +00:00
|
|
|
|
|
|
|
let repo = git2::Repository::init(&p.root()).unwrap();
|
|
|
|
let mut cfg = t!(repo.config());
|
|
|
|
t!(cfg.set_str("user.email", "foo@bar.com"));
|
|
|
|
t!(cfg.set_str("user.name", "Foo Bar"));
|
|
|
|
drop(cfg);
|
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
|
|
|
File::create(&p.root().join("src/lib.rs"))
|
|
|
|
.unwrap()
|
|
|
|
.write_all("pub fn bar() {}".to_string().as_bytes())
|
|
|
|
.unwrap();
|
|
|
|
git::add(&repo);
|
|
|
|
|
2018-08-28 23:17:39 +00:00
|
|
|
p.cargo("fix")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-09-21 06:47:09 +00:00
|
|
|
error: the working directory of this package has uncommitted changes, \
|
2018-08-21 07:06:19 +00:00
|
|
|
and `cargo fix` can potentially perform destructive changes; if you'd \
|
|
|
|
like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \
|
|
|
|
commit the changes to these files:
|
|
|
|
|
|
|
|
* src/lib.rs (staged)
|
|
|
|
|
|
|
|
|
2018-08-28 23:17:39 +00:00
|
|
|
",
|
|
|
|
).run();
|
|
|
|
p.cargo("fix --allow-staged").run();
|
2018-08-21 07:06:19 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 01:49:26 +00:00
|
|
|
#[test]
|
|
|
|
fn does_not_warn_about_clean_working_directory() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "pub fn foo() {}").build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
let repo = git2::Repository::init(&p.root()).unwrap();
|
|
|
|
let mut cfg = t!(repo.config());
|
|
|
|
t!(cfg.set_str("user.email", "foo@bar.com"));
|
|
|
|
t!(cfg.set_str("user.name", "Foo Bar"));
|
|
|
|
drop(cfg);
|
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
2018-07-22 18:01:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_warn_about_dirty_ignored_files() {
|
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn foo() {}")
|
2018-07-17 06:27:43 +00:00
|
|
|
.file(".gitignore", "bar\n")
|
2018-07-22 18:01:07 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
let repo = git2::Repository::init(&p.root()).unwrap();
|
|
|
|
let mut cfg = t!(repo.config());
|
|
|
|
t!(cfg.set_str("user.email", "foo@bar.com"));
|
|
|
|
t!(cfg.set_str("user.name", "Foo Bar"));
|
|
|
|
drop(cfg);
|
|
|
|
git::add(&repo);
|
|
|
|
git::commit(&repo);
|
2018-07-17 06:27:43 +00:00
|
|
|
File::create(p.root().join("bar")).unwrap();
|
2018-07-22 18:01:07 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix").run();
|
2018-07-22 18:01:07 +00:00
|
|
|
}
|
2018-07-26 22:21:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fix_all_targets_by_default() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
|
|
|
|
.file("tests/foo.rs", "pub fn foo() { let mut x = 3; drop(x); }")
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.run();
|
2018-07-26 22:21:34 +00:00
|
|
|
assert!(!p.read_file("src/lib.rs").contains("let mut x"));
|
|
|
|
assert!(!p.read_file("tests/foo.rs").contains("let mut x"));
|
|
|
|
}
|
2018-07-28 20:22:32 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn prepare_for_and_enable() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
edition = '2018'
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file("src/lib.rs", "")
|
2018-07-28 20:22:32 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
let stderr = "\
|
|
|
|
error: cannot prepare for the 2018 edition when it is enabled, so cargo cannot
|
2018-08-02 09:18:48 +00:00
|
|
|
automatically fix errors in `src/lib.rs`
|
2018-07-28 20:22:32 +00:00
|
|
|
|
|
|
|
To prepare for the 2018 edition you should first remove `edition = '2018'` from
|
|
|
|
your `Cargo.toml` and then rerun this command. Once all warnings have been fixed
|
|
|
|
then you can re-enable the `edition` key in `Cargo.toml`. For some more
|
|
|
|
information about transitioning to the 2018 edition see:
|
|
|
|
|
|
|
|
https://[..]
|
|
|
|
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition --allow-no-vcs")
|
|
|
|
.with_stderr_contains(stderr)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2018-07-28 20:22:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 20:08:46 +00:00
|
|
|
#[test]
|
|
|
|
fn fix_overlapping() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-31 20:08:46 +00:00
|
|
|
}
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(rust_2018_preview)]
|
|
|
|
|
|
|
|
pub fn foo<T>() {}
|
|
|
|
pub struct A;
|
|
|
|
|
|
|
|
pub mod bar {
|
|
|
|
pub fn baz() {
|
|
|
|
::foo::<::A>();
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 09:20:03 +00:00
|
|
|
"#,
|
|
|
|
).build();
|
2018-07-31 20:08:46 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
|
|
|
[CHECKING] foo [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[FIXING] src/lib.rs (2 fixes)
|
2018-07-31 20:08:46 +00:00
|
|
|
[FINISHED] dev [..]
|
|
|
|
";
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs --prepare-for 2018 --lib")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.run();
|
2018-07-31 20:08:46 +00:00
|
|
|
|
|
|
|
let contents = p.read_file("src/lib.rs");
|
|
|
|
println!("{}", contents);
|
|
|
|
assert!(contents.contains("crate::foo::<crate::A>()"));
|
|
|
|
}
|
2018-08-01 00:01:09 +00:00
|
|
|
|
2018-07-31 22:42:38 +00:00
|
|
|
#[test]
|
|
|
|
fn fix_idioms() {
|
|
|
|
if !is_nightly() {
|
2018-08-28 09:20:03 +00:00
|
|
|
return;
|
2018-07-31 22:42:38 +00:00
|
|
|
}
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
edition = '2018'
|
|
|
|
"#,
|
2018-08-28 09:20:03 +00:00
|
|
|
).file(
|
2018-07-31 22:42:38 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
use std::any::Any;
|
|
|
|
pub fn foo() {
|
|
|
|
let _x: Box<Any> = Box::new(3);
|
|
|
|
}
|
2018-08-28 09:20:03 +00:00
|
|
|
"#,
|
|
|
|
).build();
|
2018-07-31 22:42:38 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
|
|
|
[CHECKING] foo [..]
|
|
|
|
[FIXING] src/lib.rs (1 fix)
|
|
|
|
[FINISHED] [..]
|
|
|
|
";
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition-idioms --allow-no-vcs")
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_status(0)
|
|
|
|
.run();
|
2018-07-31 22:42:38 +00:00
|
|
|
|
|
|
|
assert!(p.read_file("src/lib.rs").contains("Box<dyn Any>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn idioms_2015_ok() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2018-07-31 22:42:38 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --edition-idioms --allow-no-vcs")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.with_status(0)
|
|
|
|
.run();
|
2018-07-31 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 00:01:09 +00:00
|
|
|
#[test]
|
|
|
|
fn both_edition_migrate_flags() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2018-08-01 00:01:09 +00:00
|
|
|
|
|
|
|
let stderr = "\
|
|
|
|
error: The argument '--edition' cannot be used with '--prepare-for <prepare-for>'
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
cargo[..] fix --edition --message-format <FMT>
|
|
|
|
|
|
|
|
For more information try --help
|
|
|
|
";
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --prepare-for 2018 --edition")
|
|
|
|
.with_status(1)
|
|
|
|
.with_stderr(stderr)
|
|
|
|
.run();
|
2018-08-01 00:01:09 +00:00
|
|
|
}
|
2018-07-20 10:15:50 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shows_warnings_on_second_run_without_changes() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
|
|
|
|
pub fn foo() {
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.with_stderr_contains("[..]warning: unused import[..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.with_stderr_contains("[..]warning: unused import[..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn shows_warnings_on_second_run_without_changes_on_multiple_targets() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
|
|
|
|
pub fn a() -> u32 { 3 }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
fn main() { println!("3"); }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
#[test]
|
|
|
|
fn foo_test() {
|
|
|
|
println!("3");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/bar.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn foo_test() {
|
|
|
|
println!("3");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/fooxample.rs",
|
|
|
|
r#"
|
|
|
|
use std::default::Default;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("3");
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --all-targets")
|
|
|
|
.with_stderr_contains(" --> examples/fooxample.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> src/lib.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> src/main.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> tests/bar.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> tests/foo.rs:2:21")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --all-targets")
|
|
|
|
.with_stderr_contains(" --> examples/fooxample.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> src/lib.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> src/main.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> tests/bar.rs:2:21")
|
|
|
|
.with_stderr_contains(" --> tests/foo.rs:2:21")
|
|
|
|
.run();
|
|
|
|
}
|
2018-08-29 19:24:16 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doesnt_rebuild_dependencies() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = 'bar' }
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
"#,
|
|
|
|
).file("src/lib.rs", "extern crate bar;")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs -p foo")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stdout("")
|
2018-08-30 05:28:20 +00:00
|
|
|
.with_stderr("\
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
")
|
2018-08-29 19:24:16 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs -p foo")
|
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stdout("")
|
2018-08-30 05:28:20 +00:00
|
|
|
.with_stderr("\
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
")
|
2018-08-29 19:24:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
2018-09-05 22:17:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_crash_with_rustc_wrapper() {
|
|
|
|
// We don't have /usr/bin/env on Windows.
|
|
|
|
if cfg!(windows) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs")
|
|
|
|
.env("RUSTC_WRAPPER", "/usr/bin/env")
|
|
|
|
.run();
|
|
|
|
}
|
2018-11-01 15:13:11 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn only_warn_for_relevant_crates() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = 'a' }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
"
|
|
|
|
pub fn foo() {}
|
|
|
|
pub mod bar {
|
|
|
|
use foo;
|
|
|
|
pub fn baz() { foo() }
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --edition")
|
|
|
|
.with_stderr("\
|
|
|
|
[CHECKING] a v0.1.0 ([..])
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
")
|
|
|
|
.run();
|
|
|
|
}
|