use assert_cmd::Command;
use tempfile::TempDir;
fn sdivi() -> Command {
Command::cargo_bin("sdivi").expect("sdivi binary must be built")
}
fn empty_repo_with_snapshot() -> TempDir {
let repo = tempfile::tempdir().unwrap();
Command::cargo_bin("sdivi")
.expect("sdivi binary")
.arg("--repo")
.arg(repo.path())
.arg("snapshot")
.assert()
.success();
repo
}
fn has_ansi(s: &str) -> bool {
s.contains("\x1b[")
}
#[test]
fn no_color_env_suppresses_ansi_in_show() {
let repo = empty_repo_with_snapshot();
let out = sdivi()
.arg("--repo")
.arg(repo.path())
.arg("show")
.env("NO_COLOR", "1")
.output()
.unwrap();
assert!(out.status.success());
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
!has_ansi(&stdout),
"NO_COLOR=1 sdivi show stdout must not contain ANSI codes; got: {stdout:?}"
);
}
#[test]
fn no_color_env_suppresses_ansi_in_check() {
let repo = tempfile::tempdir().unwrap();
let out = sdivi()
.arg("--repo")
.arg(repo.path())
.arg("check")
.env("NO_COLOR", "1")
.output()
.unwrap();
assert!(out.status.success());
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
!has_ansi(&stdout),
"NO_COLOR=1 sdivi check stdout must not contain ANSI codes; got: {stdout:?}"
);
}
#[test]
fn no_color_env_suppresses_ansi_in_trend_insufficient_snapshots() {
let repo = tempfile::tempdir().unwrap();
let out = sdivi()
.arg("--repo")
.arg(repo.path())
.arg("trend")
.env("NO_COLOR", "1")
.output()
.unwrap();
assert!(out.status.success());
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
!has_ansi(&stdout),
"NO_COLOR=1 sdivi trend stdout must not contain ANSI codes"
);
}
#[test]
fn default_show_output_has_no_ansi_codes() {
let repo = empty_repo_with_snapshot();
let out = sdivi()
.arg("--repo")
.arg(repo.path())
.arg("show")
.output()
.unwrap();
assert!(out.status.success());
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
!has_ansi(&stdout),
"sdivi show stdout must not contain ANSI codes by default; got: {stdout:?}"
);
}