1 //! `sigit --version` answers and exits without starting a session.
2
3 use std::process::{Command, Stdio};
4
5 fn version_output(flag: &str) -> std::process::Output {
6 Command::new(env!("CARGO_BIN_EXE_sigit"))
7 .arg(flag)
8 // A closed stdin: a build that mistook the flag for a session would
9 // sit in ACP mode reading it.
10 .stdin(Stdio::null())
11 .output()
12 .expect("sigit runs")
13 }
14
15 #[test]
16 fn version_flag_prints_the_release_and_exits() {
17 for flag in ["--version", "-V"] {
18 let output = version_output(flag);
19
20 assert!(output.status.success(), "{flag} exits 0");
21 assert_eq!(
22 String::from_utf8_lossy(&output.stdout),
23 format!("sigit {}\n", env!("CARGO_PKG_VERSION")),
24 "{flag} prints the release on stdout"
25 );
26 assert!(
27 output.stderr.is_empty(),
28 "{flag} logs nothing: {}",
29 String::from_utf8_lossy(&output.stderr)
30 );
31 }
32 }