summaryrefslogtreecommitdiff
path: root/cli/tools/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r--cli/tools/test.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 4424ee28d..7dcc23dd1 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -77,6 +77,58 @@ pub enum TestMode {
Both,
}
+// TODO(nayeemrmn): This is only used for benches right now.
+#[derive(Clone, Debug, Default)]
+pub struct TestFilter {
+ pub substring: Option<String>,
+ pub regex: Option<Regex>,
+ pub include: Option<Vec<String>>,
+ pub exclude: Vec<String>,
+}
+
+impl TestFilter {
+ pub fn includes(&self, name: &String) -> bool {
+ if let Some(substring) = &self.substring {
+ if !name.contains(substring) {
+ return false;
+ }
+ }
+ if let Some(regex) = &self.regex {
+ if !regex.is_match(name) {
+ return false;
+ }
+ }
+ if let Some(include) = &self.include {
+ if !include.contains(name) {
+ return false;
+ }
+ }
+ if self.exclude.contains(name) {
+ return false;
+ }
+ true
+ }
+
+ pub fn from_flag(flag: &Option<String>) -> Self {
+ let mut substring = None;
+ let mut regex = None;
+ if let Some(flag) = flag {
+ if flag.starts_with('/') && flag.ends_with('/') {
+ let rs = flag.trim_start_matches('/').trim_end_matches('/');
+ regex =
+ Some(Regex::new(rs).unwrap_or_else(|_| Regex::new("$^").unwrap()));
+ } else {
+ substring = Some(flag.clone());
+ }
+ }
+ Self {
+ substring,
+ regex,
+ ..Default::default()
+ }
+ }
+}
+
#[derive(Debug, Clone, PartialEq, Deserialize, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct TestLocation {