From 88a843807910a7f0e2d5d846f288ba43309f8767 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 4 Oct 2024 11:49:18 -0500 Subject: [PATCH] feat(test): Snapshot .crate validation --- crates/cargo-test-support/src/compare.rs | 132 +++++- crates/cargo-test-support/src/publish.rs | 45 ++- tests/testsuite/artifact_dep.rs | 22 +- tests/testsuite/cross_publish.rs | 2 +- tests/testsuite/features2.rs | 21 +- tests/testsuite/features_namespaced.rs | 42 +- .../testsuite/inheritable_workspace_fields.rs | 105 +++-- tests/testsuite/package.rs | 378 +++++++++++------- tests/testsuite/publish.rs | 122 +++--- tests/testsuite/publish_lockfile.rs | 10 +- tests/testsuite/weak_dep_features.rs | 21 +- 11 files changed, 617 insertions(+), 283 deletions(-) diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 5a26aa1f18c..411506590b4 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -46,8 +46,11 @@ use crate::paths; use crate::{diff, rustc_host}; use anyhow::{bail, Context, Result}; use serde_json::Value; +use snapbox::Data; +use snapbox::IntoData; use std::fmt; use std::path::Path; +use std::path::PathBuf; use std::str; use url::Url; @@ -461,14 +464,6 @@ pub(crate) fn match_exact( ); } -/// Convenience wrapper around [`match_exact`] which will panic on error. -#[track_caller] -pub(crate) fn assert_match_exact(expected: &str, actual: &str) { - if let Err(e) = match_exact(expected, actual, "", "", None) { - crate::panic_error("", e); - } -} - /// Checks that the given string contains the given lines, ignoring the order /// of the lines. /// @@ -860,6 +855,127 @@ impl fmt::Debug for WildStr<'_> { } } +pub struct InMemoryDir { + files: Vec<(PathBuf, Data)>, +} + +impl InMemoryDir { + pub fn paths(&self) -> impl Iterator { + self.files.iter().map(|(p, _)| p.as_path()) + } + + #[track_caller] + pub fn assert_contains(&self, expected: &Self) { + let assert = assert_e2e(); + for (path, expected_data) in &expected.files { + let actual_data = self + .files + .iter() + .find_map(|(p, d)| (path == p).then(|| d.clone())) + .unwrap_or_else(|| Data::new()); + assert.eq(actual_data, expected_data); + } + } +} + +impl FromIterator<(P, D)> for InMemoryDir +where + P: Into, + D: IntoData, +{ + fn from_iter>(files: I) -> Self { + let files = files + .into_iter() + .map(|(p, d)| (p.into(), d.into_data())) + .collect(); + Self { files } + } +} + +impl From<[(P, D); N]> for InMemoryDir +where + P: Into, + D: IntoData, +{ + fn from(files: [(P, D); N]) -> Self { + let files = files + .into_iter() + .map(|(p, d)| (p.into(), d.into_data())) + .collect(); + Self { files } + } +} + +impl From> for InMemoryDir +where + P: Into, + D: IntoData, +{ + fn from(files: std::collections::HashMap) -> Self { + let files = files + .into_iter() + .map(|(p, d)| (p.into(), d.into_data())) + .collect(); + Self { files } + } +} + +impl From> for InMemoryDir +where + P: Into, + D: IntoData, +{ + fn from(files: std::collections::BTreeMap) -> Self { + let files = files + .into_iter() + .map(|(p, d)| (p.into(), d.into_data())) + .collect(); + Self { files } + } +} + +impl From<()> for InMemoryDir { + fn from(_files: ()) -> Self { + let files = Vec::new(); + Self { files } + } +} + +macro_rules! impl_from_tuple_for_dirsnapshot { + ($($var:ident $path:ident $data:ident),+) => { + impl<$($path: Into, $data: IntoData),+> From<($(($path, $data)),+ ,)> for InMemoryDir { + fn from(files: ($(($path, $data)),+,)) -> Self { + let ($($var),+ ,) = files; + let files = [$(($var.0.into(), $var.1.into_data())),+]; + files.into() + } + } + }; +} + +macro_rules! impl_from_tuples_for_dirsnapshot { + ($var1:ident $path1:ident $data1:ident, $($var:ident $path:ident $data:ident),+) => { + impl_from_tuples_for_dirsnapshot!(__impl $var1 $path1 $data1; $($var $path $data),+); + }; + (__impl $($var:ident $path:ident $data:ident),+; $var1:ident $path1:ident $data1:ident $(,$var2:ident $path2:ident $data2:ident)*) => { + impl_from_tuple_for_dirsnapshot!($($var $path $data),+); + impl_from_tuples_for_dirsnapshot!(__impl $($var $path $data),+, $var1 $path1 $data1; $($var2 $path2 $data2),*); + }; + (__impl $($var:ident $path:ident $data:ident),+;) => { + impl_from_tuple_for_dirsnapshot!($($var $path $data),+); + } +} + +impl_from_tuples_for_dirsnapshot!( + s1 P1 D1, + s2 P2 D2, + s3 P3 D3, + s4 P4 D4, + s5 P5 D5, + s6 P6 D6, + s7 P7 D7 +); + #[cfg(test)] mod test { use snapbox::assert_data_eq; diff --git a/crates/cargo-test-support/src/publish.rs b/crates/cargo-test-support/src/publish.rs index ffe872fe70f..2cd4a1d3d4d 100644 --- a/crates/cargo-test-support/src/publish.rs +++ b/crates/cargo-test-support/src/publish.rs @@ -57,14 +57,14 @@ //! ); //! ``` -use crate::compare::{assert_match_exact, find_json_mismatch}; +use crate::compare::{find_json_mismatch, InMemoryDir}; use crate::registry::{self, alt_api_path, FeatureMap}; use flate2::read::GzDecoder; -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; use std::fs; use std::fs::File; use std::io::{self, prelude::*, SeekFrom}; -use std::path::{Path, PathBuf}; +use std::path::Path; use tar::Archive; fn read_le_u32(mut reader: R) -> io::Result @@ -84,7 +84,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_ expected_json, expected_crate_name, expected_files, - &[], + (), ); } @@ -93,7 +93,7 @@ pub fn validate_upload_with_contents( expected_json: &str, expected_crate_name: &str, expected_files: &[&str], - expected_contents: &[(&str, &str)], + expected_contents: impl Into, ) { let new_path = registry::api_path().join("api/v1/crates/new"); _validate_upload( @@ -117,7 +117,7 @@ pub fn validate_alt_upload( expected_json, expected_crate_name, expected_files, - &[], + (), ); } @@ -126,7 +126,7 @@ fn _validate_upload( expected_json: &str, expected_crate_name: &str, expected_files: &[&str], - expected_contents: &[(&str, &str)], + expected_contents: impl Into, ) { let (actual_json, krate_bytes) = read_new_post(new_path); @@ -177,7 +177,22 @@ pub fn validate_crate_contents( reader: impl Read, expected_crate_name: &str, expected_files: &[&str], - expected_contents: &[(&str, &str)], + expected_contents: impl Into, +) { + let expected_contents = expected_contents.into(); + validate_crate_contents_( + reader, + expected_crate_name, + expected_files, + expected_contents, + ) +} + +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!( @@ -192,7 +207,7 @@ pub fn validate_crate_contents( .strip_suffix(".crate") .expect("must end with .crate"), ); - let files: HashMap = ar + let actual_contents: InMemoryDir = ar .entries() .unwrap() .map(|entry| { @@ -208,7 +223,7 @@ pub fn validate_crate_contents( (name, contents) }) .collect(); - let actual_files: HashSet<&Path> = files.keys().map(|p| p.as_path()).collect(); + let actual_files: HashSet<&Path> = actual_contents.paths().collect(); let expected_files: HashSet<&Path> = expected_files.iter().map(|name| Path::new(name)).collect(); let missing: Vec<&&Path> = expected_files.difference(&actual_files).collect(); @@ -219,15 +234,7 @@ pub fn validate_crate_contents( missing, extra ); } - if !expected_contents.is_empty() { - for (e_file_name, e_file_contents) in expected_contents { - let e_file_name = Path::new(e_file_name); - let actual_contents = files - .get(e_file_name) - .unwrap_or_else(|| panic!("file `{}` missing in archive", e_file_name.display())); - assert_match_exact(e_file_contents, actual_contents); - } - } + actual_contents.assert_contains(&expected_contents); } pub(crate) fn create_index_line( diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index c4d1f9ce15d..867721f74fa 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2260,10 +2260,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -2299,9 +2309,9 @@ artifact = [ "cdylib", "staticlib", ] -target = "target""#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), +target = "target" + +"##]], )], ); } diff --git a/tests/testsuite/cross_publish.rs b/tests/testsuite/cross_publish.rs index 2646dea4083..fa74669b482 100644 --- a/tests/testsuite/cross_publish.rs +++ b/tests/testsuite/cross_publish.rs @@ -58,7 +58,7 @@ fn simple_cross_package() { f, "foo-0.0.0.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 8f469e2b110..c8142b7d8a2 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -1788,8 +1788,18 @@ fn package_includes_resolve_behavior() { p.cargo("package").cwd("a").run(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "a" @@ -1810,16 +1820,15 @@ resolver = "2" [lib] name = "a" path = "src/lib.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ); + +"##]]; let f = File::open(&p.root().join("target/package/a-0.1.0.crate")).unwrap(); validate_crate_contents( f, "a-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); } diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index a620f441b69..7712bf7d5ef 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -976,10 +976,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -1009,9 +1019,8 @@ optional = true [features] feat = ["opt-dep1"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -1104,10 +1113,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -1135,9 +1154,8 @@ optional = true feat1 = [] feat2 = ["dep:bar"] feat3 = ["feat2"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index 8af4724a8aa..7ac3252eb2e 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -206,10 +206,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. ".cargo_vcs_info.json", "bar.txt", ], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2018" rust-version = "1.60" @@ -241,9 +251,8 @@ repository = "https://github.com/example/example" [[bin]] name = "foo" path = "src/main.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -385,10 +394,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "bar-0.2.0.crate", &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "bar" @@ -414,9 +433,8 @@ version = "0.5.2" [build-dependencies.dep-build] version = "0.8" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -525,10 +543,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "bar-0.2.0.crate", &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "bar" @@ -549,9 +577,8 @@ path = "src/main.rs" [dependencies.dep] version = "0.1.2" features = ["testing"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -776,10 +803,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. ".cargo_vcs_info.json", "bar.txt", ], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2018" rust-version = "1.60" @@ -814,9 +851,8 @@ repository = "https://github.com/example/example" [[bin]] name = "bar" path = "src/main.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -960,10 +996,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "bar-0.2.0.crate", &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "bar" @@ -989,9 +1035,8 @@ version = "0.5.2" [build-dependencies.dep-build] version = "0.8" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 046635a0534..e6dfaeed635 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -73,7 +73,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } @@ -183,8 +183,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "sha1": "{}" }}, "path_in_vcs": "" -}} -"#, +}}"#, repo.revparse_head() ); validate_crate_contents( @@ -197,7 +196,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "src/main.rs", ".cargo_vcs_info.json", ], - &[(".cargo_vcs_info.json", &vcs_contents)], + [(".cargo_vcs_info.json", &vcs_contents)], ); println!("package sub-repo"); @@ -223,8 +222,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "sha1": "{}" }}, "path_in_vcs": "a/a" -}} -"#, +}}"#, repo.revparse_head() ); validate_crate_contents( @@ -236,7 +234,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "src/lib.rs", ".cargo_vcs_info.json", ], - &[(".cargo_vcs_info.json", &vcs_contents)], + [(".cargo_vcs_info.json", &vcs_contents)], ); } @@ -757,7 +755,7 @@ src/main.rs f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } @@ -818,7 +816,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "src/main.rs", "src/foo.rs", ], - &[], + (), ); } @@ -1185,15 +1183,18 @@ fn issue_13695_allow_dirty_vcs_info() { "Cargo.toml.orig", "src/lib.rs", ], - &[( + [( ".cargo_vcs_info.json", - r#"{ + str![[r#" +{ "git": { - "sha1": "[..]", - "dirty": true + "dirty": true, + "sha1": "[..]" }, "path_in_vcs": "" -}"#, +} +"#]] + .is_json(), )], ); @@ -1242,14 +1243,17 @@ fn issue_13695_allowing_dirty_vcs_info_but_clean() { "Cargo.toml.orig", "src/lib.rs", ], - &[( + [( ".cargo_vcs_info.json", - r#"{ + str![[r#" +{ "git": { "sha1": "[..]" }, "path_in_vcs": "" -}"#, +} +"#]] + .is_json(), )], ); } @@ -1280,13 +1284,13 @@ fn issue_14354_allowing_dirty_bare_commit() { f, "foo-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[], + (), ); } #[cargo_test] fn generated_manifest() { - let registry = registry::alt_init(); + registry::alt_init(); Package::new("abc", "1.0.0").publish(); Package::new("def", "1.0.0").alternative(true).publish(); Package::new("ghi", "1.0.0").publish(); @@ -1325,8 +1329,18 @@ fn generated_manifest() { p.cargo("package --no-verify").run(); let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -1358,20 +1372,18 @@ version = "0.1" [dependencies.def] version = "1.0" -registry-index = "{}" +registry-index = "[ROOTURL]/alternative-registry" [dependencies.ghi] version = "1.0" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE, - registry.index_url() - ); + +"##]]; validate_crate_contents( f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); } @@ -1412,8 +1424,18 @@ fn ignore_workspace_specifier() { p.cargo("package --no-verify").cwd("bar").run(); let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "bar" @@ -1430,14 +1452,13 @@ readme = false [lib] name = "bar" path = "src/lib.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ); + +"##]]; validate_crate_contents( f, "bar-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); } @@ -1491,8 +1512,18 @@ fn package_public_dep() { ) .file("src/main.rs", "fn main() {}") .build(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -1512,16 +1543,24 @@ path = "src/main.rs" [dependencies.bar] version = "1.0.0" -[target.{host}.dependencies.baz] +[target.[HOST_TARGET].dependencies.baz] version = "1.0.0" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE, - host = rustc_host() - ); + +"##]]; verify(&p, "package", rewritten_toml); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -1542,16 +1581,14 @@ path = "src/main.rs" version = "1.0.0" public = true -[target.{host}.dependencies.baz] +[target.[HOST_TARGET].dependencies.baz] version = "1.0.0" public = true -"#, - cargo::core::manifest::MANIFEST_PREAMBLE, - host = rustc_host() - ); + +"##]]; verify(&p, "package -Zpublic-dependency", rewritten_toml); - fn verify(p: &cargo_test_support::Project, cmd: &str, rewritten_toml: String) { + fn verify(p: &cargo_test_support::Project, cmd: &str, rewritten_toml: impl IntoData) { p.cargo(cmd) .masquerade_as_nightly_cargo(&["public-dependency"]) .run(); @@ -1560,7 +1597,7 @@ public = true f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); } } @@ -2274,7 +2311,7 @@ subdir/LICENSE "subdir/LICENSE", "src/lib.rs", ], - &[("subdir/LICENSE", "license text")], + [("subdir/LICENSE", "license text")], ); } @@ -2324,7 +2361,7 @@ src/lib.rs f, "foo-1.0.0.crate", &["Cargo.toml", "Cargo.toml.orig", "LICENSE", "src/lib.rs"], - &[("LICENSE", "license text")], + [("LICENSE", "license text")], ); let manifest = std::fs::read_to_string(p.root().join("target/package/foo-1.0.0/Cargo.toml")).unwrap(); @@ -2383,7 +2420,7 @@ src/lib.rs f, "foo-1.0.0.crate", &["Cargo.toml", "Cargo.toml.orig", "LICENSE", "src/lib.rs"], - &[("LICENSE", "inner license")], + [("LICENSE", "inner license")], ); let manifest = read_to_string(p.root().join("target/package/foo-1.0.0/Cargo.toml")).unwrap(); assert!(manifest.contains("license-file = \"LICENSE\"")); @@ -2983,8 +3020,18 @@ fn workspace_overrides_resolver() { p.cargo("package --no-verify -p bar -p baz").run(); let f = File::open(&p.root().join("target/package/bar-0.1.0.crate")).unwrap(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2021" name = "bar" @@ -3001,20 +3048,29 @@ resolver = "1" [lib] name = "bar" path = "src/lib.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ); + +"##]]; validate_crate_contents( f, "bar-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); // When the crate has the same implicit resolver as the workspace it is not overridden let f = File::open(&p.root().join("target/package/baz-0.1.0.crate")).unwrap(); - let rewritten_toml = format!( - r#"{} + let rewritten_toml = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "baz" @@ -3030,14 +3086,13 @@ readme = false [lib] name = "baz" path = "src/lib.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ); + +"##]]; validate_crate_contents( f, "baz-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[("Cargo.toml", &rewritten_toml)], + [("Cargo.toml", rewritten_toml)], ); } @@ -3157,7 +3212,7 @@ src/main.rs f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[ + [ ("Cargo.lock", cargo_lock_contents), ("Cargo.toml", &cargo_toml_contents), ("Cargo.toml.orig", cargo_toml_orig_contents), @@ -3268,7 +3323,7 @@ src/main.rs "src/bar.txt", "src/main.rs", ], - &[ + [ ("Cargo.lock", cargo_lock_contents), ("Cargo.toml", &cargo_toml_contents), ("Cargo.toml.orig", cargo_toml_orig_contents), @@ -3391,7 +3446,7 @@ src/main.rs.bak "src/main.rs", "src/main.rs.bak", ], - &[ + [ ("Cargo.lock", cargo_lock_contents), ("Cargo.toml", &cargo_toml_contents), ("Cargo.toml.orig", cargo_toml_orig_contents), @@ -3494,10 +3549,20 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for "Examples/ExampleFoo.rs", "Tests/ExplicitPath.rs", ], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2018" name = "foo" @@ -3517,9 +3582,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } @@ -3584,7 +3648,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } @@ -3621,7 +3685,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for f, "foo-0.0.0.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } @@ -3893,9 +3957,10 @@ fn normalize_paths() { "tests/test_foo.rs", "benches/bench_foo.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -3941,7 +4006,8 @@ path = "tests/test_foo.rs" [[bench]] name = "bench_foo" path = "benches/bench_foo.rs" -"#, + +"##]], )], ); } @@ -3984,9 +4050,10 @@ fn discovery_inferred_build_rs_included() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4020,7 +4087,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -4064,9 +4132,10 @@ fn discovery_inferred_build_rs_excluded() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4097,7 +4166,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -4141,9 +4211,10 @@ fn discovery_explicit_build_rs_included() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4177,7 +4248,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -4222,9 +4294,10 @@ fn discovery_explicit_build_rs_excluded() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4255,7 +4328,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -4304,9 +4378,10 @@ fn discovery_inferred_lib_included() { "src/main.rs", "src/lib.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4344,7 +4419,8 @@ path = "src/lib.rs" [[bin]] name = "foo" path = "src/main.rs" -"#, + +"##]], )], ); } @@ -4388,9 +4464,10 @@ fn discovery_inferred_lib_excluded() { f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4421,7 +4498,8 @@ license = "MIT" [[bin]] name = "foo" path = "src/main.rs" -"#, + +"##]], )], ); } @@ -4473,9 +4551,10 @@ fn discovery_explicit_lib_included() { "src/main.rs", "src/lib.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4513,7 +4592,8 @@ path = "src/lib.rs" [[bin]] name = "foo" path = "src/main.rs" -"#, + +"##]], )], ); } @@ -4560,9 +4640,10 @@ fn discovery_explicit_lib_excluded() { f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4593,7 +4674,8 @@ license = "MIT" [[bin]] name = "foo" path = "src/main.rs" -"#, + +"##]], )], ); } @@ -4648,9 +4730,10 @@ fn discovery_inferred_other_included() { "tests/test_foo.rs", "benches/bench_foo.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4703,7 +4786,8 @@ path = "tests/test_foo.rs" [[bench]] name = "bench_foo" path = "benches/bench_foo.rs" -"#, + +"##]], )], ); } @@ -4753,9 +4837,10 @@ fn discovery_inferred_other_excluded() { f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4786,7 +4871,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -4853,9 +4939,10 @@ fn discovery_explicit_other_included() { "tests/test_foo.rs", "benches/bench_foo.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -4908,7 +4995,8 @@ path = "tests/test_foo.rs" [[bench]] name = "bench_foo" path = "benches/bench_foo.rs" -"#, + +"##]], )], ); } @@ -4970,9 +5058,10 @@ fn discovery_explicit_other_excluded() { f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -5003,7 +5092,8 @@ license = "MIT" [lib] name = "foo" path = "src/lib.rs" -"#, + +"##]], )], ); } @@ -5070,9 +5160,10 @@ fn deterministic_build_targets() { "examples/y.rs", "examples/z.rs", ], - &[( + [( "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -5126,7 +5217,8 @@ path = "examples/y.rs" [[example]] name = "z" path = "examples/z.rs" -"#, + +"##]], )], ); } @@ -5262,8 +5354,8 @@ fn workspace_with_local_deps_nightly() { "#]]) .run(); - let generated_lock = format!( - r#"# This file is automatically @generated by Cargo. + let generated_lock = str![[r##" +# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 @@ -5278,7 +5370,7 @@ dependencies = [ name = "level2" version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = [..] +checksum = "[..]" dependencies = [ "level3", ] @@ -5287,12 +5379,22 @@ dependencies = [ name = "level3" version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = [..] -"# - ); +checksum = "[..]" + +"##]]; + + let generated_manifest = str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. - let generated_manifest = format!( - r#"{} [package] edition = "2015" name = "level1" @@ -5316,9 +5418,8 @@ path = "src/main.rs" [dependencies.level2] version = "0.0.1" features = ["foo"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE, - ); + +"##]]; let mut f = File::open(&p.root().join("target/package/level1-0.0.1.crate")).unwrap(); @@ -5326,9 +5427,9 @@ features = ["foo"] &mut f, "level1-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[ - ("Cargo.lock", &generated_lock), - ("Cargo.toml", &generated_manifest), + [ + ("Cargo.lock", generated_lock), + ("Cargo.toml", generated_manifest), ], ); } @@ -5788,9 +5889,8 @@ fn workspace_with_local_deps_alternative_index() { "#]]) .run(); - let index = alt_reg.index_url(); - let generated_lock = format!( - r#"# This file is automatically @generated by Cargo. + let generated_lock = str![[r##" +# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 @@ -5804,10 +5904,10 @@ dependencies = [ [[package]] name = "level2" version = "0.0.1" -source = "{index}" -checksum = [..] -"# - ); +source = "sparse+http://127.0.0.1:45127/index/" +checksum = "[..]" + +"##]]; let mut f = File::open(&p.root().join("target/package/level1-0.0.1.crate")).unwrap(); @@ -5815,7 +5915,7 @@ checksum = [..] &mut f, "level1-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[("Cargo.lock", &generated_lock)], + [("Cargo.lock", generated_lock)], ); } diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 82b689e034e..eb1292110ae 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -1571,57 +1571,68 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[ + [ ( "Cargo.toml", // Check that only `version` is included in Cargo.toml. - &format!( - "{}\n\ - [package]\n\ - edition = \"2018\"\n\ - name = \"foo\"\n\ - version = \"0.1.0\"\n\ - authors = []\n\ - build = false\n\ - autolib = false\n\ - autobins = false\n\ - autoexamples = false\n\ - autotests = false\n\ - autobenches = false\n\ - description = \"foo\"\n\ - readme = false\n\ - license = \"MIT\"\n\ - \n\ - [[bin]]\n\ - name = \"foo\"\n\ - path = \"src/main.rs\"\n\ - \n\ - [dependencies.dep1]\n\ - version = \"1.0\"\n\ - ", - cargo::core::manifest::MANIFEST_PREAMBLE - ), + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "foo" +version = "0.1.0" +authors = [] +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +readme = false +license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" + +[dependencies.dep1] +version = "1.0" + +"##]], ), ( "Cargo.lock", // The important check here is that it is 1.0.1 in the registry. - "# This file is automatically @generated by Cargo.\n\ - # It is not intended for manual editing.\n\ - version = 4\n\ - \n\ - [[package]]\n\ - name = \"dep1\"\n\ - version = \"1.0.1\"\n\ - source = \"registry+https://github.com/rust-lang/crates.io-index\"\n\ - checksum = \"[..]\"\n\ - \n\ - [[package]]\n\ - name = \"foo\"\n\ - version = \"0.1.0\"\n\ - dependencies = [\n\ - \x20\"dep1\",\n\ - ]\n\ - ", + str![[r##" +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "dep1" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "[..]" + +[[package]] +name = "foo" +version = "0.1.0" +dependencies = [ + "dep1", +] + +"##]], ), ], ); @@ -1954,10 +1965,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[( - "Cargo.toml", - &format!( - r#"{} + [( + "Cargo.toml", + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -2047,9 +2068,8 @@ features = ["cat"] [target."cfg(unix)".dev-dependencies.target-normal-and-dev] version = "1.0" features = ["cat"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); } diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs index 059d6ce54d6..0ba0e6e6f8d 100644 --- a/tests/testsuite/publish_lockfile.rs +++ b/tests/testsuite/publish_lockfile.rs @@ -108,7 +108,7 @@ src/main.rs f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "Cargo.lock", "src/main.rs"], - &[], + (), ); } @@ -163,7 +163,7 @@ fn no_lock_file_with_library() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[], + (), ); } @@ -188,7 +188,7 @@ fn lock_file_and_workspace() { f, "foo-0.0.1.crate", &["Cargo.toml", "Cargo.toml.orig", "src/main.rs", "Cargo.lock"], - &[], + (), ); } @@ -576,7 +576,7 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for f, "foo-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); let package_path = p.root().join("target/package/bar-0.0.1.crate"); @@ -586,6 +586,6 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for f, "bar-0.0.1.crate", &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[], + (), ); } diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index 3e931be3a6f..b26d767de94 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -621,10 +621,20 @@ You may press ctrl-c to skip waiting; the crate should be available shortly. "#, "foo-0.1.0.crate", &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( + [( "Cargo.toml", - &format!( - r#"{} + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + [package] edition = "2015" name = "foo" @@ -651,9 +661,8 @@ optional = true [features] feat1 = [] feat2 = ["bar?/feat"] -"#, - cargo::core::manifest::MANIFEST_PREAMBLE - ), + +"##]], )], ); }