use std::path::Path;
use super::report::{ProofError, ProofReport};
#[non_exhaustive]
pub struct RenderContext<'a> {
pub report: &'a ProofReport,
pub output: &'a Path,
}
impl<'a> RenderContext<'a> {
pub fn new(report: &'a ProofReport, output: &'a Path) -> Self {
Self { report, output }
}
}
pub trait ProofBackend {
fn render(&self, context: &RenderContext<'_>) -> Result<(), ProofError>;
}
#[cfg(test)]
mod tests {
use super::*;
struct StubBackend {
should_fail: bool,
}
impl ProofBackend for StubBackend {
fn render(&self, _context: &RenderContext<'_>) -> Result<(), ProofError> {
if self.should_fail {
return Err(ProofError::Format("stub failure".to_string()));
}
Ok(())
}
}
#[test]
fn render_context_exposes_report_and_output() {
let report = ProofReport::new("ctx_scenario");
let path = Path::new("/tmp/ctx.txt");
let context = RenderContext::new(&report, path);
assert_eq!(context.report.scenario_name, "ctx_scenario");
assert_eq!(context.output, path);
}
#[test]
fn stub_backend_succeeds() {
let backend = StubBackend { should_fail: false };
let report = ProofReport::new("test");
let result = backend.render(&RenderContext::new(&report, Path::new("/tmp/test.txt")));
assert!(result.is_ok());
}
#[test]
fn stub_backend_returns_error() {
let backend = StubBackend { should_fail: true };
let report = ProofReport::new("test");
let result = backend.render(&RenderContext::new(&report, Path::new("/tmp/test.txt")));
assert!(result.is_err());
}
}