Skip to content

Commit 0499e31

Browse files
authored
test: track caller for .crate file publish verification (#14992)
### 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.
2 parents 9b5efd9 + 562e83a commit 0499e31

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

crates/cargo-test-support/src/publish.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ where
7878
}
7979

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

9293
/// Check the `cargo publish` API call, with file contents
94+
#[track_caller]
9395
pub fn validate_upload_with_contents(
9496
expected_json: &str,
9597
expected_crate_name: &str,
@@ -107,6 +109,7 @@ pub fn validate_upload_with_contents(
107109
}
108110

109111
/// Check the `cargo publish` API call to the alternative test registry
112+
#[track_caller]
110113
pub fn validate_alt_upload(
111114
expected_json: &str,
112115
expected_crate_name: &str,
@@ -122,6 +125,7 @@ pub fn validate_alt_upload(
122125
);
123126
}
124127

128+
#[track_caller]
125129
fn _validate_upload(
126130
new_path: &Path,
127131
expected_json: &str,
@@ -142,6 +146,7 @@ fn _validate_upload(
142146
);
143147
}
144148

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

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

194+
#[track_caller]
188195
fn validate_crate_contents_(
189196
reader: impl Read,
190197
expected_crate_name: &str,
191198
expected_files: &[&str],
192199
expected_contents: InMemoryDir,
193200
) {
194201
let mut rdr = GzDecoder::new(reader);
195-
assert_eq!(
196-
rdr.header().unwrap().filename().unwrap(),
197-
expected_crate_name.as_bytes()
198-
);
202+
snapbox::assert_data_eq!(rdr.header().unwrap().filename().unwrap(), {
203+
let expected: snapbox::Data = expected_crate_name.into();
204+
expected.raw()
205+
});
206+
199207
let mut contents = Vec::new();
200208
rdr.read_to_end(&mut contents).unwrap();
201209
let mut ar = Archive::new(&contents[..]);

0 commit comments

Comments
 (0)