use tester::{ShouldPanic, TestDesc, TestDescAndFn, TestFn, TestName, TestType};
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct TestCase {
name: &'static str,
f: fn(),
should_panic: bool,
}
impl TestCase {
pub const fn new(name: &'static str, f: fn(), should_panic: bool) -> Self {
Self {
name,
f,
should_panic,
}
}
pub const fn name(&self) -> &str {
self.name
}
pub fn run(&self) {
(self.f)()
}
pub fn should_panic(&self) -> bool {
self.should_panic
}
pub const fn to_tester(&self) -> TestDescAndFn {
TestDescAndFn {
desc: TestDesc {
name: TestName::StaticTestName(self.name),
ignore: false,
should_panic: if self.should_panic {
ShouldPanic::Yes
} else {
ShouldPanic::No
},
allow_fail: false,
test_type: TestType::IntegrationTest,
},
testfn: TestFn::StaticTestFn(self.f),
}
}
}
impl From<&TestCase> for TestDescAndFn {
#[inline(always)]
fn from(tc: &TestCase) -> Self {
tc.to_tester()
}
}
impl From<TestCase> for TestDescAndFn {
#[inline(always)]
fn from(tc: TestCase) -> Self {
tc.to_tester()
}
}
#[::linkme::distributed_slice]
pub static TARANTOOL_MODULE_TESTS: [TestCase] = [..];
pub fn test_cases() -> &'static [TestCase] {
&TARANTOOL_MODULE_TESTS
}
pub fn collect_tester() -> Vec<TestDescAndFn> {
TARANTOOL_MODULE_TESTS.iter().map(Into::into).collect()
}
#[cfg(feature = "internal_test")]
pub mod util {
use std::convert::Infallible;
pub const TARANTOOL_LISTEN: u16 = 3301;
pub async fn always_pending() -> Result<Infallible, Infallible> {
loop {
futures::pending!()
}
}
pub fn ok<T>(v: T) -> std::result::Result<T, Infallible> {
Ok(v)
}
}
#[macro_export]
macro_rules! temp_space_name {
() => {
::std::format!(
"temp_space@{}:{}:{}",
::std::file!(),
::std::line!(),
::std::column!()
)
};
}