From 104ab6c2bc19cad3a61e338a324a4980a8920711 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 17 Nov 2018 22:57:06 +0000 Subject: [PATCH 1/6] Make verify-project honour unstable features --- src/bin/cargo/commands/verify_project.rs | 19 ++----------------- tests/testsuite/verify_project.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/bin/cargo/commands/verify_project.rs b/src/bin/cargo/commands/verify_project.rs index eea65c77598..b7887591bd8 100644 --- a/src/bin/cargo/commands/verify_project.rs +++ b/src/bin/cargo/commands/verify_project.rs @@ -2,10 +2,6 @@ use command_prelude::*; use std::collections::HashMap; use std::process; -use std::fs::File; -use std::io::Read; - -use toml; use cargo::print_json; @@ -23,19 +19,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { process::exit(1) } - let mut contents = String::new(); - let filename = match args.root_manifest(config) { - Ok(filename) => filename, - Err(e) => fail("invalid", &e.to_string()), - }; - - let file = File::open(&filename); - match file.and_then(|mut f| f.read_to_string(&mut contents)) { - Ok(_) => {} - Err(e) => fail("invalid", &format!("error reading file: {}", e)), - }; - if contents.parse::().is_err() { - fail("invalid", "invalid-format"); + if let Err(e) = args.workspace(config) { + fail("invalid", &e.to_string()) } let mut h = HashMap::new(); diff --git a/tests/testsuite/verify_project.rs b/tests/testsuite/verify_project.rs index d368b7c9fb4..060e3e3df52 100644 --- a/tests/testsuite/verify_project.rs +++ b/tests/testsuite/verify_project.rs @@ -42,3 +42,27 @@ fn cargo_verify_project_cwd() { .with_stdout(verify_project_success_output()) .run(); } + +#[test] +fn cargo_verify_project_honours_unstable_features() { + let p = project() + .file("Cargo.toml", r#" + cargo-features = ["test-dummy-unstable"] + + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", "") + .build(); + + p.cargo("verify-project") + .masquerade_as_nightly_cargo() + .with_stdout(verify_project_success_output()) + .run(); + + p.cargo("verify-project") + .with_status(1) + .with_stdout(r#"{"invalid":"failed to parse manifest at `[CWD]/Cargo.toml`"}"#) + .run(); +} From b088539de834d698352f9c543fb5079e481a44d3 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 09:08:15 +0000 Subject: [PATCH 2/6] Handle backslash-escaped backslashes --- tests/testsuite/support/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 06b7c6c3df9..6392df5654c 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -1188,6 +1188,9 @@ enum MatchKind { /// See `substitute_macros` for a complete list of macros. pub fn lines_match(expected: &str, actual: &str) -> bool { // Let's not deal with / vs \ (windows...) + // First replace backslash-escaped backslashes with forward slashes + // which can occur in, for example, JSON output + let expected = expected.replace("\\\\", "/"); let expected = expected.replace("\\", "/"); let mut actual: &str = &actual.replace("\\", "/"); let expected = substitute_macros(&expected); From 6afca122e556d2c08f1d2990be0147c404e566eb Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 12:08:03 +0000 Subject: [PATCH 3/6] Handle backslash-escaped backslashes in actual output too --- tests/testsuite/support/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 6392df5654c..9c8fbec795c 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -1190,9 +1190,8 @@ pub fn lines_match(expected: &str, actual: &str) -> bool { // Let's not deal with / vs \ (windows...) // First replace backslash-escaped backslashes with forward slashes // which can occur in, for example, JSON output - let expected = expected.replace("\\\\", "/"); - let expected = expected.replace("\\", "/"); - let mut actual: &str = &actual.replace("\\", "/"); + let expected = expected.replace("\\\\", "/").replace("\\", "/"); + let mut actual: &str = &actual.replace("\\\\", "/").replace("\\", "/"); let expected = substitute_macros(&expected); for (i, part) in expected.split("[..]").enumerate() { match actual.find(part) { From 49f73b9c4e686d237b043a5320ed82bc797995a3 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 13:38:33 +0000 Subject: [PATCH 4/6] Simplify cargo_command::cargo_subcommand_args test --- tests/testsuite/cargo_command.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index 8e0b6e19f15..e5adabe4fe6 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -264,13 +264,8 @@ fn cargo_subcommand_args() { cargo_process("foo bar -v --help") .env("PATH", &path) - .with_stdout( - if cfg!(windows) { // weird edge-case w/ CWD & (windows vs unix) - format!(r#"[{:?}, "foo", "bar", "-v", "--help"]"#, cargo_foo_bin) - } else { - r#"["[CWD]/cargo-foo/target/debug/cargo-foo", "foo", "bar", "-v", "--help"]"#.to_string() - } - ).run(); + .with_stdout(r#"["[CWD]/cargo-foo/target/debug/cargo-foo", "foo", "bar", "-v", "--help"]"#) + .run(); } #[test] From 092f7baea3bda0e1bc32de572a6cb3693120d884 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 14:44:16 +0000 Subject: [PATCH 5/6] Fix cargo_command::cargo_subcommand_args test --- tests/testsuite/cargo_command.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index e5adabe4fe6..793ed50299c 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -264,7 +264,9 @@ fn cargo_subcommand_args() { cargo_process("foo bar -v --help") .env("PATH", &path) - .with_stdout(r#"["[CWD]/cargo-foo/target/debug/cargo-foo", "foo", "bar", "-v", "--help"]"#) + .with_stdout( + r#"["[CWD]/cargo-foo/target/debug/cargo-foo[EXE]", "foo", "bar", "-v", "--help"]"#, + ) .run(); } From dc6b5be30d604d5e14a17a834fef710e3653ec41 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 18 Nov 2018 14:45:28 +0000 Subject: [PATCH 6/6] Simplify tool_paths::absolute_tools test ... by reusing the new [ROOT] macro. --- tests/testsuite/tool_paths.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index 5bd256715d6..d952991f322 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -33,7 +33,6 @@ fn pathless_tools() { #[test] fn absolute_tools() { let target = rustc_host(); - let root = if cfg!(windows) { r#"C:\"# } else { "/" }; // Escaped as they appear within a TOML config file let config = if cfg!(windows) { @@ -62,14 +61,11 @@ fn absolute_tools() { ), ).build(); - foo.cargo("build --verbose").with_stderr(&format!( - "\ + foo.cargo("build --verbose").with_stderr("\ [COMPILING] foo v0.5.0 ([CWD]) -[RUNNING] `rustc [..] -C ar={root}bogus/nonexistent-ar -C linker={root}bogus/nonexistent-linker [..]` +[RUNNING] `rustc [..] -C ar=[ROOT]bogus/nonexistent-ar -C linker=[ROOT]bogus/nonexistent-linker [..]` [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - root = root, - )).run(); +").run(); } #[test]