diff --git a/crates/core/src/helpers/test.rs b/crates/core/src/helpers/test.rs index 261f29f..c13d893 100644 --- a/crates/core/src/helpers/test.rs +++ b/crates/core/src/helpers/test.rs @@ -223,17 +223,24 @@ impl<'a> TestDefinition<'a> { /// Checks if the platforms all support the desired targets in the metadata file. fn check_target_compatibility(&self) -> TestCheckFunctionResult { - let mut error_map = indexmap! { - "test_desired_targets" => json!(self.metadata.targets.as_ref()), + // The case targets takes presence over the metadata targets. + let Some(targets) = self + .case + .targets + .as_ref() + .or(self.metadata.targets.as_ref()) + else { + return Ok(()); }; + + let mut error_map = indexmap! { + "test_desired_targets" => json!(targets), + }; + let mut is_allowed = true; for (_, platform_information) in self.platforms.iter() { - let is_allowed_for_platform = match self.metadata.targets.as_ref() { - None => true, - Some(required_vm_identifiers) => { - required_vm_identifiers.contains(&platform_information.platform.vm_identifier()) - } - }; + let is_allowed_for_platform = + targets.contains(&platform_information.platform.vm_identifier()); is_allowed &= is_allowed_for_platform; error_map.insert( platform_information.platform.platform_identifier().into(), diff --git a/crates/format/src/case.rs b/crates/format/src/case.rs index 19114a9..f8d4afa 100644 --- a/crates/format/src/case.rs +++ b/crates/format/src/case.rs @@ -1,16 +1,22 @@ -use alloy::primitives::Address; +use alloy::primitives::{Address, map::HashSet}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use revive_dt_common::{ macros::define_wrapper_type, - types::{Mode, ParsedMode}, + types::{Mode, ParsedMode, VmIdentifier}, }; use crate::steps::*; #[derive(Debug, Default, Serialize, Deserialize, Clone, Eq, PartialEq, JsonSchema)] pub struct Case { + /// An optional vector of targets that this Metadata file's cases can be executed on. As an + /// example, if we wish for the metadata file's cases to only be run on PolkaVM then we'd + /// specify a target of "PolkaVM" in here. + #[serde(skip_serializing_if = "Option::is_none")] + pub targets: Option>, + /// An optional name of the test case. #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, diff --git a/crates/format/src/metadata.rs b/crates/format/src/metadata.rs index 173e288..c73a6e9 100644 --- a/crates/format/src/metadata.rs +++ b/crates/format/src/metadata.rs @@ -8,6 +8,7 @@ use std::{ str::FromStr, }; +use alloy::primitives::map::HashSet; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -83,7 +84,7 @@ pub struct Metadata { /// example, if we wish for the metadata file's cases to only be run on PolkaVM then we'd /// specify a target of "PolkaVM" in here. #[serde(skip_serializing_if = "Option::is_none")] - pub targets: Option>, + pub targets: Option>, /// A vector of the test cases and workloads contained within the metadata file. This is their /// primary description.