1
Fork 0

Add a test for --exclude test::XXX

I didn't know that the `test::` syntax was valid before, and it doesn't
seem to be documented anywhere. Add a test so it doesn't regress accidentally,
and as executable documentation.
This commit is contained in:
Joshua Nelson 2022-04-21 21:29:37 -05:00
parent 8b94fbea01
commit 7a4a66da3d
3 changed files with 65 additions and 29 deletions

View file

@ -26,6 +26,49 @@ fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
v.into_iter().map(|(a, _)| a).collect::<Vec<_>>() v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
} }
fn run_build(paths: &[PathBuf], config: Config) -> Cache {
let kind = config.cmd.kind();
let build = Build::new(config);
let builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(kind), paths);
builder.cache
}
#[test]
fn test_exclude() {
let mut config = configure("test", &["A"], &["A"]);
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
let build = Build::new(config);
let builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
// Ensure we have really excluded tidy
assert!(!builder.cache.contains::<test::Tidy>());
// Ensure other tests are not affected.
assert!(builder.cache.contains::<test::RustdocUi>());
}
#[test]
fn test_exclude_kind() {
let path = PathBuf::from("src/tools/cargotest");
let exclude = TaskPath::parse("test::src/tools/cargotest");
assert_eq!(exclude, TaskPath { kind: Some(Kind::Test), path: path.clone() });
let mut config = configure("test", &["A"], &["A"]);
// Ensure our test is valid, and `test::Cargotest` would be run without the exclude.
assert!(run_build(&[path.clone()], config.clone()).contains::<test::Cargotest>());
// Ensure tests for cargotest are skipped.
config.exclude = vec![exclude.clone()];
assert!(!run_build(&[path.clone()], config).contains::<test::Cargotest>());
// Ensure builds for cargotest are not skipped.
let mut config = configure("build", &["A"], &["A"]);
config.exclude = vec![exclude];
assert!(run_build(&[path], config).contains::<tool::CargoTest>());
}
mod defaults { mod defaults {
use super::{configure, first}; use super::{configure, first};
use crate::builder::*; use crate::builder::*;
@ -515,35 +558,6 @@ mod dist {
); );
} }
#[test]
fn test_exclude() {
let mut config = configure(&["A"], &["A"]);
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
config.cmd = Subcommand::Test {
paths: Vec::new(),
test_args: Vec::new(),
rustc_args: Vec::new(),
fail_fast: true,
doc_tests: DocTests::No,
bless: false,
force_rerun: false,
compare_mode: None,
rustfix_coverage: false,
pass: None,
run: None,
};
let build = Build::new(config);
let builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
// Ensure we have really excluded tidy
assert!(!builder.cache.contains::<test::Tidy>());
// Ensure other tests are not affected.
assert!(builder.cache.contains::<test::RustdocUi>());
}
#[test] #[test]
fn doc_ci() { fn doc_ci() {
let mut config = configure(&["A"], &["A"]); let mut config = configure(&["A"], &["A"]);

View file

@ -41,6 +41,7 @@ macro_rules! check_ci_llvm {
/// each field, see the corresponding fields in /// each field, see the corresponding fields in
/// `config.toml.example`. /// `config.toml.example`.
#[derive(Default)] #[derive(Default)]
#[cfg_attr(test, derive(Clone))]
pub struct Config { pub struct Config {
pub changelog_seen: Option<usize>, pub changelog_seen: Option<usize>,
pub ccache: Option<String>, pub ccache: Option<String>,
@ -330,6 +331,7 @@ impl PartialEq<&str> for TargetSelection {
/// Per-target configuration stored in the global configuration structure. /// Per-target configuration stored in the global configuration structure.
#[derive(Default)] #[derive(Default)]
#[cfg_attr(test, derive(Clone))]
pub struct Target { pub struct Target {
/// Some(path to llvm-config) if using an external LLVM. /// Some(path to llvm-config) if using an external LLVM.
pub llvm_config: Option<PathBuf>, pub llvm_config: Option<PathBuf>,

View file

@ -14,6 +14,7 @@ use crate::setup::Profile;
use crate::util::t; use crate::util::t;
use crate::{Build, DocTests}; use crate::{Build, DocTests};
#[derive(Copy, Clone)]
pub enum Color { pub enum Color {
Always, Always,
Never, Never,
@ -79,6 +80,7 @@ pub struct Flags {
pub llvm_profile_generate: bool, pub llvm_profile_generate: bool,
} }
#[cfg_attr(test, derive(Clone))]
pub enum Subcommand { pub enum Subcommand {
Build { Build {
paths: Vec<PathBuf>, paths: Vec<PathBuf>,
@ -668,6 +670,24 @@ Arguments:
} }
impl Subcommand { impl Subcommand {
pub fn kind(&self) -> Kind {
match self {
Subcommand::Bench { .. } => Kind::Bench,
Subcommand::Build { .. } => Kind::Build,
Subcommand::Check { .. } => Kind::Check,
Subcommand::Clippy { .. } => Kind::Clippy,
Subcommand::Doc { .. } => Kind::Doc,
Subcommand::Fix { .. } => Kind::Fix,
Subcommand::Format { .. } => Kind::Format,
Subcommand::Test { .. } => Kind::Test,
Subcommand::Clean { .. } => Kind::Clean,
Subcommand::Dist { .. } => Kind::Dist,
Subcommand::Install { .. } => Kind::Install,
Subcommand::Run { .. } => Kind::Run,
Subcommand::Setup { .. } => Kind::Setup,
}
}
pub fn test_args(&self) -> Vec<&str> { pub fn test_args(&self) -> Vec<&str> {
match *self { match *self {
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => { Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {