diff --git a/crates/cargo-test-support/src/compare.rs b/crates/cargo-test-support/src/compare.rs index 5b5d4b6ce85..b05bc42b996 100644 --- a/crates/cargo-test-support/src/compare.rs +++ b/crates/cargo-test-support/src/compare.rs @@ -45,8 +45,11 @@ use crate::cross_compile::try_alternate; use crate::paths; use crate::{diff, rustc_host}; use anyhow::{bail, Result}; +use snapbox::Data; +use snapbox::IntoData; use std::fmt; use std::path::Path; +use std::path::PathBuf; use std::str; use url::Url; @@ -428,46 +431,6 @@ fn substitute_macros(input: &str) -> String { result } -/// Compares one string against another, checking that they both match. -/// -/// See [Patterns](index.html#patterns) for more information on pattern matching. -/// -/// - `description` explains where the output is from (usually "stdout" or "stderr"). -/// - `other_output` is other output to display in the error (usually stdout or stderr). -pub(crate) fn match_exact( - expected: &str, - actual: &str, - description: &str, - other_output: &str, - cwd: Option<&Path>, -) -> Result<()> { - let expected = normalize_expected(expected, cwd); - let actual = normalize_actual(actual, cwd); - let e: Vec<_> = expected.lines().map(WildStr::new).collect(); - let a: Vec<_> = actual.lines().map(WildStr::new).collect(); - if e == a { - return Ok(()); - } - let diff = diff::colored_diff(&e, &a); - bail!( - "{} did not match:\n\ - {}\n\n\ - other output:\n\ - {}\n", - description, - diff, - other_output, - ); -} - -/// 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. /// @@ -706,6 +669,136 @@ 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) { + use std::fmt::Write as _; + let assert = assert_e2e(); + let mut errs = String::new(); + 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()); + if let Err(err) = + assert.try_eq(Some(&path.display()), actual_data, expected_data.clone()) + { + let _ = write!(&mut errs, "{err}"); + } + } + if !errs.is_empty() { + panic!("{errs}") + } + } +} + +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/diff.rs b/crates/cargo-test-support/src/diff.rs index cd0c9738553..8b5e109be45 100644 --- a/crates/cargo-test-support/src/diff.rs +++ b/crates/cargo-test-support/src/diff.rs @@ -16,99 +16,6 @@ pub enum Change { Keep(usize, usize, T), } -pub fn diff<'a, T>(a: &'a [T], b: &'a [T]) -> Vec> -where - T: PartialEq, -{ - if a.is_empty() && b.is_empty() { - return vec![]; - } - let mut diff = vec![]; - for (prev_x, prev_y, x, y) in backtrack(&a, &b) { - if x == prev_x { - diff.push(Change::Add(prev_y + 1, &b[prev_y])); - } else if y == prev_y { - diff.push(Change::Remove(prev_x + 1, &a[prev_x])); - } else { - diff.push(Change::Keep(prev_x + 1, prev_y + 1, &a[prev_x])); - } - } - diff.reverse(); - diff -} - -fn shortest_edit(a: &[T], b: &[T]) -> Vec> -where - T: PartialEq, -{ - let max = a.len() + b.len(); - let mut v = vec![0; 2 * max + 1]; - let mut trace = vec![]; - for d in 0..=max { - trace.push(v.clone()); - for k in (0..=(2 * d)).step_by(2) { - let mut x = if k == 0 || (k != 2 * d && v[max - d + k - 1] < v[max - d + k + 1]) { - // Move down - v[max - d + k + 1] - } else { - // Move right - v[max - d + k - 1] + 1 - }; - let mut y = x + d - k; - // Step diagonally as far as possible. - while x < a.len() && y < b.len() && a[x] == b[y] { - x += 1; - y += 1; - } - v[max - d + k] = x; - // Return if reached the bottom-right position. - if x >= a.len() && y >= b.len() { - return trace; - } - } - } - panic!("finished without hitting end?"); -} - -fn backtrack(a: &[T], b: &[T]) -> Vec<(usize, usize, usize, usize)> -where - T: PartialEq, -{ - let mut result = vec![]; - let mut x = a.len(); - let mut y = b.len(); - let max = x + y; - for (d, v) in shortest_edit(a, b).iter().enumerate().rev() { - let k = x + d - y; - let prev_k = if k == 0 || (k != 2 * d && v[max - d + k - 1] < v[max - d + k + 1]) { - k + 1 - } else { - k - 1 - }; - let prev_x = v[max - d + prev_k]; - let prev_y = (prev_x + d).saturating_sub(prev_k); - while x > prev_x && y > prev_y { - result.push((x - 1, y - 1, x, y)); - x -= 1; - y -= 1; - } - if d > 0 { - result.push((prev_x, prev_y, x, y)); - } - x = prev_x; - y = prev_y; - } - return result; -} - -pub fn colored_diff<'a, T>(a: &'a [T], b: &'a [T]) -> String -where - T: PartialEq + fmt::Display, -{ - let changes = diff(a, b); - render_colored_changes(&changes) -} - pub fn render_colored_changes(changes: &[Change]) -> String { // anstyle is not very ergonomic, but I don't want to bring in another dependency. let red = anstyle::AnsiColor::Red.on_default().render(); @@ -140,27 +47,3 @@ pub fn render_colored_changes(changes: &[Change]) -> String } String::from_utf8(buffer.into_inner()).unwrap() } - -#[cfg(test)] -pub fn compare(a: &str, b: &str) { - let a: Vec<_> = a.chars().collect(); - let b: Vec<_> = b.chars().collect(); - let changes = diff(&a, &b); - let mut result = vec![]; - for change in changes { - match change { - Change::Add(_, s) => result.push(*s), - Change::Remove(_, _s) => {} - Change::Keep(_, _, s) => result.push(*s), - } - } - assert_eq!(b, result); -} - -#[test] -fn basic_tests() { - compare("", ""); - compare("A", ""); - compare("", "B"); - compare("ABCABBA", "CBABAC"); -} diff --git a/crates/cargo-test-support/src/publish.rs b/crates/cargo-test-support/src/publish.rs index a1c7f04e4cd..e6adac7d048 100644 --- a/crates/cargo-test-support/src/publish.rs +++ b/crates/cargo-test-support/src/publish.rs @@ -57,15 +57,15 @@ //! ); //! ``` -use crate::compare::assert_match_exact; +use crate::compare::InMemoryDir; use crate::registry::{self, alt_api_path, FeatureMap}; use flate2::read::GzDecoder; use snapbox::prelude::*; -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 @@ -85,7 +85,7 @@ pub fn validate_upload(expected_json: &str, expected_crate_name: &str, expected_ expected_json, expected_crate_name, expected_files, - &[], + (), ); } @@ -94,7 +94,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( @@ -118,7 +118,7 @@ pub fn validate_alt_upload( expected_json, expected_crate_name, expected_files, - &[], + (), ); } @@ -127,7 +127,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); @@ -174,7 +174,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!( @@ -189,7 +204,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| { @@ -205,7 +220,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(); @@ -216,15 +231,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 80ff28bab5c..7360992459b 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -2339,10 +2339,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" @@ -2378,9 +2388,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..3984d5dae4f 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), ], ); } @@ -5805,7 +5906,7 @@ dependencies = [ name = "level2" version = "0.0.1" source = "{index}" -checksum = [..] +checksum = "[..]" "# ); @@ -5815,7 +5916,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 - ), + +"##]], )], ); }