Skip to content

Commit

Permalink
WIP: feat: tags property on tests and subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Aug 3, 2024
1 parent 76b84db commit 64263d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ fn run(cli: Cli) -> ExitCode {
is_disabled,
expected,
implementation_status: _,
tags: _,
} = properties;

let test_name = Arc::new(test_name);
Expand Down Expand Up @@ -703,6 +704,7 @@ fn run(cli: Cli) -> ExitCode {
is_disabled,
expected,
implementation_status: _,
tags: _,
} = properties;

if is_disabled {
Expand Down
51 changes: 49 additions & 2 deletions moz-webgpu-cts/src/wpt/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ impl<'a> Properties<'a> for FileProps {
}
}

fn tags_parser<'a>(
helper: &mut PropertiesParseHelper<'a>,
conditional_term: impl Parser<'a, &'a str, Expr<Value<'static>>, ParseError<'a>>,
) -> impl Parser<'a, &'a str, PropertyValue<Expr<Value<'static>>, Vec<String>>, ParseError<'a>> {
helper
.parser(
keyword("tags").to(()),
conditional_term,
ascii::ident()
.map(|i: &str| i.to_owned())
.separated_by(just(',').padded_by(inline_whitespace()))
.collect()
.delimited_by(
just('[').padded_by(inline_whitespace()),
just(']').padded_by(inline_whitespace()),
)
.validate(|idents: Vec<_>, e, emitter| {
if idents.is_empty() {
emitter.emit(Rich::custom(e.span(), "no tags specified"));
}
idents
}),
)
.map(|((), tags)| tags)
}

#[test]
fn file_props() {
let parser = FileProps::property_parser(&mut PropertiesParseHelper::new(0));
Expand Down Expand Up @@ -740,7 +766,7 @@ fn format_test_properties<Out>(indentation: u8, property: &TestProps<Out>) -> im
where
Out: Default + Display + EnumSetType + Eq + PartialEq,
{
lazy_format!(move |f| {
let display = lazy_format!(move |f| {
let indent = lazy_format!(move |f| write!(
f,
"{}",
Expand All @@ -752,6 +778,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = property;

if *is_disabled {
Expand Down Expand Up @@ -832,6 +859,20 @@ where
Ok(())
}

if let Some(tags) = tags {
#[derive(Clone, Debug, Default, Eq, PartialEq)]
struct TagsDisplay();

impl Display for TagsDisplay {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let Self(tags) = self;

Check failure on line 868 in moz-webgpu-cts/src/wpt/metadata.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

this pattern has 1 field, but the corresponding tuple struct has 0 fields
Display::fmt(&tags.iter().join_with(", "), f)
}
}

write_normalized(f, &indent, TAGS_IDENT, &tags.map(TagsDisplay))?;

Check failure on line 873 in moz-webgpu-cts/src/wpt/metadata.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

function is expected to take 1 argument, but it takes 0 arguments
}

if let Some(implementation_status) = implementation_status {
write_normalized(
f,
Expand All @@ -846,7 +887,8 @@ where
}

Ok(())
})
});
display
}

#[derive(Clone, Copy, Debug, Enum, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
Expand All @@ -870,6 +912,7 @@ where
pub is_disabled: bool,
pub expected: Option<ExpandedPropertyValue<Expected<Out>>>,
pub implementation_status: Option<ExpandedPropertyValue<ImplementationStatus>>,
pub tags: Option<ExpandedPropertyValue<Vec<String>>>,
}

impl<'a, Out> TestProps<Out>
Expand All @@ -881,6 +924,7 @@ where
is_disabled,
expected,
implementation_status,
tags,
} = self;

let TestProp { kind, span } = prop;
Expand Down Expand Up @@ -959,6 +1003,7 @@ where
implementation_status,
val,
),
TestPropKind::Tags(val) => conditional(emitter, span, TAGS_IDENT, tags, val),
}
}
}
Expand Down Expand Up @@ -986,6 +1031,7 @@ where
Expected(PropertyValue<Applicability, Expected<Out>>),
Disabled,
ImplementationStatus(PropertyValue<Applicability, ImplementationStatus>),
Tags(PropertyValue<Applicability, Vec<String>>),
}

impl<Out> TestProp<Out>
Expand Down Expand Up @@ -1175,6 +1221,7 @@ where
}

pub(crate) const EXPECTED_IDENT: &str = "expected";
pub(crate) const TAGS_IDENT: &str = "expected";
pub(crate) const PASS: &str = "PASS";
pub(crate) const FAIL: &str = "FAIL";
pub(crate) const NOTRUN: &str = "NOTRUN";
Expand Down

0 comments on commit 64263d1

Please sign in to comment.