2021-12-25 20:39:42 +01:00
|
|
|
mod test_conditionals;
|
|
|
|
mod test_converters;
|
|
|
|
mod test_custom_commands;
|
|
|
|
mod test_engine;
|
|
|
|
mod test_env;
|
|
|
|
mod test_hiding;
|
|
|
|
mod test_iteration;
|
|
|
|
mod test_math;
|
|
|
|
mod test_modules;
|
|
|
|
mod test_parser;
|
|
|
|
mod test_ranges;
|
|
|
|
mod test_strings;
|
|
|
|
mod test_table_operations;
|
|
|
|
mod test_type_check;
|
|
|
|
|
2021-07-30 22:02:16 +02:00
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::process::Command;
|
|
|
|
use tempfile::NamedTempFile;
|
2021-07-17 20:52:50 +02:00
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
pub type TestResult = Result<(), Box<dyn std::error::Error>>;
|
2021-07-30 22:02:16 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2021-12-25 20:39:42 +01:00
|
|
|
pub fn run_test(input: &str, expected: &str) -> TestResult {
|
2021-07-30 22:02:16 +02:00
|
|
|
let mut file = NamedTempFile::new()?;
|
|
|
|
let name = file.path();
|
|
|
|
|
|
|
|
let mut cmd = Command::cargo_bin("engine-q")?;
|
|
|
|
cmd.arg(name);
|
|
|
|
|
|
|
|
writeln!(file, "{}", input)?;
|
|
|
|
|
|
|
|
let output = cmd.output()?;
|
|
|
|
|
2021-07-30 23:57:22 +02:00
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
|
|
|
|
|
|
|
println!("stdout: {}", stdout);
|
|
|
|
println!("stderr: {}", stderr);
|
2021-07-30 22:02:16 +02:00
|
|
|
|
2021-07-30 23:57:22 +02:00
|
|
|
assert!(output.status.success());
|
2021-07-30 22:02:16 +02:00
|
|
|
|
2021-07-30 23:57:22 +02:00
|
|
|
assert_eq!(stdout.trim(), expected);
|
2021-07-30 22:02:16 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2021-12-25 20:39:42 +01:00
|
|
|
pub fn fail_test(input: &str, expected: &str) -> TestResult {
|
2021-07-30 22:02:16 +02:00
|
|
|
let mut file = NamedTempFile::new()?;
|
|
|
|
let name = file.path();
|
|
|
|
|
|
|
|
let mut cmd = Command::cargo_bin("engine-q")?;
|
|
|
|
cmd.arg(name);
|
2022-01-05 01:26:01 +01:00
|
|
|
cmd.env(
|
|
|
|
"PWD",
|
|
|
|
std::env::current_dir().expect("Can't get current dir"),
|
|
|
|
);
|
2021-07-30 22:02:16 +02:00
|
|
|
|
|
|
|
writeln!(file, "{}", input)?;
|
|
|
|
|
|
|
|
let output = cmd.output()?;
|
|
|
|
|
2021-08-10 07:08:10 +02:00
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
|
|
|
|
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
|
|
|
|
|
|
|
|
println!("stdout: {}", stdout);
|
|
|
|
println!("stderr: {}", stderr);
|
2021-07-30 22:02:16 +02:00
|
|
|
|
2021-08-10 07:08:10 +02:00
|
|
|
assert!(stderr.contains(expected));
|
2021-07-30 22:02:16 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:39:42 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
pub fn not_found_msg() -> &'static str {
|
2021-10-09 17:44:45 +02:00
|
|
|
if cfg!(windows) {
|
2021-12-02 21:55:16 +01:00
|
|
|
"cannot find"
|
2021-10-09 17:44:45 +02:00
|
|
|
} else {
|
2021-12-02 21:55:16 +01:00
|
|
|
"No such"
|
2021-10-09 17:44:45 +02:00
|
|
|
}
|
|
|
|
}
|