Skip to content

Commit b931d98

Browse files
committed
refactor(test): Document 'publish' mod
1 parent 6d0eea0 commit b931d98

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

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

+62-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
//! Helpers for testing `cargo package` / `cargo publish`
2+
//!
3+
//! # Example
4+
//!
5+
//! ```no_run
6+
//! # use cargo_test_support::registry::RegistryBuilder;
7+
//! # use cargo_test_support::publish::validate_upload;
8+
//! # use cargo_test_support::project;
9+
//! // This replaces `registry::init()` and must be called before `Package::new().publish()`
10+
//! let registry = RegistryBuilder::new().http_api().http_index().build();
11+
//!
12+
//! let p = project()
13+
//! .file(
14+
//! "Cargo.toml",
15+
//! r#"
16+
//! [package]
17+
//! name = "foo"
18+
//! version = "0.0.1"
19+
//! edition = "2015"
20+
//! authors = []
21+
//! license = "MIT"
22+
//! description = "foo"
23+
//! "#,
24+
//! )
25+
//! .file("src/main.rs", "fn main() {}")
26+
//! .build();
27+
//!
28+
//! p.cargo("publish --no-verify")
29+
//! .replace_crates_io(registry.index_url())
30+
//! .run();
31+
//!
32+
//! validate_upload(
33+
//! r#"
34+
//! {
35+
//! "authors": [],
36+
//! "badges": {},
37+
//! "categories": [],
38+
//! "deps": [],
39+
//! "description": "foo",
40+
//! "documentation": null,
41+
//! "features": {},
42+
//! "homepage": null,
43+
//! "keywords": [],
44+
//! "license": "MIT",
45+
//! "license_file": null,
46+
//! "links": null,
47+
//! "name": "foo",
48+
//! "readme": null,
49+
//! "readme_file": null,
50+
//! "repository": null,
51+
//! "rust_version": null,
52+
//! "vers": "0.0.1"
53+
//! }
54+
//! "#,
55+
//! "foo-0.0.1.crate",
56+
//! &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
57+
//! );
58+
//! ```
59+
160
use crate::compare::{assert_match_exact, find_json_mismatch};
261
use crate::registry::{self, alt_api_path, FeatureMap};
362
use flate2::read::GzDecoder;
@@ -17,7 +76,7 @@ where
1776
Ok(u32::from_le_bytes(buf))
1877
}
1978

20-
/// Checks the result of a crate publish.
79+
/// Check the `cargo publish` API call
2180
pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_files: &[&str]) {
2281
let new_path = registry::api_path().join("api/v1/crates/new");
2382
_validate_upload(
@@ -29,7 +88,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_
2988
);
3089
}
3190

32-
/// Checks the result of a crate publish, along with the contents of the files.
91+
/// Check the `cargo publish` API call, with file contents
3392
pub fn validate_upload_with_contents(
3493
expected_json: &str,
3594
expected_crate_name: &str,
@@ -46,7 +105,7 @@ pub fn validate_upload_with_contents(
46105
);
47106
}
48107

49-
/// Checks the result of a crate publish to an alternative registry.
108+
/// Check the `cargo publish` API call to the alternative test registry
50109
pub fn validate_alt_upload(
51110
expected_json: &str,
52111
expected_crate_name: &str,

0 commit comments

Comments
 (0)