Next Generation WASM Microkernel Operating System
at main 60 lines 1.8 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use ktest::Test; 9 10#[derive(Default)] 11pub struct Arguments<'a> { 12 pub test_name: Option<&'a str>, 13 pub list: bool, 14 pub include_ignored: bool, 15 pub ignored: bool, 16 pub exact: bool, 17 pub format: FormatSetting, 18} 19 20#[derive(Default, Copy, Clone)] 21pub enum FormatSetting { 22 #[default] 23 Pretty, 24 Terse, 25 Json, 26} 27 28impl<'a> Arguments<'a> { 29 #[allow(clippy::should_implement_trait)] 30 pub fn from_str(str: &'a str) -> Self { 31 Self::parse(str.split_ascii_whitespace()) 32 } 33 34 pub fn parse(mut iter: impl Iterator<Item = &'a str>) -> Self { 35 let mut out = Self::default(); 36 37 while let Some(str) = iter.next() { 38 match str { 39 "--list" => out.list = true, 40 "--include-ignored" => out.include_ignored = true, 41 "--ignored" => out.ignored = true, 42 "--exact" => out.exact = true, 43 "--format" => match iter.next().unwrap() { 44 "pretty" => out.format = FormatSetting::Pretty, 45 "terse" => out.format = FormatSetting::Terse, 46 "json" => out.format = FormatSetting::Json, 47 _ => {} 48 }, 49 _ => out.test_name = Some(str), 50 } 51 } 52 53 out 54 } 55 56 /// Returns `true` if the given test should be ignored. 57 pub fn is_ignored(&self, test: &Test) -> bool { 58 test.info.ignored && !self.ignored && !self.include_ignored 59 } 60}