Skip to content

Commit 35f90de

Browse files
committed
rewrite sparql10/11/12 tests
1 parent 60bf239 commit 35f90de

1 file changed

Lines changed: 49 additions & 107 deletions

File tree

src/builder.rs

Lines changed: 49 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -55,127 +55,69 @@ mod tests {
5555
use super::*;
5656
use walkdir::WalkDir;
5757

58-
#[test]
59-
fn sparql10_tests() -> hdt::hdt::Result<()> {
60-
let input_files = find_ttl_files("tests/resources/rdf-tests/sparql/sparql10");
58+
fn run_sparql_suite(suite: &str) -> hdt::hdt::Result<()> {
59+
let suite_dir = format!("tests/resources/rdf-tests/sparql/{suite}");
60+
assert!(
61+
std::path::Path::new(&suite_dir).exists(),
62+
"{suite_dir} not found — run `git submodule update --init` to fetch rdf-tests"
63+
);
64+
65+
let input_files = find_ttl_files(&suite_dir);
66+
assert!(
67+
!input_files.is_empty(),
68+
"no .ttl files found under {suite_dir}"
69+
);
70+
71+
let tmp = tempfile::tempdir()?;
72+
let mut failures = Vec::new();
73+
6174
for f in &input_files {
62-
if f.ends_with("manifest.ttl")
63-
|| std::path::Path::new(f)
64-
.parent()
65-
.unwrap()
66-
.file_name()
67-
.unwrap()
68-
.to_str()
69-
.unwrap()
70-
== "sparql10"
71-
{
75+
let p = std::path::Path::new(f);
76+
let parent_name = p
77+
.parent()
78+
.and_then(|x| x.file_name())
79+
.and_then(|x| x.to_str());
80+
let file_name = p.file_name().and_then(|n| n.to_str());
81+
82+
if file_name == Some("manifest.ttl") || parent_name == Some(suite) {
7283
continue;
7384
}
74-
let hdt_file_path = format!(
75-
"tests/resources/generated/nt/sparql10/{}/{}",
76-
std::path::Path::new(f)
77-
.parent()
78-
.unwrap()
79-
.file_name()
80-
.unwrap()
81-
.to_str()
82-
.unwrap(),
83-
std::path::Path::new(f)
84-
.file_name()
85-
.unwrap()
86-
.to_str()
87-
.unwrap()
88-
.replace(".ttl", ".hdt")
89-
);
90-
std::fs::create_dir_all(std::path::Path::new(&hdt_file_path).parent().unwrap())?;
91-
92-
if build_hdt(vec![f.to_string()], &hdt_file_path).is_ok() {
93-
assert!(std::path::Path::new(&hdt_file_path).exists())
85+
86+
let stem = p.file_stem().and_then(|s| s.to_str()).unwrap_or("out");
87+
let out = tmp
88+
.path()
89+
.join(format!("{}_{}.hdt", parent_name.unwrap_or("root"), stem,));
90+
let out_str = out
91+
.to_str()
92+
.expect("tempdir path should be valid UTF-8 on test platforms");
93+
94+
if let Err(e) = build_hdt(vec![f.to_string()], out_str) {
95+
failures.push(format!("{f}: {e}"));
9496
}
9597
}
98+
99+
assert!(
100+
failures.is_empty(),
101+
"{} conversion failure(s) in {suite}:\n{}",
102+
failures.len(),
103+
failures.join("\n")
104+
);
96105
Ok(())
97106
}
98107

108+
#[test]
109+
fn sparql10_tests() -> hdt::hdt::Result<()> {
110+
run_sparql_suite("sparql10")
111+
}
112+
99113
#[test]
100114
fn sparql11_tests() -> hdt::hdt::Result<()> {
101-
let input_files = find_ttl_files("tests/resources/rdf-tests/sparql/sparql11");
102-
for f in &input_files {
103-
if f.ends_with("manifest.ttl")
104-
|| std::path::Path::new(f)
105-
.parent()
106-
.unwrap()
107-
.file_name()
108-
.unwrap()
109-
.to_str()
110-
.unwrap()
111-
== "sparql11"
112-
{
113-
continue;
114-
}
115-
let hdt_file_path = format!(
116-
"tests/resources/generated/nt/sparql11/{}/{}",
117-
std::path::Path::new(f)
118-
.parent()
119-
.unwrap()
120-
.file_name()
121-
.unwrap()
122-
.to_str()
123-
.unwrap(),
124-
std::path::Path::new(f)
125-
.file_name()
126-
.unwrap()
127-
.to_str()
128-
.unwrap()
129-
.replace(".ttl", ".hdt")
130-
);
131-
std::fs::create_dir_all(std::path::Path::new(&hdt_file_path).parent().unwrap())?;
132-
133-
if build_hdt(vec![f.to_string()], &hdt_file_path).is_ok() {
134-
assert!(std::path::Path::new(&hdt_file_path).exists())
135-
}
136-
}
137-
Ok(())
115+
run_sparql_suite("sparql11")
138116
}
139117

140118
#[test]
141119
fn sparql12_tests() -> hdt::hdt::Result<()> {
142-
let input_files = find_ttl_files("tests/resources/rdf-tests/sparql/sparql12");
143-
for f in &input_files {
144-
if f.ends_with("manifest.ttl")
145-
|| std::path::Path::new(f)
146-
.parent()
147-
.unwrap()
148-
.file_name()
149-
.unwrap()
150-
.to_str()
151-
.unwrap()
152-
== "sparql12"
153-
{
154-
continue;
155-
}
156-
let hdt_file_path = format!(
157-
"tests/resources/generated/nt/sparql12/{}/{}",
158-
std::path::Path::new(f)
159-
.parent()
160-
.unwrap()
161-
.file_name()
162-
.unwrap()
163-
.to_str()
164-
.unwrap(),
165-
std::path::Path::new(f)
166-
.file_name()
167-
.unwrap()
168-
.to_str()
169-
.unwrap()
170-
.replace(".ttl", ".hdt")
171-
);
172-
std::fs::create_dir_all(std::path::Path::new(&hdt_file_path).parent().unwrap())?;
173-
174-
if build_hdt(vec![f.to_string()], &hdt_file_path).is_ok() {
175-
assert!(std::path::Path::new(&hdt_file_path).exists())
176-
}
177-
}
178-
Ok(())
120+
run_sparql_suite("sparql12")
179121
}
180122

181123
fn find_ttl_files<P: AsRef<std::path::Path>>(dir: P) -> Vec<String> {

0 commit comments

Comments
 (0)