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