# Module publish

Source
Expand description

Helpers for testing `cargo package` / `cargo publish`

## §Example

    // This replaces `registry::init()` and must be called before `Package::new().publish()`
    let registry = RegistryBuilder::new().http_api().http_index().build();

    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [package]
                name = "foo"
                version = "0.0.1"
                edition = "2015"
                authors = []
                license = "MIT"
                description = "foo"
            "#,
        )
        .file("src/main.rs", "fn main() {}")
        .build();

    p.cargo("publish --no-verify")
        .replace_crates_io(registry.index_url())
        .run();

    validate_upload(
        r#"
        {
          "authors": [],
          "badges": {},
          "categories": [],
          "deps": [],
          "description": "foo",
          "documentation": null,
          "features": {},
          "homepage": null,
          "keywords": [],
          "license": "MIT",
          "license_file": null,
          "links": null,
          "name": "foo",
          "readme": null,
          "readme_file": null,
          "repository": null,
          "rust_version": null,
          "vers": "0.0.1"
          }
        "#,
        "foo-0.0.1.crate",
        &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
    );

## Functions§

_validate_upload 🔒
create_index_line 🔒
read_le_u32 🔒
read_new_post 🔒
split_index_features 🔒
validate_alt_upload
  Check the `cargo publish` API call to the alternative test registry
validate_crate_contents
  Checks the contents of a `.crate` file.
validate_crate_contents_ 🔒
validate_upload
  Check the `cargo publish` API call
validate_upload_with_contents
  Check the `cargo publish` API call, with file contents
write_to_index 🔒