Skip to content

Commit 7a4a66d

Browse files
committed
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.
1 parent 8b94fbe commit 7a4a66d

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

src/bootstrap/builder/tests.rs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
2626
v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
2727
}
2828

29+
fn run_build(paths: &[PathBuf], config: Config) -> Cache {
30+
let kind = config.cmd.kind();
31+
let build = Build::new(config);
32+
let builder = Builder::new(&build);
33+
builder.run_step_descriptions(&Builder::get_step_descriptions(kind), paths);
34+
builder.cache
35+
}
36+
37+
#[test]
38+
fn test_exclude() {
39+
let mut config = configure("test", &["A"], &["A"]);
40+
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
41+
42+
let build = Build::new(config);
43+
let builder = Builder::new(&build);
44+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
45+
46+
// Ensure we have really excluded tidy
47+
assert!(!builder.cache.contains::<test::Tidy>());
48+
49+
// Ensure other tests are not affected.
50+
assert!(builder.cache.contains::<test::RustdocUi>());
51+
}
52+
53+
#[test]
54+
fn test_exclude_kind() {
55+
let path = PathBuf::from("src/tools/cargotest");
56+
let exclude = TaskPath::parse("test::src/tools/cargotest");
57+
assert_eq!(exclude, TaskPath { kind: Some(Kind::Test), path: path.clone() });
58+
59+
let mut config = configure("test", &["A"], &["A"]);
60+
// Ensure our test is valid, and `test::Cargotest` would be run without the exclude.
61+
assert!(run_build(&[path.clone()], config.clone()).contains::<test::Cargotest>());
62+
// Ensure tests for cargotest are skipped.
63+
config.exclude = vec![exclude.clone()];
64+
assert!(!run_build(&[path.clone()], config).contains::<test::Cargotest>());
65+
66+
// Ensure builds for cargotest are not skipped.
67+
let mut config = configure("build", &["A"], &["A"]);
68+
config.exclude = vec![exclude];
69+
assert!(run_build(&[path], config).contains::<tool::CargoTest>());
70+
}
71+
2972
mod defaults {
3073
use super::{configure, first};
3174
use crate::builder::*;
@@ -515,35 +558,6 @@ mod dist {
515558
);
516559
}
517560

518-
#[test]
519-
fn test_exclude() {
520-
let mut config = configure(&["A"], &["A"]);
521-
config.exclude = vec![TaskPath::parse("src/tools/tidy")];
522-
config.cmd = Subcommand::Test {
523-
paths: Vec::new(),
524-
test_args: Vec::new(),
525-
rustc_args: Vec::new(),
526-
fail_fast: true,
527-
doc_tests: DocTests::No,
528-
bless: false,
529-
force_rerun: false,
530-
compare_mode: None,
531-
rustfix_coverage: false,
532-
pass: None,
533-
run: None,
534-
};
535-
536-
let build = Build::new(config);
537-
let builder = Builder::new(&build);
538-
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
539-
540-
// Ensure we have really excluded tidy
541-
assert!(!builder.cache.contains::<test::Tidy>());
542-
543-
// Ensure other tests are not affected.
544-
assert!(builder.cache.contains::<test::RustdocUi>());
545-
}
546-
547561
#[test]
548562
fn doc_ci() {
549563
let mut config = configure(&["A"], &["A"]);

src/bootstrap/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ macro_rules! check_ci_llvm {
4141
/// each field, see the corresponding fields in
4242
/// `config.toml.example`.
4343
#[derive(Default)]
44+
#[cfg_attr(test, derive(Clone))]
4445
pub struct Config {
4546
pub changelog_seen: Option<usize>,
4647
pub ccache: Option<String>,
@@ -330,6 +331,7 @@ impl PartialEq<&str> for TargetSelection {
330331

331332
/// Per-target configuration stored in the global configuration structure.
332333
#[derive(Default)]
334+
#[cfg_attr(test, derive(Clone))]
333335
pub struct Target {
334336
/// Some(path to llvm-config) if using an external LLVM.
335337
pub llvm_config: Option<PathBuf>,

src/bootstrap/flags.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::setup::Profile;
1414
use crate::util::t;
1515
use crate::{Build, DocTests};
1616

17+
#[derive(Copy, Clone)]
1718
pub enum Color {
1819
Always,
1920
Never,
@@ -79,6 +80,7 @@ pub struct Flags {
7980
pub llvm_profile_generate: bool,
8081
}
8182

83+
#[cfg_attr(test, derive(Clone))]
8284
pub enum Subcommand {
8385
Build {
8486
paths: Vec<PathBuf>,
@@ -668,6 +670,24 @@ Arguments:
668670
}
669671

670672
impl Subcommand {
673+
pub fn kind(&self) -> Kind {
674+
match self {
675+
Subcommand::Bench { .. } => Kind::Bench,
676+
Subcommand::Build { .. } => Kind::Build,
677+
Subcommand::Check { .. } => Kind::Check,
678+
Subcommand::Clippy { .. } => Kind::Clippy,
679+
Subcommand::Doc { .. } => Kind::Doc,
680+
Subcommand::Fix { .. } => Kind::Fix,
681+
Subcommand::Format { .. } => Kind::Format,
682+
Subcommand::Test { .. } => Kind::Test,
683+
Subcommand::Clean { .. } => Kind::Clean,
684+
Subcommand::Dist { .. } => Kind::Dist,
685+
Subcommand::Install { .. } => Kind::Install,
686+
Subcommand::Run { .. } => Kind::Run,
687+
Subcommand::Setup { .. } => Kind::Setup,
688+
}
689+
}
690+
671691
pub fn test_args(&self) -> Vec<&str> {
672692
match *self {
673693
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {

0 commit comments

Comments
 (0)