use assert_cmd::prelude::*; use predicates::prelude::*;
use std::fs::{self};
use std::process::Command;
#[test]
fn full_file_compare_no_args() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png");
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img.txt").unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
#[cfg(feature = "web_image")]
fn full_file_compare_url() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg(
"https://raw.githubusercontent.com/FineFindus/artem/master/assets/images/standard_test_img.png",
);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img.txt").unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
fn full_file_compare_border() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.arg("--border");
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_border.txt").unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
fn full_file_compare_outline() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.arg("--outline");
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_outline.txt").unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
fn full_file_compare_border_outline() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.arg("--outline")
.arg("--border");
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_border_outline.txt")
.unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
fn full_file_compare_outline_hysteresis() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.args(["--outline", "--hysteresis"]);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_outline_hysteresis.txt")
.unwrap(); cmd.assert()
.success()
.stdout(predicate::str::contains(desired_output));
}
#[test]
#[cfg(not(target_os = "windows"))]
fn full_file_compare_html() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.args(["-o", "/tmp/ascii.html"]);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img.html").unwrap(); cmd.assert().success().stdout(predicate::str::contains(
"Written 77361 bytes to /tmp/ascii.html",
));
let file_output = fs::read_to_string("/tmp/ascii.html").unwrap();
fs::remove_file("/tmp/ascii.html").unwrap();
assert_eq!(desired_output, file_output);
}
#[test]
#[cfg(not(target_os = "windows"))]
fn full_file_compare_html_border() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.args(["-o", "/tmp/ascii.html", "--border"]);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_border.html").unwrap(); cmd.assert().success().stdout(predicate::str::contains(
"Written 76075 bytes to /tmp/ascii.html",
));
let file_output = fs::read_to_string("/tmp/ascii.html").unwrap();
fs::remove_file("/tmp/ascii.html").unwrap();
assert_eq!(desired_output, file_output);
}
#[test]
#[cfg(not(target_os = "windows"))]
fn full_file_compare_html_outline() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.args(["-o", "/tmp/ascii.html", "--outline"]);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_outline.html").unwrap(); cmd.assert().success().stdout(predicate::str::contains(
"Written 77361 bytes to /tmp/ascii.html",
));
let file_output = fs::read_to_string("/tmp/ascii.html").unwrap();
fs::remove_file("/tmp/ascii.html").unwrap();
assert_eq!(desired_output, file_output);
}
#[test]
#[cfg(not(target_os = "windows"))]
fn full_file_compare_html_background_color() {
let mut cmd = Command::cargo_bin("artem").unwrap();
cmd.arg("assets/images/standard_test_img.png")
.args(["-o", "/tmp/ascii.html", "--background"]);
let desired_output =
fs::read_to_string("assets/standard_test_img/standard_test_img_background.html").unwrap(); cmd.assert().success().stdout(predicate::str::contains(
"Written 100241 bytes to /tmp/ascii.html",
));
let file_output = fs::read_to_string("/tmp/ascii.html").unwrap();
fs::remove_file("/tmp/ascii.html").unwrap();
assert_eq!(desired_output, file_output);
}