Skip to content

Commit c4da0c5

Browse files
committed
Auto merge of #9246 - ehuss:fix-filter_platform, r=Eh2406
Fix filter_platform to run on targets other than x86. The issue is that the `dependencies` array was hard-coded to be sorted by `[none, 'cfg(foobar)', 'wasm32-unknown-unknown', host_target]` where `host_target` is usually a target that starts with "x". However, running the test on a target that sorts less than `wasm32` causes the test to fail (such as `aarch64`). The order of arrays used to be ignored until #8489. The solution here is to just sort the expected order of dependencies. An alternate solution would be to extend `with_json` with more options on comparison (such as ignoring array order), but this seems simple enough. Fixes #9238
2 parents 970bc67 + 95827ad commit c4da0c5

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

tests/testsuite/metadata.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,7 @@ fn filter_platform() {
20572057
// Just needs to be a valid target that is different from host.
20582058
// Presumably nobody runs these tests on wasm. 🙃
20592059
let alt_target = "wasm32-unknown-unknown";
2060+
let host_target = rustc_host();
20602061
let p = project()
20612062
.file(
20622063
"Cargo.toml",
@@ -2078,8 +2079,7 @@ fn filter_platform() {
20782079
[target.'cfg(foobar)'.dependencies]
20792080
cfg-dep = "0.0.1"
20802081
"#,
2081-
rustc_host(),
2082-
alt_target
2082+
host_target, alt_target
20832083
),
20842084
)
20852085
.file("src/lib.rs", "")
@@ -2253,16 +2253,10 @@ fn filter_platform() {
22532253
}
22542254
"#;
22552255

2256-
let foo = r#"
2257-
{
2258-
"name": "foo",
2259-
"version": "0.1.0",
2260-
"id": "foo 0.1.0 (path+file:[..]foo)",
2261-
"license": null,
2262-
"license_file": null,
2263-
"description": null,
2264-
"source": null,
2265-
"dependencies": [
2256+
// The dependencies are stored in sorted order by target and then by name.
2257+
// Since the testsuite may run on different targets, this needs to be
2258+
// sorted before it can be compared.
2259+
let mut foo_deps = serde_json::json!([
22662260
{
22672261
"name": "normal-dep",
22682262
"source": "registry+https://github.com/rust-lang/crates.io-index",
@@ -2296,7 +2290,7 @@ fn filter_platform() {
22962290
"optional": false,
22972291
"uses_default_features": true,
22982292
"features": [],
2299-
"target": "$ALT_TRIPLE",
2293+
"target": alt_target,
23002294
"registry": null
23012295
},
23022296
{
@@ -2308,10 +2302,30 @@ fn filter_platform() {
23082302
"optional": false,
23092303
"uses_default_features": true,
23102304
"features": [],
2311-
"target": "$HOST_TRIPLE",
2305+
"target": host_target,
23122306
"registry": null
23132307
}
2314-
],
2308+
]);
2309+
foo_deps.as_array_mut().unwrap().sort_by(|a, b| {
2310+
// This really should be `rename`, but not needed here.
2311+
// Also, sorting on `name` isn't really necessary since this test
2312+
// only has one package per target, but leaving it here to be safe.
2313+
let a = (a["target"].as_str(), a["name"].as_str());
2314+
let b = (b["target"].as_str(), b["name"].as_str());
2315+
a.cmp(&b)
2316+
});
2317+
2318+
let foo = r#"
2319+
{
2320+
"name": "foo",
2321+
"version": "0.1.0",
2322+
"id": "foo 0.1.0 (path+file:[..]foo)",
2323+
"license": null,
2324+
"license_file": null,
2325+
"description": null,
2326+
"source": null,
2327+
"dependencies":
2328+
$FOO_DEPS,
23152329
"targets": [
23162330
{
23172331
"kind": [
@@ -2344,7 +2358,8 @@ fn filter_platform() {
23442358
}
23452359
"#
23462360
.replace("$ALT_TRIPLE", alt_target)
2347-
.replace("$HOST_TRIPLE", &rustc_host());
2361+
.replace("$HOST_TRIPLE", &host_target)
2362+
.replace("$FOO_DEPS", &foo_deps.to_string());
23482363

23492364
// We're going to be checking that we don't download excessively,
23502365
// so we need to ensure that downloads will happen.
@@ -2468,7 +2483,7 @@ fn filter_platform() {
24682483
}
24692484
"#
24702485
.replace("$ALT_TRIPLE", alt_target)
2471-
.replace("$HOST_TRIPLE", &rustc_host())
2486+
.replace("$HOST_TRIPLE", &host_target)
24722487
.replace("$ALT_DEP", alt_dep)
24732488
.replace("$CFG_DEP", cfg_dep)
24742489
.replace("$HOST_DEP", host_dep)
@@ -2562,7 +2577,7 @@ fn filter_platform() {
25622577

25632578
// Filter on host, removes alt and cfg.
25642579
p.cargo("metadata --filter-platform")
2565-
.arg(rustc_host())
2580+
.arg(&host_target)
25662581
.with_stderr_unordered(
25672582
"\
25682583
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
@@ -2633,7 +2648,7 @@ fn filter_platform() {
26332648
"metadata": null
26342649
}
26352650
"#
2636-
.replace("$HOST_TRIPLE", &rustc_host())
2651+
.replace("$HOST_TRIPLE", &host_target)
26372652
.replace("$HOST_DEP", host_dep)
26382653
.replace("$NORMAL_DEP", normal_dep)
26392654
.replace("$FOO", &foo),
@@ -2643,7 +2658,7 @@ fn filter_platform() {
26432658

26442659
// Filter host with cfg, removes alt only
26452660
p.cargo("metadata --filter-platform")
2646-
.arg(rustc_host())
2661+
.arg(&host_target)
26472662
.env("RUSTFLAGS", "--cfg=foobar")
26482663
.with_stderr_unordered(
26492664
"\
@@ -2734,7 +2749,7 @@ fn filter_platform() {
27342749
"metadata": null
27352750
}
27362751
"#
2737-
.replace("$HOST_TRIPLE", &rustc_host())
2752+
.replace("$HOST_TRIPLE", &host_target)
27382753
.replace("$CFG_DEP", cfg_dep)
27392754
.replace("$HOST_DEP", host_dep)
27402755
.replace("$NORMAL_DEP", normal_dep)

0 commit comments

Comments
 (0)