From: Nicolas Luck Date: Thu, 1 Feb 2024 13:14:50 +0000 (+0100) Subject: Test show problem with nonexistent predicate X-Git-Tag: v0.9.4~3^2~13 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=06f198bc57b0fa06fd0c3171e5c2709e0edc288d;p=scryer-prolog.git Test show problem with nonexistent predicate --- 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")) + ); + } }