diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index d0748189b..280abb19f 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1444,7 +1444,7 @@ fn lines_match_works() { /// You can use `[..]` wildcard in strings (useful for OS-dependent things such /// as paths). You can use a `"{...}"` string literal as a wildcard for /// arbitrary nested JSON (useful for parts of object emitted by other programs -/// (e.g., rustc) rather than Cargo itself). Arrays are sorted before comparison. +/// (e.g., rustc) rather than Cargo itself). pub fn find_json_mismatch(expected: &Value, actual: &Value) -> Result<(), String> { match find_json_mismatch_r(expected, actual) { Some((expected_part, actual_part)) => Err(format!( @@ -1472,26 +1472,10 @@ fn find_json_mismatch_r<'a>( return Some((expected, actual)); } - let mut l = l.iter().collect::>(); - let mut r = r.iter().collect::>(); - - l.retain( - |l| match r.iter().position(|r| find_json_mismatch_r(l, r).is_none()) { - Some(i) => { - r.remove(i); - false - } - None => true, - }, - ); - - if !l.is_empty() { - assert!(!r.is_empty()); - Some((l[0], r[0])) - } else { - assert_eq!(r.len(), 0); - None - } + l.iter() + .zip(r.iter()) + .filter_map(|(l, r)| find_json_mismatch_r(l, r)) + .next() } (&Object(ref l), &Object(ref r)) => { let same_keys = l.len() == r.len() && l.keys().all(|k| r.contains_key(k)); diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index 51fe4e725..2dc179378 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -190,7 +190,8 @@ fn build_resolve_graph_r( } }) .filter_map(|(dep_id, deps)| { - let dep_kinds: Vec<_> = deps.iter().map(DepKindInfo::from).collect(); + let mut dep_kinds: Vec<_> = deps.iter().map(DepKindInfo::from).collect(); + dep_kinds.sort(); package_map .get(&dep_id) .and_then(|pkg| pkg.targets().iter().find(|t| t.is_lib())) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index e328fef3e..f9129e284 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -836,28 +836,6 @@ fn alt_reg_metadata() { r#" { "packages": [ - { - "name": "altdep2", - "version": "0.0.1", - "id": "altdep2 0.0.1 (registry+file:[..]/alternative-registry)", - "license": null, - "license_file": null, - "description": null, - "source": "registry+file:[..]/alternative-registry", - "dependencies": [], - "targets": "{...}", - "features": {}, - "manifest_path": "[..]/altdep2-0.0.1/Cargo.toml", - "metadata": null, - "publish": null, - "authors": [], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2015", - "links": null - }, { "name": "altdep", "version": "0.0.1", @@ -893,6 +871,50 @@ fn alt_reg_metadata() { "edition": "2015", "links": null }, + { + "name": "altdep2", + "version": "0.0.1", + "id": "altdep2 0.0.1 (registry+file:[..]/alternative-registry)", + "license": null, + "license_file": null, + "description": null, + "source": "registry+file:[..]/alternative-registry", + "dependencies": [], + "targets": "{...}", + "features": {}, + "manifest_path": "[..]/altdep2-0.0.1/Cargo.toml", + "metadata": null, + "publish": null, + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "edition": "2015", + "links": null + }, + { + "name": "bar", + "version": "0.0.1", + "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "license": null, + "license_file": null, + "description": null, + "source": "registry+https://github.com/rust-lang/crates.io-index", + "dependencies": [], + "targets": "{...}", + "features": {}, + "manifest_path": "[..]/bar-0.0.1/Cargo.toml", + "metadata": null, + "publish": null, + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "edition": "2015", + "links": null + }, { "name": "foo", "version": "0.0.1", @@ -974,28 +996,6 @@ fn alt_reg_metadata() { "repository": null, "edition": "2015", "links": null - }, - { - "name": "bar", - "version": "0.0.1", - "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "license": null, - "license_file": null, - "description": null, - "source": "registry+https://github.com/rust-lang/crates.io-index", - "dependencies": [], - "targets": "{...}", - "features": {}, - "manifest_path": "[..]/bar-0.0.1/Cargo.toml", - "metadata": null, - "publish": null, - "authors": [], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2015", - "links": null } ], "workspace_members": [ @@ -1055,6 +1055,41 @@ fn unknown_registry() { r#" { "packages": [ + { + "name": "bar", + "version": "0.0.1", + "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "license": null, + "license_file": null, + "description": null, + "source": "registry+https://github.com/rust-lang/crates.io-index", + "dependencies": [ + { + "name": "baz", + "source": "registry+file://[..]/alternative-registry", + "req": "^0.0.1", + "kind": null, + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": "file:[..]/alternative-registry" + } + ], + "targets": "{...}", + "features": {}, + "manifest_path": "[..]", + "metadata": null, + "publish": null, + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "edition": "2015", + "links": null + }, { "name": "baz", "version": "0.0.1", @@ -1111,41 +1146,6 @@ fn unknown_registry() { "repository": null, "edition": "2015", "links": null - }, - { - "name": "bar", - "version": "0.0.1", - "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "license": null, - "license_file": null, - "description": null, - "source": "registry+https://github.com/rust-lang/crates.io-index", - "dependencies": [ - { - "name": "baz", - "source": "registry+file://[..]/alternative-registry", - "req": "^0.0.1", - "kind": null, - "rename": null, - "optional": false, - "uses_default_features": true, - "features": [], - "target": null, - "registry": "file:[..]/alternative-registry" - } - ], - "targets": "{...}", - "features": {}, - "manifest_path": "[..]", - "metadata": null, - "publish": null, - "authors": [], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "edition": "2015", - "links": null } ], "workspace_members": [ diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs index 44e4d6af7..22afcf6c8 100644 --- a/tests/testsuite/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -290,6 +290,54 @@ fn cargo_metadata_with_deps_and_version() { r#" { "packages": [ + { + "authors": [], + "categories": [], + "dependencies": [ + { + "features": [], + "kind": null, + "name": "baz", + "optional": false, + "registry": null, + "rename": null, + "req": "^0.0.1", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "target": null, + "uses_default_features": true + } + ], + "description": null, + "edition": "2015", + "features": {}, + "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "keywords": [], + "license": null, + "license_file": null, + "links": null, + "manifest_path": "[..]Cargo.toml", + "metadata": null, + "publish": null, + "name": "bar", + "readme": null, + "repository": null, + "source": "registry+https://github.com/rust-lang/crates.io-index", + "targets": [ + { + "crate_types": [ + "lib" + ], + "doctest": true, + "edition": "2015", + "kind": [ + "lib" + ], + "name": "bar", + "src_path": "[..]src/lib.rs" + } + ], + "version": "0.0.1" + }, { "authors": [], "categories": [], @@ -419,69 +467,34 @@ fn cargo_metadata_with_deps_and_version() { } ], "version": "0.0.1" - }, - { - "authors": [], - "categories": [], - "dependencies": [ - { - "features": [], - "kind": null, - "name": "baz", - "optional": false, - "registry": null, - "rename": null, - "req": "^0.0.1", - "source": "registry+https://github.com/rust-lang/crates.io-index", - "target": null, - "uses_default_features": true - } - ], - "description": null, - "edition": "2015", - "features": {}, - "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keywords": [], - "license": null, - "license_file": null, - "links": null, - "manifest_path": "[..]Cargo.toml", - "metadata": null, - "publish": null, - "name": "bar", - "readme": null, - "repository": null, - "source": "registry+https://github.com/rust-lang/crates.io-index", - "targets": [ - { - "crate_types": [ - "lib" - ], - "doctest": true, - "edition": "2015", - "kind": [ - "lib" - ], - "name": "bar", - "src_path": "[..]src/lib.rs" - } - ], - "version": "0.0.1" } ], "resolve": { "nodes": [ { - "dependencies": [], - "deps": [], + "dependencies": [ + "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" + ], + "deps": [ + { + "dep_kinds": [ + { + "kind": null, + "target": null + } + ], + "name": "baz", + "pkg": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" + } + ], "features": [], - "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" + "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" }, { "dependencies": [], "deps": [], "features": [], - "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" + "id": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" }, { "dependencies": [ @@ -514,23 +527,10 @@ fn cargo_metadata_with_deps_and_version() { "id": "foo 0.5.0 (path+file:[..]foo)" }, { - "dependencies": [ - "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" - ], - "deps": [ - { - "dep_kinds": [ - { - "kind": null, - "target": null - } - ], - "name": "baz", - "pkg": "baz 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" - } - ], + "dependencies": [], + "deps": [], "features": [], - "id": "bar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" + "id": "foobar 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" } ], "root": "foo 0.5.0 (path+file:[..]foo)" @@ -816,20 +816,20 @@ fn workspace_metadata() { "publish": null } ], - "workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"], + "workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"], "resolve": { "nodes": [ { "dependencies": [], "deps": [], "features": [], - "id": "baz 0.5.0 (path+file:[..]baz)" + "id": "bar 0.5.0 (path+file:[..]bar)" }, { "dependencies": [], "deps": [], "features": [], - "id": "bar 0.5.0 (path+file:[..]bar)" + "id": "baz 0.5.0 (path+file:[..]baz)" } ], "root": null @@ -937,7 +937,7 @@ fn workspace_metadata_no_deps() { "publish": null } ], - "workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"], + "workspace_members": ["bar 0.5.0 (path+file:[..]bar)", "baz 0.5.0 (path+file:[..]baz)"], "resolve": null, "target_directory": "[..]foo/target", "version": 1, @@ -1557,66 +1557,6 @@ fn rename_dependency() { r#" { "packages": [ - { - "authors": [], - "categories": [], - "dependencies": [ - { - "features": [], - "kind": null, - "name": "bar", - "optional": false, - "rename": null, - "registry": null, - "req": "^0.1.0", - "source": "registry+https://github.com/rust-lang/crates.io-index", - "target": null, - "uses_default_features": true - }, - { - "features": [], - "kind": null, - "name": "bar", - "optional": false, - "rename": "baz", - "registry": null, - "req": "^0.2.0", - "source": "registry+https://github.com/rust-lang/crates.io-index", - "target": null, - "uses_default_features": true - } - ], - "description": null, - "edition": "2015", - "features": {}, - "id": "foo 0.0.1[..]", - "keywords": [], - "license": null, - "license_file": null, - "links": null, - "manifest_path": "[..]", - "metadata": null, - "publish": null, - "name": "foo", - "readme": null, - "repository": null, - "source": null, - "targets": [ - { - "crate_types": [ - "lib" - ], - "doctest": true, - "edition": "2015", - "kind": [ - "lib" - ], - "name": "foo", - "src_path": "[..]" - } - ], - "version": "0.0.1" - }, { "authors": [], "categories": [], @@ -1686,6 +1626,66 @@ fn rename_dependency() { } ], "version": "0.2.0" + }, + { + "authors": [], + "categories": [], + "dependencies": [ + { + "features": [], + "kind": null, + "name": "bar", + "optional": false, + "rename": null, + "registry": null, + "req": "^0.1.0", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "target": null, + "uses_default_features": true + }, + { + "features": [], + "kind": null, + "name": "bar", + "optional": false, + "rename": "baz", + "registry": null, + "req": "^0.2.0", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "target": null, + "uses_default_features": true + } + ], + "description": null, + "edition": "2015", + "features": {}, + "id": "foo 0.0.1[..]", + "keywords": [], + "license": null, + "license_file": null, + "links": null, + "manifest_path": "[..]", + "metadata": null, + "publish": null, + "name": "foo", + "readme": null, + "repository": null, + "source": null, + "targets": [ + { + "crate_types": [ + "lib" + ], + "doctest": true, + "edition": "2015", + "kind": [ + "lib" + ], + "name": "foo", + "src_path": "[..]" + } + ], + "version": "0.0.1" } ], "resolve": { @@ -1694,13 +1694,13 @@ fn rename_dependency() { "dependencies": [], "deps": [], "features": [], - "id": "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" + "id": "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" }, { "dependencies": [], "deps": [], "features": [], - "id": "bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" + "id": "bar 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" }, { "dependencies": [ @@ -2009,7 +2009,7 @@ fn filter_platform() { "repository": null, "edition": "2015", "links": null - }, + } "#; let cfg_dep = r#" @@ -2047,7 +2047,7 @@ fn filter_platform() { "repository": null, "edition": "2015", "links": null - }, + } "#; let host_dep = r#" @@ -2085,7 +2085,7 @@ fn filter_platform() { "repository": null, "edition": "2015", "links": null - }, + } "#; let normal_dep = r#" @@ -2123,7 +2123,7 @@ fn filter_platform() { "repository": null, "edition": "2015", "links": null - }, + } "#; let foo = r#" @@ -2221,11 +2221,11 @@ fn filter_platform() { &r#" { "packages": [ - $ALT_DEP - $CFG_DEP - $HOST_DEP + $ALT_DEP, + $CFG_DEP, + $FOO, + $HOST_DEP, $NORMAL_DEP - $FOO ], "workspace_members": [ "foo 0.1.0 (path+file:[..]foo)" @@ -2334,9 +2334,9 @@ fn filter_platform() { &r#" { "packages": [ - $ALT_DEP + $ALT_DEP, + $FOO, $NORMAL_DEP - $FOO ], "workspace_members": "{...}", "resolve": { @@ -2406,9 +2406,9 @@ fn filter_platform() { &r#" { "packages": [ - $HOST_DEP + $FOO, + $HOST_DEP, $NORMAL_DEP - $FOO ], "workspace_members": "{...}", "resolve": { @@ -2479,10 +2479,10 @@ fn filter_platform() { &r#" { "packages": [ - $CFG_DEP - $HOST_DEP + $CFG_DEP, + $FOO, + $HOST_DEP, $NORMAL_DEP - $FOO ], "workspace_members": "{...}", "resolve": { @@ -2720,12 +2720,6 @@ fn dep_kinds_workspace() { "metadata": null, "resolve": { "nodes": [ - { - "id": "dep 0.5.0 (path+file://[..]/foo/dep)", - "dependencies": [], - "deps": [], - "features": [] - }, { "id": "bar 0.1.0 (path+file://[..]/foo/bar)", "dependencies": [ @@ -2745,6 +2739,12 @@ fn dep_kinds_workspace() { ], "features": [] }, + { + "id": "dep 0.5.0 (path+file://[..]/foo/dep)", + "dependencies": [], + "deps": [], + "features": [] + }, { "id": "foo 0.1.0 (path+file://[..]/foo)", "dependencies": [ diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index dc5b78415..5e3919cdc 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -430,41 +430,6 @@ fn update_precise_first_run() { .with_json( r#"{ "packages": [ - { - "authors": [], - "categories": [], - "dependencies": [], - "description": null, - "edition": "2015", - "features": {}, - "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "keywords": [], - "license": null, - "license_file": null, - "links": null, - "manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml", - "metadata": null, - "publish": null, - "name": "serde", - "readme": null, - "repository": null, - "source": "registry+https://github.com/rust-lang/crates.io-index", - "targets": [ - { - "crate_types": [ - "lib" - ], - "doctest": true, - "edition": "2015", - "kind": [ - "lib" - ], - "name": "serde", - "src_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/src/lib.rs" - } - ], - "version": "0.2.0" - }, { "authors": [], "categories": [], @@ -512,6 +477,41 @@ fn update_precise_first_run() { } ], "version": "0.0.1" + }, + { + "authors": [], + "categories": [], + "dependencies": [], + "description": null, + "edition": "2015", + "features": {}, + "id": "serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keywords": [], + "license": null, + "license_file": null, + "links": null, + "manifest_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/Cargo.toml", + "metadata": null, + "publish": null, + "name": "serde", + "readme": null, + "repository": null, + "source": "registry+https://github.com/rust-lang/crates.io-index", + "targets": [ + { + "crate_types": [ + "lib" + ], + "doctest": true, + "edition": "2015", + "kind": [ + "lib" + ], + "name": "serde", + "src_path": "[..]/home/.cargo/registry/src/-[..]/serde-0.2.0/src/lib.rs" + } + ], + "version": "0.2.0" } ], "resolve": {