Skip to content

test(rustflags): Verify -Cmetadata directly, not through -Cextra-filename #14846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,10 @@ pub fn cargo_exe() -> PathBuf {
/// does not have access to the raw `ExitStatus` because `ProcessError` needs
/// to be serializable (for the Rustc cache), and `ExitStatus` does not
/// provide a constructor.
struct RawOutput {
#[allow(dead_code)]
code: Option<i32>,
stdout: Vec<u8>,
#[allow(dead_code)]
stderr: Vec<u8>,
pub struct RawOutput {
pub code: Option<i32>,
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
}

/// Run and verify a [`ProcessBuilder`]
Expand Down Expand Up @@ -1042,34 +1040,32 @@ impl Execs {
}

#[track_caller]
pub fn run(&mut self) {
pub fn run(&mut self) -> RawOutput {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean Execs::exec_with_output is kinda obsolete and we should remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I missed that function but I can still see them serving different roles as run still applies any assertions and "successful exit" is the most basic one which provides better error messages than unwrapping the result would.

... ok so 44 out of 50 uses of exec_with_output can be replaced with the new run and provide a better experience. Seems like a worthwhile conversion though maybe not for this PR.

self.ran = true;
let mut p = (&self.process_builder).clone().unwrap();
if let Some(stdin) = self.expect_stdin.take() {
p.stdin(stdin);
}
if let Err(e) = self.match_process(&p) {
panic_error(&format!("test failed running {}", p), e);

match self.match_process(&p) {
Err(e) => panic_error(&format!("test failed running {}", p), e),
Ok(output) => output,
}
}

/// Runs the process, checks the expected output, and returns the first
/// JSON object on stdout.
#[track_caller]
pub fn run_json(&mut self) -> serde_json::Value {
self.ran = true;
let p = (&self.process_builder).clone().unwrap();
match self.match_process(&p) {
Err(e) => panic_error(&format!("test failed running {}", p), e),
Ok(output) => serde_json::from_slice(&output.stdout).unwrap_or_else(|e| {
panic!(
"\nfailed to parse JSON: {}\n\
let output = self.run();
serde_json::from_slice(&output.stdout).unwrap_or_else(|e| {
panic!(
"\nfailed to parse JSON: {}\n\
output was:\n{}\n",
e,
String::from_utf8_lossy(&output.stdout)
);
}),
}
e,
String::from_utf8_lossy(&output.stdout)
);
})
}

#[track_caller]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn build_with_symlink_to_path_dependency_with_build_script_in_git() {
// It is necessary to have a sub-repository and to add files so there is an index.
let repo = git::init(&root.join("original"));
git::add(&repo);
cargo_process("build").run()
cargo_process("build").run();
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5234,7 +5234,7 @@ fn dev_dep_with_links() {
.file("bar/build.rs", "fn main() {}")
.file("bar/src/lib.rs", "")
.build();
p.cargo("check --tests").run()
p.cargo("check --tests").run();
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ fn cargo_target_empty_env() {

"#]])
.with_status(101)
.run()
.run();
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/future_incompat_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,5 @@ big_update v1.0.0 has the following newer versions available: 2.0.0
with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1
...
"#]])
.run()
.run();
}
2 changes: 1 addition & 1 deletion tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3401,7 +3401,7 @@ fn metadata_links() {
"#]]
.is_json(),
)
.run()
.run();
}

#[cargo_test]
Expand Down
14 changes: 7 additions & 7 deletions tests/testsuite/open_namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Caused by:
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#open-namespaces for more information about the status of this feature.

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -100,7 +100,7 @@ fn implicit_lib_within_namespace() {
.is_json(),
)
.with_stderr_data("")
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -169,7 +169,7 @@ fn implicit_bin_within_namespace() {
.is_json(),
)
.with_stderr_data("")
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -256,7 +256,7 @@ fn explicit_bin_within_namespace() {
.is_json(),
)
.with_stderr_data("")
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -354,7 +354,7 @@ path+[ROOTURL]/foo#foo::[email protected]

"#]])
.with_stderr_data("")
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -384,7 +384,7 @@ fn update_spec_accepts_namespaced_name() {
[LOCKING] 0 packages to latest compatible versions

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -414,7 +414,7 @@ fn update_spec_accepts_namespaced_pkgid() {
[LOCKING] 0 packages to latest compatible versions

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3923,7 +3923,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/pkgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,5 @@ fn pkgid_json_message_metadata_consistency() {
"#]]
.is_json(),
)
.run()
.run();
}
2 changes: 1 addition & 1 deletion tests/testsuite/precise_pre_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if you are looking for the prerelease package it needs to be specified explicitl
perhaps a crate was updated and forgotten to be re-vendored?

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down
26 changes: 13 additions & 13 deletions tests/testsuite/pub_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn exported_priv_warning() {
src/lib.rs:3:13: [WARNING] type `FromPriv` from private dependency 'priv_dep' in public interface
...
"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -87,7 +87,7 @@ fn exported_pub_dep() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test]
Expand All @@ -113,7 +113,7 @@ Caused by:
See https://doc.rust-lang.org/[..]cargo/reference/unstable.html#public-dependency for more information about using this feature.

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -151,7 +151,7 @@ fn requires_feature() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -194,7 +194,7 @@ Caused by:
'public' specifier can only be used on regular dependencies, not dev-dependencies

"#]])
.run()
.run();
}

#[cargo_test]
Expand Down Expand Up @@ -233,7 +233,7 @@ fn pub_dev_dependency_without_feature() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -291,7 +291,7 @@ Caused by:
foo2 is public, but workspace dependencies cannot be public

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -336,7 +336,7 @@ fn allow_priv_in_tests() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -381,7 +381,7 @@ fn allow_priv_in_benchs() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -427,7 +427,7 @@ fn allow_priv_in_bins() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -473,7 +473,7 @@ fn allow_priv_in_examples() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -520,7 +520,7 @@ fn allow_priv_in_custom_build() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down Expand Up @@ -576,7 +576,7 @@ fn publish_package_with_public_dependency() {
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run()
.run();
}

#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,7 @@ fn protocol() {
[ERROR] unsupported registry protocol `invalid` (defined in environment variable `CARGO_REGISTRIES_CRATES_IO_PROTOCOL`)

"#]])
.run()
.run();
}

#[cargo_test]
Expand All @@ -3253,7 +3253,7 @@ fn http_requires_trailing_slash() {
[ERROR] sparse registry url must end in a slash `/`: sparse+https://invalid.crates.io/test

"#]])
.run()
.run();
}

// Limit the test to debug builds so that `__CARGO_TEST_MAX_UNPACK_SIZE` will take affect.
Expand Down
Loading