1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-09 17:16:16 +02:00
youki/tests/contest/test_framework/src/conditional_test.rs
Toru Komatsu 464344923f
Name the test tools `contest` (#2486)
* Name the test tools `contest`

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a build error

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a workflow

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

---------

Signed-off-by: utam0k <k0ma@utam0k.jp>
2024-01-12 14:28:47 +05:30

43 lines
1.1 KiB
Rust

//! Contains definition for a tests which should be conditionally run
use crate::testable::{TestResult, Testable};
// type aliases for test function signature
type TestFn = dyn Fn() -> TestResult + Sync + Send;
// type alias for function signature for function which checks if a test can be run or not
type CheckFn = dyn Fn() -> bool + Sync + Send;
/// Basic Template structure for tests which need to be run conditionally
pub struct ConditionalTest {
/// name of the test
name: &'static str,
/// actual test function
test_fn: Box<TestFn>,
/// function to check if a test can be run or not
check_fn: Box<CheckFn>,
}
impl ConditionalTest {
/// Create a new condition test
pub fn new(name: &'static str, check_fn: Box<CheckFn>, test_fn: Box<TestFn>) -> Self {
ConditionalTest {
name,
check_fn,
test_fn,
}
}
}
impl Testable for ConditionalTest {
fn get_name(&self) -> &'static str {
self.name
}
fn can_run(&self) -> bool {
(self.check_fn)()
}
fn run(&self) -> TestResult {
(self.test_fn)()
}
}