Skip to content

Commit

Permalink
test: track caller for .crate file publish verification (#14992)
Browse files Browse the repository at this point in the history
### What does this PR try to resolve?

This was found during some recent works around `cargo package`.
The purpose of it is showing the caller's line number when panicking.

### How should we test and review this PR?

Wait for CI. Nothing really change though.
  • Loading branch information
epage authored Dec 30, 2024
2 parents 9b5efd9 + 562e83a commit 0499e31
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/cargo-test-support/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
}

/// Check the `cargo publish` API call
#[track_caller]
pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_files: &[&str]) {
let new_path = registry::api_path().join("api/v1/crates/new");
_validate_upload(
Expand All @@ -90,6 +91,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_
}

/// Check the `cargo publish` API call, with file contents
#[track_caller]
pub fn validate_upload_with_contents(
expected_json: &str,
expected_crate_name: &str,
Expand All @@ -107,6 +109,7 @@ pub fn validate_upload_with_contents(
}

/// Check the `cargo publish` API call to the alternative test registry
#[track_caller]
pub fn validate_alt_upload(
expected_json: &str,
expected_crate_name: &str,
Expand All @@ -122,6 +125,7 @@ pub fn validate_alt_upload(
);
}

#[track_caller]
fn _validate_upload(
new_path: &Path,
expected_json: &str,
Expand All @@ -142,6 +146,7 @@ fn _validate_upload(
);
}

#[track_caller]
fn read_new_post(new_path: &Path) -> (Vec<u8>, Vec<u8>) {
let mut f = File::open(new_path).unwrap();

Expand Down Expand Up @@ -170,6 +175,7 @@ fn read_new_post(new_path: &Path) -> (Vec<u8>, Vec<u8>) {
/// - `expected_contents` should be a list of `(file_name, contents)` tuples
/// to validate the contents of the given file. Only the listed files will
/// be checked (others will be ignored).
#[track_caller]
pub fn validate_crate_contents(
reader: impl Read,
expected_crate_name: &str,
Expand All @@ -185,17 +191,19 @@ pub fn validate_crate_contents(
)
}

#[track_caller]
fn validate_crate_contents_(
reader: impl Read,
expected_crate_name: &str,
expected_files: &[&str],
expected_contents: InMemoryDir,
) {
let mut rdr = GzDecoder::new(reader);
assert_eq!(
rdr.header().unwrap().filename().unwrap(),
expected_crate_name.as_bytes()
);
snapbox::assert_data_eq!(rdr.header().unwrap().filename().unwrap(), {
let expected: snapbox::Data = expected_crate_name.into();
expected.raw()
});

let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
Expand Down

0 comments on commit 0499e31

Please sign in to comment.