Skip to content

Commit

Permalink
[nextest-filtering] add a "binary_id" predicate
Browse files Browse the repository at this point in the history
This predicate can be used to match against the binary ID, by copy-pasting it
from the output. This can be done today with `package(foo) & binary(bar)` but
is much easier this way.
  • Loading branch information
sunshowers committed Nov 27, 2023
1 parent 97bd625 commit c1cfe18
Show file tree
Hide file tree
Showing 17 changed files with 338 additions and 499 deletions.
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [

[workspace.dependencies]
globset = "0.4.14"
nextest-metadata = { path = "nextest-metadata" }
nextest-workspace-hack = "0.1.0"

# make backtrace + color-eyre faster on debug builds
Expand Down
1 change: 1 addition & 0 deletions nextest-filtering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ recursion = "0.5.1"
regex = "1.10.2"
regex-syntax = "0.8.2"
thiserror = "1.0.50"
nextest-metadata.workspace = true
proptest = { version = "1.4.0", optional = true }
test-strategy = { version = "0.3.1", optional = true }
twox-hash = { version = "1.6.3", optional = true }
Expand Down
1 change: 1 addition & 0 deletions nextest-filtering/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn compile_set_def(
)),
SetDef::Kind(matcher, span) => FilteringSet::Kind(matcher.clone(), *span),
SetDef::Binary(matcher, span) => FilteringSet::Binary(matcher.clone(), *span),
SetDef::BinaryId(matcher, span) => FilteringSet::BinaryId(matcher.clone(), *span),
SetDef::Platform(platform, span) => FilteringSet::Platform(*platform, *span),
SetDef::Test(matcher, span) => FilteringSet::Test(matcher.clone(), *span),
SetDef::All => FilteringSet::All,
Expand Down
14 changes: 11 additions & 3 deletions nextest-filtering/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use guppy::{
PackageId,
};
use miette::SourceSpan;
use nextest_metadata::{RustBinaryId, RustTestBinaryKind};
use recursion::{Collapsible, CollapsibleExt, MappableFrame, PartiallyApplied};
use std::{cell::RefCell, collections::HashSet, fmt};

Expand Down Expand Up @@ -118,6 +119,8 @@ pub enum FilteringSet {
Platform(BuildPlatform, SourceSpan),
/// All binaries matching a name
Binary(NameMatcher, SourceSpan),
/// All binary IDs matching a name
BinaryId(NameMatcher, SourceSpan),
/// All tests matching a name
Test(NameMatcher, SourceSpan),
/// All tests
Expand All @@ -132,11 +135,14 @@ pub struct BinaryQuery<'a> {
/// The package ID.
pub package_id: &'a PackageId,

/// The binary ID.
pub binary_id: &'a RustBinaryId,

/// The name of the binary.
pub binary_name: &'a str,

/// The kind of binary this test is (lib, test etc).
pub kind: &'a str,
pub kind: &'a RustTestBinaryKind,

/// The platform this test is built for.
pub platform: BuildPlatform,
Expand Down Expand Up @@ -197,8 +203,9 @@ impl FilteringSet {
Self::None => false,
Self::Test(matcher, _) => matcher.is_match(query.test_name),
Self::Binary(matcher, _) => matcher.is_match(query.binary_query.binary_name),
Self::BinaryId(matcher, _) => matcher.is_match(query.binary_query.binary_id.as_str()),
Self::Platform(platform, _) => query.binary_query.platform == *platform,
Self::Kind(matcher, _) => matcher.is_match(query.binary_query.kind),
Self::Kind(matcher, _) => matcher.is_match(query.binary_query.kind.as_str()),
Self::Packages(packages) => packages.contains(query.binary_query.package_id),
}
}
Expand All @@ -209,8 +216,9 @@ impl FilteringSet {
Self::None => Logic::bottom(),
Self::Test(_, _) => None,
Self::Binary(matcher, _) => Some(matcher.is_match(query.binary_name)),
Self::BinaryId(matcher, _) => Some(matcher.is_match(query.binary_id.as_str())),
Self::Platform(platform, _) => Some(query.platform == *platform),
Self::Kind(matcher, _) => Some(matcher.is_match(query.kind)),
Self::Kind(matcher, _) => Some(matcher.is_match(query.kind.as_str())),
Self::Packages(packages) => Some(packages.contains(query.package_id)),
}
}
Expand Down
5 changes: 5 additions & 0 deletions nextest-filtering/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum SetDef<S = SourceSpan> {
Rdeps(NameMatcher, S),
Kind(NameMatcher, S),
Binary(NameMatcher, S),
BinaryId(NameMatcher, S),
Platform(BuildPlatform, S),
Test(NameMatcher, S),
All,
Expand All @@ -67,6 +68,7 @@ impl SetDef {
Self::Rdeps(matcher, _) => SetDef::Rdeps(matcher, ()),
Self::Kind(matcher, _) => SetDef::Kind(matcher, ()),
Self::Binary(matcher, _) => SetDef::Binary(matcher, ()),
Self::BinaryId(matcher, _) => SetDef::BinaryId(matcher, ()),
Self::Platform(platform, _) => SetDef::Platform(platform, ()),
Self::Test(matcher, _) => SetDef::Test(matcher, ()),
Self::All => SetDef::All,
Expand All @@ -83,6 +85,7 @@ impl<S> fmt::Display for SetDef<S> {
Self::Rdeps(matcher, _) => write!(f, "rdeps({matcher})"),
Self::Kind(matcher, _) => write!(f, "kind({matcher})"),
Self::Binary(matcher, _) => write!(f, "binary({matcher})"),
Self::BinaryId(matcher, _) => write!(f, "binary_id({matcher})"),
Self::Platform(platform, _) => write!(f, "platform({platform})"),
Self::Test(matcher, _) => write!(f, "test({matcher})"),
Self::All => write!(f, "all()"),
Expand Down Expand Up @@ -599,6 +602,8 @@ fn parse_set_def(input: Span) -> IResult<Option<SetDef>> {
unary_set_def("deps", DefaultMatcher::Glob, SetDef::Deps),
unary_set_def("rdeps", DefaultMatcher::Glob, SetDef::Rdeps),
unary_set_def("kind", DefaultMatcher::Equal, SetDef::Kind),
// binary_id must go above binary, otherwise we'll parse the opening predicate wrong.
unary_set_def("binary_id", DefaultMatcher::Glob, SetDef::BinaryId),
unary_set_def("binary", DefaultMatcher::Glob, SetDef::Binary),
unary_set_def("test", DefaultMatcher::Contains, SetDef::Test),
platform_def,
Expand Down
Loading

0 comments on commit c1cfe18

Please sign in to comment.