From 6e346a20d7d3094b03e516f0bfebbcd7c1615ce1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 3 Jun 2024 09:40:09 -0500 Subject: [PATCH] test(vendor): Ensure order is consistent --- tests/testsuite/vendor.rs | 127 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index e5e56b396bf6..1deb47f2b046 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -6,8 +6,10 @@ use std::fs; +use cargo_test_support::compare::assert_e2e; use cargo_test_support::git; use cargo_test_support::registry::{self, Package, RegistryBuilder}; +use cargo_test_support::str; use cargo_test_support::{basic_lib_manifest, basic_manifest, paths, project, Project}; #[cargo_test] @@ -862,6 +864,131 @@ fn git_complex() { .run(); } +#[cargo_test] +fn git_deterministic() { + let git_dep = git::new("git_dep", |p| { + p.file( + "Cargo.toml", + r#" + [package] + name = "git_dep" + version = "0.0.1" + edition = "2021" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + + [[example]] + name = "c" + + [[example]] + name = "b" + + [[example]] + name = "a" + "#, + ) + .file("src/lib.rs", "") + .file("examples/z.rs", "fn main() {}") + .file("examples/y.rs", "fn main() {}") + .file("examples/x.rs", "fn main() {}") + .file("examples/c.rs", "fn main() {}") + .file("examples/b.rs", "fn main() {}") + .file("examples/a.rs", "fn main() {}") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + git_dep = {{ git = '{}' }} + "#, + git_dep.url() + ), + ) + .file("src/lib.rs", "") + .build(); + + let output = p + .cargo("vendor --respect-source-config") + .exec_with_output() + .unwrap(); + let output = String::from_utf8(output.stdout).unwrap(); + p.change_file(".cargo/config.toml", &output); + + let git_dep_manifest = p.read_file("vendor/git_dep/Cargo.toml"); + assert_e2e().eq( + git_dep_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. + +bin = [] +test = [] +bench = [] + +[package] +edition = "2021" +name = "git_dep" +version = "0.0.1" +authors = [] +build = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "git_dep" +path = [..] + +[[example]] +name = "c" +path = [..] + +[[example]] +name = "b" +path = [..] + +[[example]] +name = "a" +path = [..] + +[[example]] +name = "z" +path = [..] + +[[example]] +name = "x" +path = [..] + +[[example]] +name = "y" +path = [..] + +"##]], + ); +} + #[cargo_test] fn depend_on_vendor_dir_not_deleted() { let p = project()