57 lines
2.2 KiB
Rust
57 lines
2.2 KiB
Rust
//! Startup contracts that must hold before entering terminal raw mode.
|
|
use std::process::{Command, Output};
|
|
|
|
fn run(args: &[&str]) -> Output {
|
|
Command::new(env!("CARGO_BIN_EXE_efo-tui"))
|
|
.args(args)
|
|
.output()
|
|
.expect("run efo-tui")
|
|
}
|
|
|
|
#[test]
|
|
fn help_and_version_work_without_a_terminal() {
|
|
let help = run(&["--help"]);
|
|
assert!(help.status.success());
|
|
let text = String::from_utf8_lossy(&help.stdout);
|
|
assert!(text.contains("--repository <PATH>"));
|
|
assert!(text.contains("--no-color"));
|
|
assert!(text.contains("read-only"));
|
|
assert!(text.contains("HEAD/index/worktree"));
|
|
assert!(run(&["--version"]).status.success());
|
|
}
|
|
|
|
#[test]
|
|
fn repository_failure_is_actionable_and_emits_no_terminal_controls() {
|
|
let temp = tempfile::tempdir().expect("tempdir");
|
|
let output = run(&["--repository", temp.path().to_str().expect("path")]);
|
|
assert!(!output.status.success());
|
|
let error = String::from_utf8_lossy(&output.stderr);
|
|
assert!(error.contains("could not open"));
|
|
assert!(error.contains("efo status"));
|
|
assert!(error.contains(temp.path().to_str().expect("path")));
|
|
assert!(output.stdout.is_empty());
|
|
assert!(!output.stderr.contains(&0x1b));
|
|
}
|
|
|
|
#[test]
|
|
fn redirected_startup_fails_cleanly_without_writing_repository() {
|
|
let temp = tempfile::tempdir().expect("tempdir");
|
|
let workspace = lib_efo::workspace::Workspace::initialize(temp.path(), "test").expect("init");
|
|
let manifest = std::fs::read(temp.path().join(".epoch")).expect("manifest");
|
|
let worktree = std::fs::read(temp.path().join(".efo/worktree.json")).expect("worktree");
|
|
let output = run(&["--repository", workspace.root().to_str().expect("path")]);
|
|
assert!(!output.status.success());
|
|
assert!(String::from_utf8_lossy(&output.stderr).contains("interactive terminal"));
|
|
assert!(output.stdout.is_empty());
|
|
assert!(!output.stderr.contains(&0x1b));
|
|
assert_eq!(
|
|
std::fs::read(temp.path().join(".epoch")).expect("manifest"),
|
|
manifest
|
|
);
|
|
assert_eq!(
|
|
std::fs::read(temp.path().join(".efo/worktree.json")).expect("worktree"),
|
|
worktree
|
|
);
|
|
assert!(!temp.path().join(".efo/lock").exists());
|
|
}
|