|
|
@ -2,11 +2,12 @@ use crate::files::*; |
|
|
|
use crate::manifest::*; |
|
|
|
use crate::manifest::*; |
|
|
|
use crate::report::*; |
|
|
|
use crate::report::*; |
|
|
|
use crate::vocab::*; |
|
|
|
use crate::vocab::*; |
|
|
|
|
|
|
|
use anyhow::{anyhow, Result}; |
|
|
|
use chrono::Utc; |
|
|
|
use chrono::Utc; |
|
|
|
use oxigraph::model::vocab::*; |
|
|
|
use oxigraph::model::vocab::*; |
|
|
|
use oxigraph::model::*; |
|
|
|
use oxigraph::model::*; |
|
|
|
use oxigraph::sparql::*; |
|
|
|
use oxigraph::sparql::*; |
|
|
|
use oxigraph::{Error, MemoryStore, Result}; |
|
|
|
use oxigraph::{Error, MemoryStore}; |
|
|
|
use std::collections::HashMap; |
|
|
|
use std::collections::HashMap; |
|
|
|
use std::fmt; |
|
|
|
use std::fmt; |
|
|
|
use std::str::FromStr; |
|
|
|
use std::str::FromStr; |
|
|
@ -36,20 +37,17 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { |
|
|
|
let query_file = test |
|
|
|
let query_file = test |
|
|
|
.action |
|
|
|
.action |
|
|
|
.as_deref() |
|
|
|
.as_deref() |
|
|
|
.ok_or_else(|| Error::msg(format!("No action found for test {}", test)))?; |
|
|
|
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
|
|
|
match Query::parse(&read_file_to_string(&query_file)?, Some(&query_file)) { |
|
|
|
match Query::parse(&read_file_to_string(&query_file)?, Some(&query_file)) { |
|
|
|
Err(error) => Err(Error::msg(format!( |
|
|
|
Err(error) => Err(anyhow!("Not able to parse {} with error: {}", test, error)), |
|
|
|
"Not able to parse {} with error: {}", |
|
|
|
|
|
|
|
test, error |
|
|
|
|
|
|
|
))), |
|
|
|
|
|
|
|
Ok(query) => match Query::parse(&query.to_string(), None) { |
|
|
|
Ok(query) => match Query::parse(&query.to_string(), None) { |
|
|
|
Ok(_) => Ok(()), |
|
|
|
Ok(_) => Ok(()), |
|
|
|
Err(error) => Err(Error::msg(format!( |
|
|
|
Err(error) => Err(anyhow!( |
|
|
|
"Failure to deserialize \"{}\" of {} with error: {}", |
|
|
|
"Failure to deserialize \"{}\" of {} with error: {}", |
|
|
|
query.to_string(), |
|
|
|
query.to_string(), |
|
|
|
test, |
|
|
|
test, |
|
|
|
error |
|
|
|
error |
|
|
|
))), |
|
|
|
)), |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} else if test.kind |
|
|
|
} else if test.kind |
|
|
@ -60,12 +58,13 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { |
|
|
|
let query_file = test |
|
|
|
let query_file = test |
|
|
|
.action |
|
|
|
.action |
|
|
|
.as_deref() |
|
|
|
.as_deref() |
|
|
|
.ok_or_else(|| Error::msg(format!("No action found for test {}", test)))?; |
|
|
|
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
|
|
|
match Query::parse(&read_file_to_string(query_file)?, Some(query_file)) { |
|
|
|
match Query::parse(&read_file_to_string(query_file)?, Some(query_file)) { |
|
|
|
Ok(result) => Err(Error::msg(format!( |
|
|
|
Ok(result) => Err(anyhow!( |
|
|
|
"Oxigraph parses even if it should not {}. The output tree is: {}", |
|
|
|
"Oxigraph parses even if it should not {}. The output tree is: {}", |
|
|
|
test, result |
|
|
|
test, |
|
|
|
))), |
|
|
|
result |
|
|
|
|
|
|
|
)), |
|
|
|
Err(_) => Ok(()), |
|
|
|
Err(_) => Ok(()), |
|
|
|
} |
|
|
|
} |
|
|
|
} else if test.kind |
|
|
|
} else if test.kind |
|
|
@ -81,26 +80,25 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { |
|
|
|
let query_file = test |
|
|
|
let query_file = test |
|
|
|
.query |
|
|
|
.query |
|
|
|
.as_deref() |
|
|
|
.as_deref() |
|
|
|
.ok_or_else(|| Error::msg(format!("No action found for test {}", test)))?; |
|
|
|
.ok_or_else(|| anyhow!("No action found for test {}", test))?; |
|
|
|
let options = QueryOptions::default() |
|
|
|
let options = QueryOptions::default() |
|
|
|
.with_service_handler(StaticServiceHandler::new(&test.service_data)?); |
|
|
|
.with_service_handler(StaticServiceHandler::new(&test.service_data)?); |
|
|
|
match Query::parse(&read_file_to_string(query_file)?, Some(query_file)) { |
|
|
|
match Query::parse(&read_file_to_string(query_file)?, Some(query_file)) { |
|
|
|
Err(error) => Err(Error::msg(format!( |
|
|
|
Err(error) => Err(anyhow!( |
|
|
|
"Failure to parse query of {} with error: {}", |
|
|
|
"Failure to parse query of {} with error: {}", |
|
|
|
test, error |
|
|
|
test, |
|
|
|
))), |
|
|
|
error |
|
|
|
|
|
|
|
)), |
|
|
|
Ok(query) => match store.query(query, options) { |
|
|
|
Ok(query) => match store.query(query, options) { |
|
|
|
Err(error) => Err(Error::msg(format!( |
|
|
|
Err(error) => Err(anyhow!( |
|
|
|
"Failure to execute query of {} with error: {}", |
|
|
|
"Failure to execute query of {} with error: {}", |
|
|
|
test, error |
|
|
|
test, |
|
|
|
))), |
|
|
|
error |
|
|
|
|
|
|
|
)), |
|
|
|
Ok(actual_results) => { |
|
|
|
Ok(actual_results) => { |
|
|
|
let expected_results = load_sparql_query_result(test.result.as_ref().unwrap()) |
|
|
|
let expected_results = load_sparql_query_result(test.result.as_ref().unwrap()) |
|
|
|
.map_err(|e| { |
|
|
|
.map_err(|e| { |
|
|
|
Error::msg(format!( |
|
|
|
anyhow!("Error constructing expected graph for {}: {}", test, e) |
|
|
|
"Error constructing expected graph for {}: {}", |
|
|
|
|
|
|
|
test, e |
|
|
|
|
|
|
|
)) |
|
|
|
|
|
|
|
})?; |
|
|
|
})?; |
|
|
|
let with_order = |
|
|
|
let with_order = |
|
|
|
if let StaticQueryResults::Solutions { ordered, .. } = &expected_results { |
|
|
|
if let StaticQueryResults::Solutions { ordered, .. } = &expected_results { |
|
|
@ -114,19 +112,19 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { |
|
|
|
if are_query_results_isomorphic(&expected_results, &actual_results) { |
|
|
|
if are_query_results_isomorphic(&expected_results, &actual_results) { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Err(Error::msg(format!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", |
|
|
|
Err(anyhow!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", |
|
|
|
test, |
|
|
|
test, |
|
|
|
actual_results, |
|
|
|
actual_results, |
|
|
|
expected_results, |
|
|
|
expected_results, |
|
|
|
Query::parse(&read_file_to_string(query_file)?, Some(query_file)).unwrap(), |
|
|
|
Query::parse(&read_file_to_string(query_file)?, Some(query_file)).unwrap(), |
|
|
|
store |
|
|
|
store |
|
|
|
))) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Err(Error::msg(format!("Unsupported test type: {}", test.kind))) |
|
|
|
Err(anyhow!("Unsupported test type: {}", test.kind)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -170,7 +168,7 @@ impl StaticServiceHandler { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl ServiceHandler for StaticServiceHandler { |
|
|
|
impl ServiceHandler for StaticServiceHandler { |
|
|
|
fn handle(&self, service_name: NamedNode, query: Query) -> Result<QueryResult> { |
|
|
|
fn handle(&self, service_name: NamedNode, query: Query) -> oxigraph::Result<QueryResult> { |
|
|
|
self.services |
|
|
|
self.services |
|
|
|
.get(&service_name) |
|
|
|
.get(&service_name) |
|
|
|
.ok_or_else(|| Error::msg(format!("Service {} not found", service_name)))? |
|
|
|
.ok_or_else(|| Error::msg(format!("Service {} not found", service_name)))? |
|
|
@ -183,7 +181,9 @@ impl ServiceHandler for StaticServiceHandler { |
|
|
|
|
|
|
|
|
|
|
|
fn to_dataset(result: QueryResult, with_order: bool) -> Result<MemoryStore> { |
|
|
|
fn to_dataset(result: QueryResult, with_order: bool) -> Result<MemoryStore> { |
|
|
|
match result { |
|
|
|
match result { |
|
|
|
QueryResult::Graph(graph) => graph.map(|t| t.map(|t| t.in_graph(None))).collect(), |
|
|
|
QueryResult::Graph(graph) => Ok(graph |
|
|
|
|
|
|
|
.map(|t| t.map(|t| t.in_graph(None))) |
|
|
|
|
|
|
|
.collect::<Result<_, Error>>()?), |
|
|
|
QueryResult::Boolean(value) => { |
|
|
|
QueryResult::Boolean(value) => { |
|
|
|
let store = MemoryStore::new(); |
|
|
|
let store = MemoryStore::new(); |
|
|
|
let result_set = BlankNode::default(); |
|
|
|
let result_set = BlankNode::default(); |
|
|
|