mod common;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use common::Staged;
fn fixtures() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/unit_mutation")
}
fn run(language: &str, project: &Path, config: &str) -> Output {
Command::new(env!("CARGO_BIN_EXE_testing-conventions"))
.args(["unit", "mutation", "--language", language, "--config"])
.arg(fixtures().join(config))
.arg(project)
.output()
.expect("the built binary should run")
}
fn code(output: &Output) -> i32 {
output
.status
.code()
.expect("the process should exit with a code")
}
fn stderr(output: &Output) -> String {
String::from_utf8_lossy(&output.stderr).into_owned()
}
#[test]
fn rust_exempting_the_survivor_line_passes() {
let out = run(
"rust",
&fixtures().join("rust").join("survivors"),
"lines_mut_rust_ok.toml",
);
assert_eq!(code(&out), 0, "stderr: {}", stderr(&out));
}
#[test]
fn rust_over_exempting_a_caught_line_is_a_hard_error() {
let out = run(
"rust",
&fixtures().join("rust").join("killed"),
"lines_mut_rust_over.toml",
);
assert_eq!(code(&out), 1, "stderr: {}", stderr(&out));
assert!(
stderr(&out).contains("all caught"),
"expected an over-exemption guard error, got: {}",
stderr(&out)
);
}
#[test]
fn typescript_exempting_both_survivor_lines_passes() {
let project = Staged::new("survivors");
let out = run("typescript", project.path(), "lines_mut_ts_ok.toml");
assert_eq!(code(&out), 0, "stderr: {}", stderr(&out));
}
#[test]
fn typescript_under_listing_still_fails() {
let project = Staged::new("survivors");
let out = run("typescript", project.path(), "lines_mut_ts_under.toml");
assert_eq!(code(&out), 1, "stderr: {}", stderr(&out));
assert!(
stderr(&out).contains("unexplained"),
"expected the unlisted survivor to fail the gate, got: {}",
stderr(&out)
);
}
#[test]
fn typescript_over_exempting_a_caught_line_is_a_hard_error() {
let project = Staged::new("killed");
let out = run("typescript", project.path(), "lines_mut_ts_over.toml");
assert_eq!(code(&out), 1, "stderr: {}", stderr(&out));
assert!(
stderr(&out).contains("all caught"),
"expected an over-exemption guard error, got: {}",
stderr(&out)
);
}
#[test]
fn python_exempting_both_survivor_lines_passes() {
let project = Staged::python("survivors");
let out = run("python", project.path(), "lines_mut_py_ok.toml");
assert_eq!(code(&out), 0, "stderr: {}", stderr(&out));
}
#[test]
fn python_over_exempting_a_caught_line_is_a_hard_error() {
let project = Staged::python("killed");
let out = run("python", project.path(), "lines_mut_py_over.toml");
assert_eq!(code(&out), 1, "stderr: {}", stderr(&out));
assert!(
stderr(&out).contains("all caught"),
"expected an over-exemption guard error, got: {}",
stderr(&out)
);
}