diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-06-17 16:16:46 +0200 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2025-06-19 06:56:26 +0200 |
| commit | 21d21d5f81d6d0ac7e58275e40e982550951ec86 (patch) | |
| tree | aeeb6148674572cc215ce7647c94307e1459d0de /src | |
| parent | 8c281613739436582f979d228be4cc1d4f7afa3d (diff) | |
| download | rust-21d21d5f81d6d0ac7e58275e40e982550951ec86.tar.gz rust-21d21d5f81d6d0ac7e58275e40e982550951ec86.zip | |
Normalize host target in snapshot tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/src/core/builder/tests.rs | 48 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/tests/mod.rs | 43 |
2 files changed, 74 insertions, 17 deletions
diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 6268a2b59d6..f45afe0c789 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -9,6 +9,7 @@ use crate::Flags; use crate::core::build_steps::doc::DocumentationFormat; use crate::core::config::Config; use crate::utils::cache::ExecutedStep; +use crate::utils::helpers::get_host_target; use crate::utils::tests::git::{GitCtx, git_test}; static TEST_TRIPLE_1: &str = "i686-unknown-haiku"; @@ -1236,24 +1237,38 @@ fn any_debug() { /// The staging tests use insta for snapshot testing. /// See bootstrap's README on how to bless the snapshots. mod staging { + use crate::Build; + use crate::core::builder::Builder; use crate::core::builder::tests::{ TEST_TRIPLE_1, configure, configure_with_args, render_steps, run_build, }; + use crate::utils::tests::ConfigBuilder; #[test] fn build_compiler_stage_1() { - let mut cache = run_build( - &["compiler".into()], - configure_with_args(&["build", "--stage", "1"], &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]), - ); - let steps = cache.into_executed_steps(); - insta::assert_snapshot!(render_steps(&steps), @r" - [build] rustc 0 <target1> -> std 0 <target1> - [build] llvm <target1> - [build] rustc 0 <target1> -> rustc 1 <target1> - [build] rustc 0 <target1> -> rustc 1 <target1> + insta::assert_snapshot!( + ConfigBuilder::build() + .path("compiler") + .stage(1) + .get_steps(), @r" + [build] rustc 0 <host> -> std 0 <host> + [build] llvm <host> + [build] rustc 0 <host> -> rustc 1 <host> + [build] rustc 0 <host> -> rustc 1 <host> "); } + + impl ConfigBuilder { + fn get_steps(self) -> String { + let config = self.create_config(); + + let kind = config.cmd.kind(); + let build = Build::new(config); + let builder = Builder::new(&build); + builder.run_step_descriptions(&Builder::get_step_descriptions(kind), &builder.paths); + render_steps(&builder.cache.into_executed_steps()) + } + } } /// Renders the executed bootstrap steps for usage in snapshot tests with insta. @@ -1275,18 +1290,17 @@ fn render_steps(steps: &[ExecutedStep]) -> String { } let stage = if let Some(stage) = metadata.stage { format!("{stage} ") } else { "".to_string() }; - write!(record, "{} {stage}<{}>", metadata.name, metadata.target); + write!(record, "{} {stage}<{}>", metadata.name, normalize_target(metadata.target)); Some(record) }) - .map(|line| { - line.replace(TEST_TRIPLE_1, "target1") - .replace(TEST_TRIPLE_2, "target2") - .replace(TEST_TRIPLE_3, "target3") - }) .collect::<Vec<_>>() .join("\n") } +fn normalize_target(target: TargetSelection) -> String { + target.to_string().replace(&get_host_target().to_string(), "host") +} + fn render_compiler(compiler: Compiler) -> String { - format!("rustc {} <{}>", compiler.stage, compiler.host) + format!("rustc {} <{}>", compiler.stage, normalize_target(compiler.host)) } diff --git a/src/bootstrap/src/utils/tests/mod.rs b/src/bootstrap/src/utils/tests/mod.rs index 73c500f6e36..ec6293f3c2c 100644 --- a/src/bootstrap/src/utils/tests/mod.rs +++ b/src/bootstrap/src/utils/tests/mod.rs @@ -1,3 +1,46 @@ //! This module contains shared utilities for bootstrap tests. +use crate::core::builder::Builder; +use crate::core::config::DryRun; +use crate::{Build, Config, Flags}; + pub mod git; + +/// Used to configure an invocation of bootstrap. +/// Currently runs in the rustc checkout, long-term it should be switched +/// to run in a (cache-primed) temporary directory instead. +pub struct ConfigBuilder { + args: Vec<String>, +} + +impl ConfigBuilder { + pub fn from_args(args: &[&str]) -> Self { + Self::new(args) + } + + pub fn build() -> Self { + Self::new(&["build"]) + } + + pub fn path(mut self, path: &str) -> Self { + self.args.push(path.to_string()); + self + } + + pub fn stage(mut self, stage: u32) -> Self { + self.args.push("--stage".to_string()); + self.args.push(stage.to_string()); + self + } + + fn new(args: &[&str]) -> Self { + Self { args: args.iter().copied().map(String::from).collect() } + } + + pub fn create_config(mut self) -> Config { + let mut config = Config::parse(Flags::parse(&self.args)); + // Run in dry-check, otherwise the test would be too slow + config.set_dry_run(DryRun::SelfCheck); + config + } +} |
