2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo fix` command.
|
|
|
|
|
2018-07-22 18:01:07 +00:00
|
|
|
use std::fs::File;
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::git;
|
2019-10-22 14:53:51 +00:00
|
|
|
use cargo_test_support::paths;
|
|
|
|
use cargo_test_support::{basic_manifest, project};
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-08-21 07:06:19 +00:00
|
|
|
use std::io::Write;
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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)
|
2019-09-16 22:50:49 +00:00
|
|
|
.with_stderr_contains("[ERROR] could not compile `foo`.")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
assert!(p.read_file("src/lib.rs").contains("let mut x = 3;"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn broken_fixes_backed_out() {
|
2018-12-12 00:24:20 +00:00
|
|
|
// This works as follows:
|
|
|
|
// - Create a `rustc` shim (the "foo" project) which will pretend that the
|
|
|
|
// verification step fails.
|
|
|
|
// - There is an empty build script so `foo` has `OUT_DIR` to track the steps.
|
|
|
|
// - The first "check", `foo` creates a file in OUT_DIR, and it completes
|
|
|
|
// successfully with a warning diagnostic to remove unused `mut`.
|
|
|
|
// - rustfix removes the `mut`.
|
|
|
|
// - The second "check" to verify the changes, `foo` swaps out the content
|
|
|
|
// with something that fails to compile. It creates a second file so it
|
|
|
|
// won't do anything in the third check.
|
|
|
|
// - cargo fix discovers that the fix failed, and it backs out the changes.
|
|
|
|
// - The third "check" is done to display the original diagnostics of the
|
|
|
|
// original code.
|
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-12-08 11:19:47 +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() {
|
2018-12-12 00:24:20 +00:00
|
|
|
// Ignore calls to things like --print=file-names and compiling build.rs.
|
2018-07-14 01:49:26 +00:00
|
|
|
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());
|
2018-12-12 00:24:20 +00:00
|
|
|
let first = path.join("first");
|
|
|
|
let second = path.join("second");
|
|
|
|
if first.exists() && !second.exists() {
|
|
|
|
fs::write("src/lib.rs", b"not rust code").unwrap();
|
|
|
|
fs::File::create(&second).unwrap();
|
2018-07-14 01:49:26 +00:00
|
|
|
} else {
|
2018-12-12 00:24:20 +00:00
|
|
|
fs::File::create(&first).unwrap();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let status = Command::new("rustc")
|
|
|
|
.args(env::args().skip(1))
|
|
|
|
.status()
|
|
|
|
.expect("failed to run rustc");
|
|
|
|
process::exit(status.code().unwrap_or(2));
|
|
|
|
}
|
|
|
|
"##,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'bar'
|
|
|
|
version = '0.1.0'
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
// Build our rustc shim
|
2019-03-20 23:34:56 +00:00
|
|
|
p.cargo("build").cwd("foo").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
// Attempt to fix code, but our shim will always fail the second compile
|
2018-12-09 19:59:42 +00:00
|
|
|
p.cargo("fix --allow-no-vcs --lib")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("bar")
|
2018-08-28 09:20:03 +00:00
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.env("RUSTC", p.root().join("foo/target/debug/foo"))
|
|
|
|
.with_stderr_contains(
|
2019-07-13 23:00:47 +00:00
|
|
|
"warning: failed to automatically apply fixes suggested by rustc \
|
2018-08-28 09:20:03 +00:00
|
|
|
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\
|
2019-01-07 17:26:22 +00:00
|
|
|
[..]\n\
|
2018-12-12 00:24:20 +00:00
|
|
|
quoting the full output of this command we'd be very appreciative!\n\
|
2019-01-07 17:26:22 +00:00
|
|
|
Note that you may be able to make some more progress in the near-term\n\
|
|
|
|
fixing code with the `--broken-code` flag\n\
|
2018-12-12 00:24:20 +00:00
|
|
|
\n\
|
|
|
|
The following errors were reported:\n\
|
|
|
|
error: expected one of `!` or `::`, found `rust`\n\
|
2018-08-28 09:20:03 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2018-12-12 00:24:20 +00:00
|
|
|
.with_stderr_contains("Original diagnostics will follow.")
|
|
|
|
.with_stderr_contains("[WARNING] variable does not need to be mutable")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stderr_does_not_contain("[..][FIXING][..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-12-12 00:24:20 +00:00
|
|
|
|
|
|
|
// Make sure the fix which should have been applied was backed out
|
|
|
|
assert!(p.read_file("bar/src/lib.rs").contains("let mut x = 3;"));
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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-12-08 11:19:47 +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-12-08 11:19:47 +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("")
|
2018-11-06 00:32:27 +00:00
|
|
|
.with_stderr_unordered(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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-12-08 11:19:47 +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")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("foo")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
|
|
|
|
assert!(p.read_file("bar/src/lib.rs").contains("mut"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn prepare_for_2018() {
|
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)]
|
|
|
|
|
|
|
|
mod foo {
|
|
|
|
pub const FOO: &str = "fooo";
|
|
|
|
}
|
|
|
|
|
|
|
|
mod bar {
|
|
|
|
use ::foo::FOO;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = ::foo::FOO;
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-12-08 11:19:47 +00:00
|
|
|
assert!(p
|
|
|
|
.read_file("src/lib.rs")
|
|
|
|
.contains("let x = crate::foo::FOO;"));
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn local_paths() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-14 01:49:26 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
use test::foo;
|
|
|
|
|
|
|
|
mod test {
|
|
|
|
pub fn foo() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn f() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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;"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn upgrade_extern_crate() {
|
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-12-08 11:19:47 +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-12-08 11:19:47 +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"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn specify_rustflags() {
|
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)]
|
|
|
|
|
|
|
|
mod foo {
|
|
|
|
pub const FOO: &str = "fooo";
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x = ::foo::FOO;
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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")
|
2019-07-20 22:58:37 +00:00
|
|
|
.env("RUSTFLAGS", "-C linker=cc")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(stderr)
|
|
|
|
.with_stdout("")
|
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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",
|
2019-07-13 23:00:47 +00:00
|
|
|
"fn add(a: &u32) -> u32 { a + 1 }\r\n\
|
2018-07-14 01:49:26 +00:00
|
|
|
pub fn foo() -> u32 { let mut x = 3; add(&x) }\r\n\
|
|
|
|
",
|
2018-12-08 11:19:47 +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"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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",
|
2019-07-13 23:00:47 +00:00
|
|
|
"#![deny(warnings)]
|
|
|
|
pub fn foo() { let mut x = 3; drop(x); }
|
2018-07-14 01:49:26 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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() {}"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-14 01:49:26 +00:00
|
|
|
"src/bar.rs",
|
|
|
|
"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
let mut x = 3;
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
",
|
2018-12-08 11:19:47 +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;"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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-12-08 11:19:47 +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")
|
2018-12-08 11:19:47 +00:00
|
|
|
.env("__CARGO_FIX_YOLO", "1")
|
|
|
|
.with_stdout("")
|
|
|
|
.with_stderr_contains("[COMPILING] foo v0.0.1 ([..])")
|
|
|
|
.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.
|
|
|
|
.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)")
|
|
|
|
.with_stderr_contains("[FINISHED] [..]")
|
|
|
|
.run();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo("test").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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-12-08 11:19:47 +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-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn shows_warnings() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2019-04-05 19:55:01 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"#[deprecated] fn bar() {} pub fn foo() { let _ = bar(); }",
|
|
|
|
)
|
2018-07-14 01:49:26 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs")
|
2019-02-10 12:14:03 +00:00
|
|
|
.with_stderr_contains("[..]warning: use of deprecated item[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
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(
|
2019-07-13 23:00:47 +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`\
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-no-vcs").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn warns_about_dirty_working_directory() {
|
2019-08-13 05:25:36 +00:00
|
|
|
let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
|
2018-07-14 01:49:26 +00:00
|
|
|
|
2018-07-22 18:01:07 +00:00
|
|
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fix --allow-dirty").run();
|
2018-07-14 01:49:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-21 07:06:19 +00:00
|
|
|
fn warns_about_staged_working_directory() {
|
2019-08-13 05:25:36 +00:00
|
|
|
let (p, repo) = git::new_repo("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
|
2018-08-21 07:06:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-28 23:17:39 +00:00
|
|
|
p.cargo("fix --allow-staged").run();
|
2018-08-21 07:06:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-14 01:49:26 +00:00
|
|
|
fn does_not_warn_about_clean_working_directory() {
|
2019-08-13 05:25:36 +00:00
|
|
|
let p = git::new("foo", |p| p.file("src/lib.rs", "pub fn foo() {}"));
|
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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-22 18:01:07 +00:00
|
|
|
fn does_not_warn_about_dirty_ignored_files() {
|
2019-08-13 05:25:36 +00:00
|
|
|
let p = git::new("foo", |p| {
|
|
|
|
p.file("src/lib.rs", "pub fn foo() {}")
|
|
|
|
.file(".gitignore", "bar\n")
|
|
|
|
});
|
2018-07-22 18:01:07 +00:00
|
|
|
|
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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-26 22:21:34 +00:00
|
|
|
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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-28 20:22:32 +00:00
|
|
|
fn prepare_for_and_enable() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
edition = '2018'
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-31 20:08:46 +00:00
|
|
|
fn fix_overlapping() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo<T>() {}
|
|
|
|
pub struct A;
|
|
|
|
|
|
|
|
pub mod bar {
|
|
|
|
pub fn baz() {
|
|
|
|
::foo::<::A>();
|
|
|
|
}
|
|
|
|
}
|
2018-08-28 09:20:03 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-31 22:42:38 +00:00
|
|
|
fn fix_idioms() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
edition = '2018'
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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
|
|
|
"#,
|
2018-12-08 11:19:47 +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)
|
|
|
|
.run();
|
2018-07-31 22:42:38 +00:00
|
|
|
|
|
|
|
assert!(p.read_file("src/lib.rs").contains("Box<dyn Any>"));
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-31 22:42:38 +00:00
|
|
|
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
|
|
|
|
2019-05-09 17:58:18 +00:00
|
|
|
p.cargo("fix --edition-idioms --allow-no-vcs").run();
|
2018-07-31 22:42:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-01 00:01:09 +00:00
|
|
|
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:
|
2019-08-05 16:42:28 +00:00
|
|
|
cargo[..] fix --edition
|
2018-08-01 00:01:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-20 10:15:50 +00:00
|
|
|
fn shows_warnings_on_second_run_without_changes() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
2018-07-20 10:15:50 +00:00
|
|
|
|
|
|
|
pub fn foo() {
|
2019-02-10 12:14:03 +00:00
|
|
|
let _ = bar();
|
2018-07-20 10:15:50 +00:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs")
|
2019-02-10 12:14:03 +00:00
|
|
|
.with_stderr_contains("[..]warning: use of deprecated item[..]")
|
2018-07-20 10:15:50 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs")
|
2019-02-10 12:14:03 +00:00
|
|
|
.with_stderr_contains("[..]warning: use of deprecated item[..]")
|
2018-07-20 10:15:50 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-20 10:15:50 +00:00
|
|
|
fn shows_warnings_on_second_run_without_changes_on_multiple_targets() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
2018-07-20 10:15:50 +00:00
|
|
|
|
2019-02-10 12:14:03 +00:00
|
|
|
pub fn foo() {
|
|
|
|
let _ = bar();
|
|
|
|
}
|
2018-07-20 10:15:50 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = bar();
|
|
|
|
}
|
2018-07-20 10:15:50 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
|
|
|
|
2018-07-20 10:15:50 +00:00
|
|
|
#[test]
|
|
|
|
fn foo_test() {
|
2019-02-10 12:14:03 +00:00
|
|
|
let _ = bar();
|
2018-07-20 10:15:50 +00:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/bar.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
2018-07-20 10:15:50 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn foo_test() {
|
2019-02-10 12:14:03 +00:00
|
|
|
let _ = bar();
|
2018-07-20 10:15:50 +00:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/fooxample.rs",
|
|
|
|
r#"
|
2019-02-10 12:14:03 +00:00
|
|
|
#[deprecated]
|
|
|
|
fn bar() {}
|
2018-07-20 10:15:50 +00:00
|
|
|
|
|
|
|
fn main() {
|
2019-02-10 12:14:03 +00:00
|
|
|
let _ = bar();
|
2018-07-20 10:15:50 +00:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --all-targets")
|
2019-02-10 12:14:03 +00:00
|
|
|
.with_stderr_contains(" --> examples/fooxample.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> src/lib.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> src/main.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> tests/bar.rs:7:29")
|
|
|
|
.with_stderr_contains(" --> tests/foo.rs:7:29")
|
2018-07-20 10:15:50 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --all-targets")
|
2019-02-10 12:14:03 +00:00
|
|
|
.with_stderr_contains(" --> examples/fooxample.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> src/lib.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> src/main.rs:6:29")
|
|
|
|
.with_stderr_contains(" --> tests/bar.rs:7:29")
|
|
|
|
.with_stderr_contains(" --> tests/foo.rs:7:29")
|
2018-07-20 10:15:50 +00:00
|
|
|
.run();
|
|
|
|
}
|
2018-08-29 19:24:16 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-29 19:24:16 +00:00
|
|
|
fn doesnt_rebuild_dependencies() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = 'bar' }
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "extern crate bar;")
|
2018-08-29 19:24:16 +00:00
|
|
|
.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-12-08 11:19:47 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-08-30 05:28:20 +00:00
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
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-12-08 11:19:47 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-08-30 05:28:20 +00:00
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
2018-08-29 19:24:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
2018-09-05 22:17:43 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-10-22 14:53:51 +00:00
|
|
|
#[cfg(unix)]
|
2018-09-05 22:17:43 +00:00
|
|
|
fn does_not_crash_with_rustc_wrapper() {
|
|
|
|
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
|
|
|
|
2019-10-22 14:53:51 +00:00
|
|
|
#[cargo_test]
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn does_not_crash_with_rustc_workspace_wrapper() {
|
|
|
|
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 --verbose -Zunstable-options")
|
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", "/usr/bin/env")
|
|
|
|
.masquerade_as_nightly_cargo()
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn uses_workspace_wrapper_and_primary_wrapper_override() {
|
|
|
|
// We don't have /usr/bin/env on Windows.
|
|
|
|
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 --verbose -Zunstable-options")
|
2020-03-13 21:59:41 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", paths::echo_wrapper())
|
2019-10-22 14:53:51 +00:00
|
|
|
.masquerade_as_nightly_cargo()
|
2020-03-13 21:59:41 +00:00
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc src/lib.rs --crate-name foo [..]")
|
2019-10-22 14:53:51 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-01 15:13:11 +00:00
|
|
|
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")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-11-01 15:13:11 +00:00
|
|
|
[CHECKING] a v0.1.0 ([..])
|
|
|
|
[CHECKING] foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
2018-11-01 15:13:11 +00:00
|
|
|
.run();
|
|
|
|
}
|
2018-11-13 20:08:57 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-13 20:08:57 +00:00
|
|
|
fn fix_to_broken_code() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-11-13 20:08:57 +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() {
|
|
|
|
panic!()
|
|
|
|
} 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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-11-13 20:08:57 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'bar'
|
|
|
|
version = '0.1.0'
|
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/build.rs", "fn main() {}")
|
|
|
|
.file("bar/src/lib.rs", "pub fn foo() { let mut x = 3; drop(x); }")
|
|
|
|
.build();
|
2018-11-13 20:08:57 +00:00
|
|
|
|
|
|
|
// Build our rustc shim
|
2019-03-20 23:34:56 +00:00
|
|
|
p.cargo("build").cwd("foo").run();
|
2018-11-13 20:08:57 +00:00
|
|
|
|
|
|
|
// Attempt to fix code, but our shim will always fail the second compile
|
|
|
|
p.cargo("fix --allow-no-vcs --broken-code")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("bar")
|
2018-11-13 20:08:57 +00:00
|
|
|
.env("RUSTC", p.root().join("foo/target/debug/foo"))
|
|
|
|
.with_status(101)
|
2018-12-29 01:47:50 +00:00
|
|
|
.with_stderr_contains("[WARNING] failed to automatically apply fixes [..]")
|
2018-11-13 20:08:57 +00:00
|
|
|
.run();
|
|
|
|
|
2018-12-08 11:19:47 +00:00
|
|
|
assert_eq!(
|
|
|
|
p.read_file("bar/src/lib.rs"),
|
|
|
|
"pub fn foo() { let x = 3; drop(x); }"
|
|
|
|
);
|
2018-11-13 20:08:57 +00:00
|
|
|
}
|
2018-12-13 22:29:26 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-12-13 22:29:26 +00:00
|
|
|
fn fix_with_common() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
2019-01-27 13:39:49 +00:00
|
|
|
.file(
|
|
|
|
"tests/t1.rs",
|
|
|
|
"mod common; #[test] fn t1() { common::try(); }",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/t2.rs",
|
|
|
|
"mod common; #[test] fn t2() { common::try(); }",
|
|
|
|
)
|
2018-12-13 22:29:26 +00:00
|
|
|
.file("tests/common/mod.rs", "pub fn try() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --edition --allow-no-vcs").run();
|
|
|
|
|
|
|
|
assert_eq!(p.read_file("tests/common/mod.rs"), "pub fn r#try() {}");
|
|
|
|
}
|
2019-03-20 19:22:44 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-03-20 19:22:44 +00:00
|
|
|
fn fix_in_existing_repo_weird_ignore() {
|
|
|
|
// Check that ignore doesn't ignore the repo itself.
|
|
|
|
let p = git::new("foo", |project| {
|
|
|
|
project
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(".gitignore", "foo\ninner\n")
|
|
|
|
.file("inner/file", "")
|
2019-08-13 05:25:36 +00:00
|
|
|
});
|
2019-03-20 19:22:44 +00:00
|
|
|
|
|
|
|
p.cargo("fix").run();
|
|
|
|
// This is questionable about whether it is the right behavior. It should
|
|
|
|
// probably be checking if any source file for the current project is
|
|
|
|
// ignored.
|
|
|
|
p.cargo("fix")
|
2019-03-20 23:34:56 +00:00
|
|
|
.cwd("inner")
|
2019-03-20 19:22:44 +00:00
|
|
|
.with_stderr_contains("[ERROR] no VCS found[..]")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2019-03-20 23:34:56 +00:00
|
|
|
p.cargo("fix").cwd("src").run();
|
2019-03-20 19:22:44 +00:00
|
|
|
}
|
2019-06-26 17:30:24 +00:00
|
|
|
|
2019-10-28 19:00:09 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn fix_color_message() {
|
|
|
|
// Check that color appears in diagnostics.
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "std::compile_error!{\"color test\"}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --color=always")
|
|
|
|
.with_stderr_contains("[..]\x1b[[..]")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fix --allow-no-vcs --color=never")
|
|
|
|
.with_stderr_contains("error: color test")
|
|
|
|
.with_stderr_does_not_contain("[..]\x1b[[..]")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|