use assert_cmd::prelude::*;
use std::fs;
use std::process::Command;
use tempfile::tempdir;
#[test]
fn prefix_trailing_slash_uses_basename() {
let in_dir = tempdir().unwrap();
let out_dir = tempdir().unwrap();
let src = in_dir.path().join("test.ept");
fs::write(
&src,
"// <( BEGIN Agent_007 )>\nhello\n// <( END Agent_007 )>\n",
)
.unwrap();
Command::cargo_bin("enprot")
.unwrap()
.arg("passthrough")
.arg("-p")
.arg(format!("{}/", out_dir.path().display()))
.arg(&src)
.assert()
.success();
let expected_out = out_dir.path().join("test.ept");
assert!(
expected_out.is_file(),
"expected output at {}",
expected_out.display()
);
}
#[test]
fn prefix_existing_dir_uses_basename() {
let in_dir = tempdir().unwrap();
let out_dir = tempdir().unwrap();
let src = in_dir.path().join("test.ept");
fs::write(
&src,
"// <( BEGIN Agent_007 )>\nhello\n// <( END Agent_007 )>\n",
)
.unwrap();
Command::cargo_bin("enprot")
.unwrap()
.arg("passthrough")
.arg("-p")
.arg(out_dir.path())
.arg(&src)
.assert()
.success();
let expected_out = out_dir.path().join("test.ept");
assert!(
expected_out.is_file(),
"expected output at {}",
expected_out.display()
);
}
#[test]
fn output_dir_flag_places_files_in_directory() {
let in_dir = tempdir().unwrap();
let out_dir = tempdir().unwrap();
let src1 = in_dir.path().join("a.ept");
let src2 = in_dir.path().join("b.ept");
fs::write(
&src1,
"// <( BEGIN Agent_007 )>\nhi\n// <( END Agent_007 )>\n",
)
.unwrap();
fs::write(
&src2,
"// <( BEGIN Agent_007 )>\nho\n// <( END Agent_007 )>\n",
)
.unwrap();
Command::cargo_bin("enprot")
.unwrap()
.arg("passthrough")
.arg("--output-dir")
.arg(out_dir.path())
.arg(&src1)
.arg(&src2)
.assert()
.success();
assert!(out_dir.path().join("a.ept").is_file());
assert!(out_dir.path().join("b.ept").is_file());
}
#[test]
fn output_dir_conflicts_with_prefix() {
let out_dir = tempdir().unwrap();
Command::cargo_bin("enprot")
.unwrap()
.arg("passthrough")
.arg("--output-dir")
.arg(out_dir.path())
.arg("-p")
.arg("some-prefix-")
.arg("-")
.assert()
.failure();
}