Skip to content

Implement guardSet and logger tests #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions metta-run/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,65 @@ fn test_nested_constraint_tree_formatter() {

assert_eq!(String::from_utf8_lossy(&output.stdout), expected_output);
}

#[test]
fn test_guard_set_formatter() {
use std::process::Command;

let output = Command::new("cargo")
.arg("run")
.arg("tests/resources/guard_set.metta")
.arg("fgt")
.output()
.expect("failed to execute process");

let expected_output = "[(TreeNode (Value Nil False OR)\n└──GuardSets's\n ├─(TreeNode (Value B True LITERAL)\n ├─(TreeNode (Value D True LITERAL)\n ├─(TreeNode (Value E False LITERAL)\n";
assert_eq!(String::from_utf8_lossy(&output.stdout), expected_output);
}
/// test logger functions
#[test]
fn test_logger() {
use std::fs::File;
use std::io::Read;
use core::panic;
use std::{io::BufRead, process::Command};
use chrono::Local;

let now = Local::now();

let log_file = format!(
"{}/metta-bin/{}.log",
std::env::var("HOME").unwrap(),
chrono::Local::now().format("%Y-%m-%d").to_string()
);

let output = Command::new("cargo")
.arg("run")
.arg("--")
.arg("tests/resources/metta_run.metta")
.output()
.expect("failed to execute process")
.stdout
.lines()
.last()
.unwrap();

let metta_output = match output {
Ok(output) => output.to_string(),
Err(_) => panic!("Error reading output"),
};

let expected_output = vec![
metta_output,
format!("Start time: {}", now.format("%Y-%m-%d %H-%m").to_string()),
];

let mut file = File::open(&log_file).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();

let last_three_lines = contents.lines().rev().take(3).collect::<Vec<&str>>();
let output = vec![last_three_lines[0], &last_three_lines[2][..28]];

assert_eq!(output, expected_output);
}
Loading