Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

test: give every CLI test its own data directory

FABIOTESSd423869aa071
diff --git a/tests/cli_exit_codes_test.rs b/tests/cli_exit_codes_test.rs
index 61fbca0b..66e6e5c1 100644
--- a/tests/cli_exit_codes_test.rs
+++ b/tests/cli_exit_codes_test.rs
@@ -12,8 +12,14 @@
use std::process::Command;
-fn run(args: &[&str]) -> (i32, String) {
+/// Every invocation gets its own `--data-dir`, the same discipline `cli_test.rs`
+/// uses. Without it these tests open the developer's real
+/// `~/.open-ontologies/open-ontologies.db`, run migrations against it, and race
+/// every other process that has it open, including each other.
+fn run(dir: &std::path::Path, args: &[&str]) -> (i32, String) {
let out = Command::new(env!("CARGO_BIN_EXE_open-ontologies"))
+ .arg("--data-dir")
+ .arg(dir.join("data"))
.args(args)
.output()
.expect("binary should run");
@@ -39,7 +45,7 @@ const GOOD: &str = "@prefix : <http://ex.org/> .\n@prefix owl: <http://www.w3.or
fn lint_fails_the_process_on_unparseable_turtle() {
let d = tempfile::tempdir().unwrap();
let f = write(d.path(), "g.ttl", GARBAGE);
- let (code, out) = run(&["lint", &f]);
+ let (code, out) = run(d.path(), &["lint", &f]);
assert_eq!(code, 1, "lint must exit non-zero. output: {out}");
assert!(out.contains("error"), "output: {out}");
}
@@ -49,7 +55,7 @@ fn lint_fails_the_process_on_unparseable_turtle() {
fn lint_does_not_report_a_clean_bill_of_health_for_unreadable_rdfxml() {
let d = tempfile::tempdir().unwrap();
let f = write(d.path(), "broken.rdf", BROKEN_XML);
- let (code, out) = run(&["lint", &f]);
+ let (code, out) = run(d.path(), &["lint", &f]);
assert_eq!(code, 1, "lint must exit non-zero. output: {out}");
assert!(
!out.contains("\"issue_count\":0"),
@@ -62,7 +68,7 @@ fn lint_does_not_report_a_clean_bill_of_health_for_unreadable_rdfxml() {
fn diff_fails_the_process_on_unparseable_input() {
let d = tempfile::tempdir().unwrap();
let f = write(d.path(), "g.ttl", GARBAGE);
- let (code, out) = run(&["diff", &f, &f]);
+ let (code, out) = run(d.path(), &["diff", &f, &f]);
assert_eq!(code, 1, "diff must exit non-zero. output: {out}");
}
@@ -70,8 +76,8 @@ fn diff_fails_the_process_on_unparseable_input() {
fn valid_input_still_succeeds() {
let d = tempfile::tempdir().unwrap();
let f = write(d.path(), "ok.ttl", GOOD);
- let (code, out) = run(&["lint", &f]);
+ let (code, out) = run(d.path(), &["lint", &f]);
assert_eq!(code, 0, "a readable ontology must still exit 0: {out}");
- let (code, out) = run(&["diff", &f, &f]);
+ let (code, out) = run(d.path(), &["diff", &f, &f]);
assert_eq!(code, 0, "two readable ontologies must still exit 0: {out}");
}
diff --git a/tests/lint_rdfxml_serialisation_test.rs b/tests/lint_rdfxml_serialisation_test.rs
index fd11507f..974d76ea 100644
--- a/tests/lint_rdfxml_serialisation_test.rs
+++ b/tests/lint_rdfxml_serialisation_test.rs
@@ -88,7 +88,12 @@ fn lint_reports_issues_on_rdfxml_rather_than_a_parse_error() {
let dir = tempfile::tempdir().unwrap();
let path = write(dir.path(), "o.owl", RDFXML);
+ // Own data dir: the binary opens `<data_dir>/open-ontologies.db` on every
+ // subcommand, so without this the test writes to the developer's real one
+ // and races the other test binaries that shell out to the CLI.
let out = Command::new(env!("CARGO_BIN_EXE_open-ontologies"))
+ .arg("--data-dir")
+ .arg(dir.path().join("data"))
.args(["lint", &path])
.output()
.expect("binary should run");
@@ -124,6 +129,8 @@ fn batch_accepts_vocab_check_under_both_spellings() {
for spelling in ["vocab-check", "vocab_check"] {
let script = format!("load {onto}\n{spelling} {data}\n");
let mut child = Command::new(env!("CARGO_BIN_EXE_open-ontologies"))
+ .arg("--data-dir")
+ .arg(dir.path().join("data"))
.args(["batch", "-"])
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())