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(()) |
||||||
|
} |
@ -1,80 +1,117 @@ |
|||||||
|
use crate::evaluator::TestEvaluator; |
||||||
use crate::files::load_dataset; |
use crate::files::load_dataset; |
||||||
use crate::manifest::Test; |
use crate::manifest::Test; |
||||||
use crate::report::{dataset_diff, TestResult}; |
use crate::report::dataset_diff; |
||||||
use anyhow::{anyhow, Result}; |
use anyhow::{anyhow, Result}; |
||||||
use chrono::Utc; |
|
||||||
|
|
||||||
pub fn evaluate_parser_tests( |
pub fn register_parser_tests(evaluator: &mut TestEvaluator) { |
||||||
manifest: impl Iterator<Item = Result<Test>>, |
evaluator.register( |
||||||
) -> Result<Vec<TestResult>> { |
"http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax", |
||||||
manifest |
evaluate_positive_syntax_test, |
||||||
.map(|test| { |
); |
||||||
let test = test?; |
evaluator.register( |
||||||
let outcome = evaluate_parser_test(&test); |
"http://www.w3.org/ns/rdftest#TestNQuadsPositiveSyntax", |
||||||
Ok(TestResult { |
evaluate_positive_syntax_test, |
||||||
test: test.id, |
); |
||||||
outcome, |
evaluator.register( |
||||||
date: Utc::now(), |
"http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax", |
||||||
}) |
evaluate_positive_syntax_test, |
||||||
}) |
); |
||||||
.collect() |
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTrigPositiveSyntax", |
||||||
|
evaluate_positive_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestNQuadsNegativeSyntax", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTurtleNegativeEval", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTrigNegativeSyntax", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTrigNegativeEval", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestXMLNegativeSyntax", |
||||||
|
evaluate_negative_syntax_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTurtleEval", |
||||||
|
evaluate_eval_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestTrigEval", |
||||||
|
evaluate_eval_test, |
||||||
|
); |
||||||
|
evaluator.register( |
||||||
|
"http://www.w3.org/ns/rdftest#TestXMLEval", |
||||||
|
evaluate_eval_test, |
||||||
|
); |
||||||
} |
} |
||||||
|
|
||||||
fn evaluate_parser_test(test: &Test) -> Result<()> { |
fn evaluate_positive_syntax_test(test: &Test) -> Result<()> { |
||||||
let action = test |
let action = test |
||||||
.action |
.action |
||||||
.as_deref() |
.as_deref() |
||||||
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
||||||
if test.kind == "http://www.w3.org/ns/rdftest#TestNTriplesPositiveSyntax" |
match load_dataset(action) { |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestNQuadsPositiveSyntax" |
Ok(_) => Ok(()), |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtlePositiveSyntax" |
Err(e) => Err(anyhow!(format!("Parse error: {}", e))), |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigPositiveSyntax" |
} |
||||||
{ |
} |
||||||
match load_dataset(action) { |
|
||||||
Ok(_) => Ok(()), |
fn evaluate_negative_syntax_test(test: &Test) -> Result<()> { |
||||||
Err(e) => Err(anyhow!(format!("Parse error: {}", e))), |
let action = test |
||||||
} |
.action |
||||||
} else if test.kind == "http://www.w3.org/ns/rdftest#TestNTriplesNegativeSyntax" |
.as_deref() |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestNQuadsNegativeSyntax" |
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtleNegativeSyntax" |
match load_dataset(action) { |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTurtleNegativeEval" |
Ok(_) => Err(anyhow!("File parsed with an error even if it should not",)), |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigNegativeSyntax" |
Err(_) => Ok(()), |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigNegativeEval" |
} |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestXMLNegativeSyntax" |
} |
||||||
{ |
|
||||||
match load_dataset(action) { |
fn evaluate_eval_test(test: &Test) -> Result<()> { |
||||||
Ok(_) => Err(anyhow!("File parsed with an error even if it should not",)), |
let action = test |
||||||
Err(_) => Ok(()), |
.action |
||||||
} |
.as_deref() |
||||||
} else if test.kind == "http://www.w3.org/ns/rdftest#TestTurtleEval" |
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestTrigEval" |
match load_dataset(action) { |
||||||
|| test.kind == "http://www.w3.org/ns/rdftest#TestXMLEval" |
Ok(mut actual_graph) => { |
||||||
{ |
actual_graph.canonicalize(); |
||||||
match load_dataset(action) { |
if let Some(result) = &test.result { |
||||||
Ok(mut actual_graph) => { |
match load_dataset(result) { |
||||||
actual_graph.canonicalize(); |
Ok(mut expected_graph) => { |
||||||
if let Some(result) = &test.result { |
expected_graph.canonicalize(); |
||||||
match load_dataset(result) { |
if expected_graph == actual_graph { |
||||||
Ok(mut expected_graph) => { |
Ok(()) |
||||||
expected_graph.canonicalize(); |
} else { |
||||||
if expected_graph == actual_graph { |
Err(anyhow!( |
||||||
Ok(()) |
"The two files are not isomorphic. Diff:\n{}", |
||||||
} else { |
dataset_diff(&expected_graph, &actual_graph) |
||||||
Err(anyhow!( |
)) |
||||||
"The two files are not isomorphic. Diff:\n{}", |
|
||||||
dataset_diff(&expected_graph, &actual_graph) |
|
||||||
)) |
|
||||||
} |
|
||||||
} |
} |
||||||
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)), |
|
||||||
} |
} |
||||||
} else { |
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)), |
||||||
Err(anyhow!("No tests result found")) |
|
||||||
} |
} |
||||||
|
} else { |
||||||
|
Err(anyhow!("No tests result found")) |
||||||
} |
} |
||||||
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)), |
|
||||||
} |
} |
||||||
} else { |
Err(e) => Err(anyhow!("Parse error on file {}: {}", action, e)), |
||||||
Err(anyhow!("Unsupported test type: {}", test.kind)) |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue