Skip to content

Allow skipping tests via --skip #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ui_test"
version = "0.16.1"
version = "0.16.2"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A test framework for testing rustc diagnostics output"
Expand Down
44 changes: 38 additions & 6 deletions src/config/args.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Default argument processing when `ui_test` is used
//! as a test driver.

use std::num::NonZeroUsize;
use std::{borrow::Cow, num::NonZeroUsize};

use color_eyre::eyre::{bail, eyre, Result};
use color_eyre::eyre::{bail, ensure, eyre, Result};

/// Plain arguments if `ui_test` is used as a binary.
#[derive(Debug)]
Expand All @@ -20,6 +20,9 @@ pub struct Args {

/// The number of threads to use
pub threads: NonZeroUsize,

/// Skip tests whose names contain any of these entries.
pub skip: Vec<String>,
}

impl Args {
Expand All @@ -29,6 +32,7 @@ impl Args {
filters: vec![],
quiet: false,
check: false,
skip: vec![],
threads: match std::env::var_os("RUST_TEST_THREADS") {
None => std::thread::available_parallelism()?,
Some(n) => n
Expand All @@ -37,24 +41,52 @@ impl Args {
.parse()?,
},
};
for arg in std::env::args().skip(1) {
let mut iter = std::env::args().skip(1);
while let Some(arg) = iter.next() {
if arg == "--" {
continue;
}
if arg == "--quiet" {
args.quiet = true;
} else if arg == "--check" {
args.check = true;
} else if let Some(skip) = parse_value("--skip", &arg, &mut iter)? {
args.skip.push(skip.into_owned());
} else if arg == "--help" {
bail!("available flags: --quiet, --check, --test-threads=n")
} else if let Some(n) = arg.strip_prefix("--test-threads=") {
bail!("available flags: --quiet, --check, --test-threads=n, --skip")
} else if let Some(n) = parse_value("--test-threads", &arg, &mut iter)? {
args.threads = n.parse()?;
} else if arg.starts_with("--") {
bail!("unknown command line flag `{arg}`");
bail!(
"unknown command line flag `{arg}`: {:?}",
std::env::args().collect::<Vec<_>>()
);
} else {
args.filters.push(arg);
}
}
Ok(args)
}
}

fn parse_value<'a>(
name: &str,
arg: &'a str,
iter: &mut impl Iterator<Item = String>,
) -> Result<Option<Cow<'a, str>>> {
let with_eq = match arg.strip_prefix(name) {
Some(s) => s,
None => return Ok(None),
};
if let Some(n) = with_eq.strip_prefix('=') {
Ok(Some(n.into()))
} else {
ensure!(with_eq.is_empty(), "`{name}` can only be followed by `=`");

if let Some(next) = iter.next() {
Ok(Some(next.into()))
} else {
bail!("`name` must be followed by a value")
}
}
}
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ pub fn run_tests_generic(
for entry in entries {
todo.push_back((entry, config));
}
} else if file_filter(&path, &args, config) {
} else if !args
.skip
.iter()
.any(|skip| path.display().to_string().contains(skip))
&& file_filter(&path, &args, config)
{
let status = status_emitter.register_test(path);
// Forward .rs files to the test workers.
submit.send((status, config)).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic-bin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail-mode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.