Skip to content

Commit

Permalink
Move lib integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaq committed Aug 19, 2024
1 parent 0e9dc8f commit 00569f2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
47 changes: 0 additions & 47 deletions src/machine/lib_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,53 +463,6 @@ mod tests {
);
}

#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
#[ignore = "uses old flawed interface"]
fn integration_test() {
let mut machine = Machine::new_lib();

// File with test commands, i.e. program code to consult and queries to run
let code = include_str!("./lib_integration_test_commands.txt");

// Split the code into blocks
let blocks = code.split("=====");

let mut i = 0;
let mut last_result: Option<_> = None;
// Iterate over the blocks
for block in blocks {
// Trim the block to remove any leading or trailing whitespace
let block = block.trim();

// Skip empty blocks
if block.is_empty() {
continue;
}

// Check if the block is a query
if let Some(query) = block.strip_prefix("query") {
// Parse and execute the query
let result = machine.run_query(query.to_string());
assert!(result.is_ok());

last_result = Some(result);
} else if let Some(code) = block.strip_prefix("consult") {
// Load the code into the machine
machine.consult_module_string("facts", code.to_string());
} else if let Some(result) = block.strip_prefix("result") {
i += 1;
if let Some(Ok(ref last_result)) = last_result {
let _ = result;
let _ = i;
let _ = last_result;
//println!("\n\n=====Result No. {i}=======\n{last_result}\n===============");
//assert_eq!(last_result.to_string(), result.to_string().trim(),)
}
}
}
}

#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn findall() {
Expand Down
49 changes: 49 additions & 0 deletions tests/scryer_lib/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use serde_json;
use scryer_prolog::machine::Machine;

#[test]
#[cfg_attr(miri, ignore = "it takes too long to run")]
#[ignore = "uses old flawed interface"]
fn integration_test() {
let mut machine = Machine::new_lib();

// File with test commands, i.e. program code to consult and queries to run
let code = include_str!("./lib_integration_test_commands.txt");

// Split the code into blocks
let blocks = code.split("=====");

let mut i = 0;
let mut last_result: Option<_> = None;
// Iterate over the blocks
for block in blocks {
// Trim the block to remove any leading or trailing whitespace
let block = block.trim();

// Skip empty blocks
if block.is_empty() {
continue;
}

// Check if the block is a query
if let Some(query) = block.strip_prefix("query") {
// Parse and execute the query
let result = machine.run_query(query.to_string());
assert!(result.is_ok());

last_result = Some(result);
} else if let Some(code) = block.strip_prefix("consult") {
// Load the code into the machine
machine.consult_module_string("facts", code.to_string());
} else if let Some(result) = block.strip_prefix("result") {
i += 1;
if let Some(Ok(ref last_result)) = last_result {
let _ = result;
let _ = i;
let _ = last_result;
//println!("\n\n=====Result No. {i}=======\n{last_result}\n===============");
//assert_eq!(last_result.to_string(), result.to_string().trim(),)
}
}
}
}

0 comments on commit 00569f2

Please sign in to comment.