use assert_cmd::Command; use assert_fs::TempDir; use assert_fs::fixture::{PathChild, PathCreateDir}; const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); fn setup_worklane(temp: &TempDir) { let worklane = temp.child(".worklane"); worklane.create_dir_all().unwrap(); for dir in ["backlog", "committed", "reviewing", "done"] { worklane.child(dir).create_dir_all().unwrap(); } } fn run(temp: &TempDir, args: &[&str]) -> std::process::Output { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.current_dir(temp.path()).args(args); cmd.assert().get_output().clone() } /// Same message every other command gives. Checked before the terminal is, so the /// missing board is what gets reported rather than the missing tty. #[test] fn the_tui_outside_a_worklane_directory_gives_the_usual_message() { let temp = TempDir::new().unwrap(); for args in [vec!["tui"], vec![]] { let out = run(&temp, &args); let stderr = String::from_utf8_lossy(&out.stderr); assert_eq!(out.status.code(), Some(1), "{args:?}"); assert!( stderr.contains("No .worklane directory found"), "{args:?}: {stderr:?}" ); } } /// Raw mode on a pipe fails with a bare "No such device or address", which says nothing /// about the mistake. A bare `worklane` is how the board opens, so a script that lands /// here by accident has to be pointed at a subcommand. #[test] fn the_tui_without_a_terminal_says_so_and_names_an_alternative() { let temp = TempDir::new().unwrap(); setup_worklane(&temp); for args in [vec!["tui"], vec![]] { let out = run(&temp, &args); let stderr = String::from_utf8_lossy(&out.stderr); assert_eq!(out.status.code(), Some(1), "{args:?}"); assert!(stderr.contains("needs a terminal"), "{args:?}: {stderr:?}"); assert!(stderr.contains("worklane ls"), "{args:?}: {stderr:?}"); assert!( !stderr.contains("os error"), "the raw mode error leaked: {stderr:?}" ); } } /// The subcommands must keep working now that the subcommand is optional. #[test] fn an_unknown_subcommand_is_still_a_usage_error() { let temp = TempDir::new().unwrap(); setup_worklane(&temp); assert_eq!(run(&temp, &["nonsense"]).status.code(), Some(2)); assert_eq!(run(&temp, &["--bogus"]).status.code(), Some(2)); } /// `tui` has to appear in the help, or nothing points at it. #[test] fn the_help_lists_the_tui_command() { let temp = TempDir::new().unwrap(); let out = run(&temp, &["--help"]); let stdout = String::from_utf8_lossy(&out.stdout); assert!(out.status.success()); assert!(stdout.contains("tui"), "{stdout:?}"); }