mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-29 20:20:59 +03:00
refactor tests to use TestCtx
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
use crate::core::config::Config;
|
||||
use crate::utils::cache::ExecutedStep;
|
||||
use crate::utils::helpers::get_host_target;
|
||||
use crate::utils::tests::ConfigBuilder;
|
||||
use crate::utils::tests::git::{GitCtx, git_test};
|
||||
use crate::utils::tests::{ConfigBuilder, TestCtx};
|
||||
|
||||
static TEST_TRIPLE_1: &str = "i686-unknown-haiku";
|
||||
static TEST_TRIPLE_2: &str = "i686-unknown-hurd-gnu";
|
||||
@@ -22,38 +22,13 @@ fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
|
||||
}
|
||||
|
||||
fn configure_with_args(cmd: &[&str], host: &[&str], target: &[&str]) -> Config {
|
||||
let cmd = cmd.iter().copied().map(String::from).collect::<Vec<_>>();
|
||||
let mut config = Config::parse(Flags::parse(&cmd));
|
||||
// don't save toolstates
|
||||
config.save_toolstates = None;
|
||||
config.set_dry_run(DryRun::SelfCheck);
|
||||
|
||||
// Ignore most submodules, since we don't need them for a dry run, and the
|
||||
// tests run much faster without them.
|
||||
//
|
||||
// The src/doc/book submodule is needed because TheBook step tries to
|
||||
// access files even during a dry-run (may want to consider just skipping
|
||||
// that in a dry run).
|
||||
let submodule_build = Build::new(Config {
|
||||
// don't include LLVM, so CI doesn't require ninja/cmake to be installed
|
||||
rust_codegen_backends: vec![],
|
||||
..Config::parse(Flags::parse(&["check".to_owned()]))
|
||||
});
|
||||
submodule_build.require_submodule("src/doc/book", None);
|
||||
config.submodules = Some(false);
|
||||
|
||||
config.ninja_in_file = false;
|
||||
// try to avoid spurious failures in dist where we create/delete each others file
|
||||
// HACK: rather than pull in `tempdir`, use the one that cargo has conveniently created for us
|
||||
let dir = Path::new(env!("OUT_DIR"))
|
||||
.join("tmp-rustbuild-tests")
|
||||
.join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
|
||||
t!(fs::create_dir_all(&dir));
|
||||
config.out = dir;
|
||||
config.host_target = TargetSelection::from_user(TEST_TRIPLE_1);
|
||||
config.hosts = host.iter().map(|s| TargetSelection::from_user(s)).collect();
|
||||
config.targets = target.iter().map(|s| TargetSelection::from_user(s)).collect();
|
||||
config
|
||||
TestCtx::new()
|
||||
.config(cmd[0])
|
||||
.args(&cmd[1..])
|
||||
.hosts(host)
|
||||
.targets(target)
|
||||
.args(&["--build", TEST_TRIPLE_1])
|
||||
.create_config()
|
||||
}
|
||||
|
||||
fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
|
||||
@@ -547,8 +522,8 @@ mod snapshot {
|
||||
|
||||
use crate::core::build_steps::{compile, dist, doc, test, tool};
|
||||
use crate::core::builder::tests::{
|
||||
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, configure_with_args,
|
||||
first, host_target, render_steps, run_build,
|
||||
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, first, host_target,
|
||||
render_steps, run_build,
|
||||
};
|
||||
use crate::core::builder::{Builder, Kind, StepDescription, StepMetadata};
|
||||
use crate::core::config::TargetSelection;
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
use super::*;
|
||||
use crate::core::config::{Target, TargetSelection};
|
||||
use crate::{Build, Config, Flags};
|
||||
use crate::utils::tests::TestCtx;
|
||||
use crate::{Build, Config, Flags, t};
|
||||
|
||||
#[test]
|
||||
fn test_ndk_compiler_c() {
|
||||
@@ -68,7 +69,8 @@ fn test_language_clang() {
|
||||
|
||||
#[test]
|
||||
fn test_new_cc_build() {
|
||||
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let build = Build::new(config);
|
||||
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
|
||||
let cfg = new_cc_build(&build, target.clone());
|
||||
let compiler = cfg.get_compiler();
|
||||
@@ -77,7 +79,8 @@ fn test_new_cc_build() {
|
||||
|
||||
#[test]
|
||||
fn test_default_compiler_wasi() {
|
||||
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let mut build = Build::new(config);
|
||||
let target = TargetSelection::from_user("wasm32-wasi");
|
||||
let wasi_sdk = PathBuf::from("/wasi-sdk");
|
||||
build.wasi_sdk_path = Some(wasi_sdk.clone());
|
||||
@@ -98,7 +101,8 @@ fn test_default_compiler_wasi() {
|
||||
|
||||
#[test]
|
||||
fn test_default_compiler_fallback() {
|
||||
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let build = Build::new(config);
|
||||
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
|
||||
let mut cfg = cc::Build::new();
|
||||
let result = default_compiler(&mut cfg, Language::C, target, &build);
|
||||
@@ -107,7 +111,8 @@ fn test_default_compiler_fallback() {
|
||||
|
||||
#[test]
|
||||
fn test_find_target_with_config() {
|
||||
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let mut build = Build::new(config);
|
||||
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
|
||||
let mut target_config = Target::default();
|
||||
target_config.cc = Some(PathBuf::from("dummy-cc"));
|
||||
@@ -128,7 +133,8 @@ fn test_find_target_with_config() {
|
||||
|
||||
#[test]
|
||||
fn test_find_target_without_config() {
|
||||
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let mut build = Build::new(config);
|
||||
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
|
||||
build.config.target_config.clear();
|
||||
fill_target_compiler(&mut build, target.clone());
|
||||
@@ -141,7 +147,8 @@ fn test_find_target_without_config() {
|
||||
|
||||
#[test]
|
||||
fn test_find() {
|
||||
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
|
||||
let config = TestCtx::new().config("build").create_config();
|
||||
let mut build = Build::new(config);
|
||||
let target1 = TargetSelection::from_user("x86_64-unknown-linux-gnu");
|
||||
let target2 = TargetSelection::from_user("x86_64-unknown-openbsd");
|
||||
build.targets.push(target1.clone());
|
||||
|
||||
Reference in New Issue
Block a user