Skip to content

Commit a7eb8e2

Browse files
committed
[nextest-runner] add test for custom platforms + cfg(unix)
Previous versions of target-spec didn't deserialize the `target_family` field correctly.
1 parent 5161413 commit a7eb8e2

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

nextest-runner/src/config/overrides.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,4 +1202,57 @@ mod tests {
12021202
}
12031203
};
12041204
}
1205+
1206+
/// Test that `cfg(unix)` works with a custom platform.
1207+
///
1208+
/// This was broken with older versions of target-spec.
1209+
#[test]
1210+
fn cfg_unix_with_custom_platform() {
1211+
let config_contents = indoc! {r#"
1212+
[[profile.default.overrides]]
1213+
platform = { host = "cfg(unix)" }
1214+
filter = "test(test)"
1215+
retries = 5
1216+
"#};
1217+
1218+
let workspace_dir = tempdir().unwrap();
1219+
1220+
let graph = temp_workspace(workspace_dir.path(), config_contents);
1221+
let package_id = graph.workspace().iter().next().unwrap().id();
1222+
1223+
let nextest_config = NextestConfig::from_sources(
1224+
graph.workspace().root(),
1225+
&graph,
1226+
None,
1227+
&[][..],
1228+
&Default::default(),
1229+
)
1230+
.expect("config is valid");
1231+
1232+
let build_platforms = custom_build_platforms(workspace_dir.path());
1233+
1234+
let profile = nextest_config
1235+
.profile("default")
1236+
.expect("valid profile name")
1237+
.apply_build_platforms(&build_platforms);
1238+
1239+
// Check that the override is correctly applied.
1240+
let target_binary_query = binary_query(
1241+
&graph,
1242+
package_id,
1243+
"lib",
1244+
"my-binary",
1245+
BuildPlatform::Target,
1246+
);
1247+
let query = TestQuery {
1248+
binary_query: target_binary_query.to_query(),
1249+
test_name: "test",
1250+
};
1251+
let overrides = profile.settings_for(&query);
1252+
assert_eq!(
1253+
overrides.retries(),
1254+
RetryPolicy::new_without_delay(5),
1255+
"retries applied to custom platform"
1256+
);
1257+
}
12051258
}

nextest-runner/src/config/test_helpers.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

44
use crate::{
5-
cargo_config::{TargetDefinitionLocation, TargetTriple, TargetTripleSource},
5+
cargo_config::{CargoConfigs, TargetDefinitionLocation, TargetTriple, TargetTripleSource},
66
config::{CustomTestGroup, TestGroup},
77
platform::{BuildPlatforms, HostPlatform, PlatformLibdir, TargetPlatform},
88
};
@@ -104,6 +104,53 @@ pub(super) fn build_platforms() -> BuildPlatforms {
104104
}
105105
}
106106

107+
// XXX: do we need workspace_dir at all? Seems unnecessary.
108+
pub(super) fn custom_build_platforms(workspace_dir: &Utf8Path) -> BuildPlatforms {
109+
let configs = CargoConfigs::new_with_isolation(
110+
Vec::<String>::new(),
111+
workspace_dir,
112+
workspace_dir,
113+
Vec::new(),
114+
)
115+
.unwrap();
116+
117+
let mut fixture =
118+
Utf8PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect("manifest dir is available"));
119+
fixture.pop();
120+
fixture.push("fixtures/custom-target/my-target.json");
121+
122+
let triple = TargetTriple::find(&configs, Some(fixture.as_str()))
123+
.expect("custom platform parsed")
124+
.expect("custom platform found");
125+
assert!(
126+
triple.platform.is_custom(),
127+
"returned triple should be custom (was: {triple:?}"
128+
);
129+
assert_eq!(
130+
triple.platform.triple_str(),
131+
"my-target",
132+
"triple_str matches"
133+
);
134+
135+
let host = HostPlatform {
136+
platform: Platform::new("x86_64-unknown-linux-gnu", TargetFeatures::Unknown).unwrap(),
137+
libdir: PlatformLibdir::Available(
138+
Utf8PathBuf::from("/home/fake/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib")
139+
),
140+
};
141+
let target = TargetPlatform {
142+
triple,
143+
libdir: PlatformLibdir::Available(Utf8PathBuf::from(
144+
"/home/fake/.rustup/toolchains/my-target/lib/rustlib/my-target/lib",
145+
)),
146+
};
147+
148+
BuildPlatforms {
149+
host,
150+
target: Some(target),
151+
}
152+
}
153+
107154
pub(super) fn test_group(name: &str) -> TestGroup {
108155
TestGroup::Custom(custom_test_group(name))
109156
}

0 commit comments

Comments
 (0)