From c09ba9c7d4346fefc894643cd829db274a1a80b5 Mon Sep 17 00:00:00 2001 From: Harry Moulton Date: Fri, 31 May 2024 15:44:23 +0100 Subject: [PATCH] Add new test case 'test_std_on_unsupported_target' Add a new test case to check cargo handles building a target which doesn't support the standard library properly. --- tests/testsuite/standard_lib.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index 863631a00a66..32a7bd4cab9f 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -162,6 +162,7 @@ trait BuildStd: Sized { fn build_std(&mut self, setup: &Setup) -> &mut Self; fn build_std_arg(&mut self, setup: &Setup, arg: &str) -> &mut Self; fn target_host(&mut self) -> &mut Self; + fn target(&mut self, target: &str) -> &mut Self; } impl BuildStd for Execs { @@ -181,6 +182,11 @@ impl BuildStd for Execs { self.arg("--target").arg(rustc_host()); self } + + fn target(&mut self, target: &str) -> &mut Self { + self.arg("--target").arg(target); + self + } } #[cargo_test(build_std_mock)] @@ -321,6 +327,33 @@ fn check_core() { .run(); } +#[cargo_test(build_std_mock)] +fn test_std_on_unsupported_target() { + let setup = setup(); + + let p = project() + .file( + "src/main.rs", + r#" + fn main() { + println!("hello"); + } + "#, + ) + .build(); + + p.cargo("build") + .build_std(&setup) + .target("aarch64-unknown-none") + .with_status(101) + .with_stderr( + "\ +error: building std is not supported on this target: [..] +", + ) + .run(); +} + #[cargo_test(build_std_mock)] fn depend_same_as_std() { let setup = setup();