parent
7e9e3a0743
commit
8427eb23c5
@ -0,0 +1,41 @@ |
|||||||
|
use crate::manifest::Test; |
||||||
|
use crate::report::TestResult; |
||||||
|
use anyhow::{anyhow, Result}; |
||||||
|
use chrono::Utc; |
||||||
|
use std::collections::HashMap; |
||||||
|
|
||||||
|
#[derive(Default)] |
||||||
|
pub struct TestEvaluator { |
||||||
|
handlers: HashMap<String, Box<dyn Fn(&Test) -> Result<()>>>, |
||||||
|
} |
||||||
|
|
||||||
|
impl TestEvaluator { |
||||||
|
pub fn register( |
||||||
|
&mut self, |
||||||
|
test_type: impl Into<String>, |
||||||
|
handler: impl Fn(&Test) -> Result<()> + 'static, |
||||||
|
) { |
||||||
|
self.handlers.insert(test_type.into(), Box::new(handler)); |
||||||
|
} |
||||||
|
|
||||||
|
pub fn evaluate( |
||||||
|
&self, |
||||||
|
manifest: impl Iterator<Item = Result<Test>>, |
||||||
|
) -> Result<Vec<TestResult>> { |
||||||
|
manifest |
||||||
|
.map(|test| { |
||||||
|
let test = test?; |
||||||
|
let outcome = if let Some(handler) = self.handlers.get(test.kind.as_str()) { |
||||||
|
handler(&test) |
||||||
|
} else { |
||||||
|
Err(anyhow!("The test type {} is not supported", test.kind)) |
||||||
|
}; |
||||||
|
Ok(TestResult { |
||||||
|
test: test.id, |
||||||
|
outcome, |
||||||
|
date: Utc::now(), |
||||||
|
}) |
||||||
|
}) |
||||||
|
.collect() |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
use anyhow::Result; |
||||||
|
use argh::FromArgs; |
||||||
|
use oxigraph_testsuite::evaluator::TestEvaluator; |
||||||
|
use oxigraph_testsuite::manifest::TestManifest; |
||||||
|
use oxigraph_testsuite::parser_evaluator::register_parser_tests; |
||||||
|
use oxigraph_testsuite::report::build_report; |
||||||
|
use oxigraph_testsuite::sparql_evaluator::register_sparql_tests; |
||||||
|
|
||||||
|
#[derive(FromArgs)] |
||||||
|
/// Oxigraph testsuite runner
|
||||||
|
struct Args { |
||||||
|
/// URI of the testsuite manifest to run
|
||||||
|
#[argh(positional)] |
||||||
|
manifest: String, |
||||||
|
} |
||||||
|
|
||||||
|
fn main() -> Result<()> { |
||||||
|
let args: Args = argh::from_env(); |
||||||
|
|
||||||
|
let mut evaluator = TestEvaluator::default(); |
||||||
|
register_parser_tests(&mut evaluator); |
||||||
|
register_sparql_tests(&mut evaluator); |
||||||
|
let manifest = TestManifest::new(vec![args.manifest]); |
||||||
|
let results = evaluator.evaluate(manifest)?; |
||||||
|
print!("{}", build_report(results)); |
||||||
|
Ok(()) |
||||||
|
} |
Loading…
Reference in new issue