use std::time::Duration;
use crate::error::Error;
use crate::expected::{ExpGot, ExpString};
use crate::log;
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct Output {
name: String,
exit_code: ExpGot<i32>,
stdout: ExpString,
stderr: ExpString,
time: ExpGot<Duration>,
}
impl Output {
pub fn new(
name: String,
exit_code: ExpGot<i32>,
stdout: ExpString,
stderr: ExpString,
time: ExpGot<Duration>,
) -> Output {
let out = Output {
name,
exit_code,
stdout,
stderr,
time,
};
if out.exit_code.eq() {
log::success(&out.name);
} else {
log::failure(&out.name);
}
out
}
pub fn is_valid(&self) -> bool {
self.exit_code().eq() && self.stdout.matches() && self.stderr.matches() && self.time.eq()
}
pub fn exit_code(&self) -> &ExpGot<i32> {
&self.exit_code
}
#[cfg(test)]
pub fn exit_code_got(&self) -> i32 {
self.exit_code.got
}
#[cfg(test)]
pub fn out(&self) -> &str {
&self.stdout.got
}
#[cfg(test)]
pub fn err(&self) -> &str {
&self.stderr.got
}
#[cfg(test)]
pub fn time(&self) -> &Duration {
&self.time.got
}
}
pub trait FtOutput {
fn fmt(data: &Output) -> Result<String, Error>;
}