Add first pass at interop tests
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
#![feature(async_await)]
|
||||
|
||||
pub mod client;
|
||||
|
||||
pub mod pb {
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
include!(concat!(env!("OUT_DIR"), "/grpc.testing.rs"));
|
||||
}
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TestAssertion {
|
||||
Passed {
|
||||
description: &'static str,
|
||||
},
|
||||
Failed {
|
||||
description: &'static str,
|
||||
expression: &'static str,
|
||||
why: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for TestAssertion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use console::{style, Emoji};
|
||||
match *self {
|
||||
TestAssertion::Passed { ref description } => write!(
|
||||
f,
|
||||
"{check} {desc}",
|
||||
check = style(Emoji("✔", "+")).green(),
|
||||
desc = style(description).green(),
|
||||
),
|
||||
TestAssertion::Failed {
|
||||
ref description,
|
||||
ref expression,
|
||||
why: Some(ref why),
|
||||
} => write!(
|
||||
f,
|
||||
"{check} {desc}\n in `{exp}`: {why}",
|
||||
check = style(Emoji("✖", "x")).red(),
|
||||
desc = style(description).red(),
|
||||
exp = style(expression).red(),
|
||||
why = style(why).red(),
|
||||
),
|
||||
TestAssertion::Failed {
|
||||
ref description,
|
||||
ref expression,
|
||||
why: None,
|
||||
} => write!(
|
||||
f,
|
||||
"{check} {desc}\n in `{exp}`",
|
||||
check = style(Emoji("✖", "x")).red(),
|
||||
desc = style(description).red(),
|
||||
exp = style(expression).red(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! test_assert {
|
||||
($description:expr, $assertion:expr) => {
|
||||
if $assertion {
|
||||
crate::TestAssertion::Passed {
|
||||
description: $description,
|
||||
}
|
||||
} else {
|
||||
TestAssertion::Failed {
|
||||
description: $description,
|
||||
expression: stringify!($assertion),
|
||||
why: None,
|
||||
}
|
||||
}
|
||||
};
|
||||
($description:expr, $assertion:expr, $why:expr) => {
|
||||
if $assertion {
|
||||
crate::TestAssertion::Passed {
|
||||
description: $description,
|
||||
}
|
||||
} else {
|
||||
crate::TestAssertion::Failed {
|
||||
description: $description,
|
||||
expression: stringify!($assertion),
|
||||
why: Some($why),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user