|
| 1 | +//! Standard library tests. |
| 2 | +
|
| 3 | +use std::env; |
| 4 | +use std::path::PathBuf; |
| 5 | + |
| 6 | +use super::test_helpers::run_cargo_test; |
| 7 | +use crate::Mode; |
| 8 | +use crate::core::build_steps::tool::{self, SourceType}; |
| 9 | +use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; |
| 10 | +use crate::core::config::TargetSelection; |
| 11 | + |
| 12 | +// FIXME(#137178): `Crate` is also used for standard library crate tests? |
| 13 | + |
| 14 | +// FIXME(#137178): break up `TestFloatParse` into two steps: one for testing the tool itself, and |
| 15 | +// one for testing std float parsing. |
| 16 | + |
| 17 | +/// Test step that does two things: |
| 18 | +/// - Runs `cargo test` for the `src/etc/test-float-parse` tool. |
| 19 | +/// - Invokes the `test-float-parse` tool to test the standard library's float parsing routines. |
| 20 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 21 | +pub struct TestFloatParse { |
| 22 | + path: PathBuf, |
| 23 | + host: TargetSelection, |
| 24 | +} |
| 25 | + |
| 26 | +impl Step for TestFloatParse { |
| 27 | + type Output = (); |
| 28 | + const ONLY_HOSTS: bool = true; |
| 29 | + const DEFAULT: bool = true; |
| 30 | + |
| 31 | + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
| 32 | + run.path("src/etc/test-float-parse") |
| 33 | + } |
| 34 | + |
| 35 | + fn make_run(run: RunConfig<'_>) { |
| 36 | + for path in run.paths { |
| 37 | + let path = path.assert_single_path().path.clone(); |
| 38 | + run.builder.ensure(Self { path, host: run.target }); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + fn run(self, builder: &Builder<'_>) { |
| 43 | + let bootstrap_host = builder.config.build; |
| 44 | + let compiler = builder.compiler(builder.top_stage, bootstrap_host); |
| 45 | + let path = self.path.to_str().unwrap(); |
| 46 | + let crate_name = self.path.components().last().unwrap().as_os_str().to_str().unwrap(); |
| 47 | + |
| 48 | + builder.ensure(tool::TestFloatParse { host: self.host }); |
| 49 | + |
| 50 | + // Run any unit tests in the crate |
| 51 | + let cargo_test = tool::prepare_tool_cargo( |
| 52 | + builder, |
| 53 | + compiler, |
| 54 | + Mode::ToolStd, |
| 55 | + bootstrap_host, |
| 56 | + Kind::Test, |
| 57 | + path, |
| 58 | + SourceType::InTree, |
| 59 | + &[], |
| 60 | + ); |
| 61 | + |
| 62 | + run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder); |
| 63 | + |
| 64 | + // Run the actual parse tests. |
| 65 | + let mut cargo_run = tool::prepare_tool_cargo( |
| 66 | + builder, |
| 67 | + compiler, |
| 68 | + Mode::ToolStd, |
| 69 | + bootstrap_host, |
| 70 | + Kind::Run, |
| 71 | + path, |
| 72 | + SourceType::InTree, |
| 73 | + &[], |
| 74 | + ); |
| 75 | + |
| 76 | + if !matches!(env::var("FLOAT_PARSE_TESTS_NO_SKIP_HUGE").as_deref(), Ok("1") | Ok("true")) { |
| 77 | + cargo_run.args(["--", "--skip-huge"]); |
| 78 | + } |
| 79 | + |
| 80 | + cargo_run.into_cmd().run(builder); |
| 81 | + } |
| 82 | +} |
0 commit comments