From 06f198bc57b0fa06fd0c3171e5c2709e0edc288d Mon Sep 17 00:00:00 2001 From: Nicolas Luck Date: Thu, 1 Feb 2024 14:14:50 +0100 Subject: [PATCH] Test show problem with nonexistent predicate --- src/machine/lib_machine.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/machine/lib_machine.rs b/src/machine/lib_machine.rs index ab16a7a4..346e0ebc 100644 --- a/src/machine/lib_machine.rs +++ b/src/machine/lib_machine.rs @@ -584,4 +584,28 @@ mod tests { let output = machine.run_query(query); assert_eq!(output, Ok(QueryResolution::False)); } + + #[test] + fn non_existent_predicate_should_not_cause_panic_when_other_predicates_are_defined() { + let mut machine = Machine::new_lib(); + + machine.consult_module_string( + "facts", + String::from( + r#" + triple("a", "p1", "b"). + triple("a", "p2", "b"). + "#, + ), + ); + + let query = String::from("non_existent_predicate(\"a\",\"p1\",\"b\")."); + + let result = machine.run_query(query); + + assert_eq!( + result, + Err(String::from("error existence_error procedure / non_existent_predicate 3 / non_existent_predicate 3")) + ); + } } -- 2.54.0