use assert_cmd::Command; use predicates::prelude::*; use serde_json::Value; fn cargo_command() -> Command { Command::cargo_bin("msudo").expect("binary") } #[test] fn help_mentions_dangerous_flag_and_shell_presets() { let mut command = cargo_command(); command .arg("--help") .assert() .success() .stdout(predicate::str::contains( "current-process, current-user, admin, system, trustedinstaller", )) .stdout(predicate::str::contains("--dangerous")) .stdout(predicate::str::contains("trustedinstaller")) .stdout(predicate::str::contains("Shell preset")) .stdout(predicate::str::contains("pwsh")) .stdout(predicate::str::contains("git-bash")); } #[test] fn status_json_exposes_stable_top_level_fields() { let output = cargo_command() .args(["status", "--json"]) .assert() .success() .get_output() .stdout .clone(); let report: Value = serde_json::from_slice(&output).expect("valid status json"); let object = report.as_object().expect("status json object"); for field in [ "ok", "host", "supports_runas", "is_elevated", "is_admin_member", "integrity", "current_user", "session_id", "active_session_id", "can_admin", "can_current_user", "can_system", "can_trustedinstaller", "trustedinstaller_installed", "trustedinstaller_running", "shells", ] { assert!(object.contains_key(field), "missing status field: {field}"); } assert_eq!(object.get("ok").and_then(Value::as_bool), Some(true)); assert!(matches!(object.get("host"), Some(Value::String(_)))); assert!(matches!(object.get("supports_runas"), Some(Value::Bool(_)))); assert!(matches!(object.get("is_elevated"), Some(Value::Bool(_)))); assert!(matches!( object.get("is_admin_member"), Some(Value::Bool(_)) )); assert!(matches!(object.get("integrity"), Some(Value::String(_)))); assert!(matches!( object.get("current_user"), Some(Value::Null | Value::String(_)) )); assert!(matches!( object.get("session_id"), Some(Value::Null | Value::Number(_)) )); assert!(matches!( object.get("active_session_id"), Some(Value::Null | Value::Number(_)) )); for field in [ "can_admin", "can_current_user", "can_system", "can_trustedinstaller", "trustedinstaller_installed", "trustedinstaller_running", ] { assert!( matches!(object.get(field), Some(Value::Bool(_))), "status field should be boolean: {field}" ); } let shells = object .get("shells") .and_then(Value::as_array) .expect("shells array"); assert!(!shells.is_empty(), "shell preset list should not be empty"); let first_shell = shells[0].as_object().expect("shell status object"); for field in ["preset", "available", "executable", "error"] { assert!( first_shell.contains_key(field), "missing shell status field: {field}" ); } } #[test] fn help_mentions_console_and_window_launch_controls() { let mut command = cargo_command(); command .arg("--help") .assert() .success() .stdout(predicate::str::contains( "current-process, current-user, admin, system, trustedinstaller", )) .stdout(predicate::str::contains("--same-console")) .stdout(predicate::str::contains("Reuse the current console")) .stdout(predicate::str::contains("--new-window")) .stdout(predicate::str::contains( "Force a new window for the launched process", )); }