shadow_terminal/tests/
helpers.rs1#![expect(clippy::unwrap_used, reason = "It's for use in tests only")]
4
5#[inline]
9pub fn workspace_dir() -> std::path::PathBuf {
10 let output = std::process::Command::new(env!("CARGO"))
11 .arg("locate-project")
12 .arg("--workspace")
13 .arg("--message-format=plain")
14 .output()
15 .unwrap()
16 .stdout;
17 let cargo_path = std::path::Path::new(std::str::from_utf8(&output).unwrap().trim());
18 let workspace_dir = cargo_path.parent().unwrap().to_path_buf();
19 tracing::debug!("Using workspace directory: {workspace_dir:?}");
20 workspace_dir
21}
22
23#[inline]
25#[must_use]
26pub fn get_canonical_shell() -> Vec<std::ffi::OsString> {
27 #[cfg(not(target_os = "windows"))]
28 let mut shell = "bash --norc --noprofile".to_owned();
29
30 #[cfg(target_os = "windows")]
31 let mut shell = "powershell -NoProfile".to_owned();
32
33 if let Ok(custom_shell) = std::env::var("CANONICAL_SHELL") {
34 shell = custom_shell;
35 }
36
37 tracing::debug!("Use canonical shell: {shell}");
38
39 shell
40 .split_whitespace()
41 .map(std::convert::Into::into)
42 .collect()
43}
44
45#[inline]
49pub async fn run(
50 width: Option<u16>,
51 height: Option<u16>,
52) -> crate::steppable_terminal::SteppableTerminal {
53 let config = crate::shadow_terminal::Config {
54 width: width.unwrap_or(50),
55 height: height.unwrap_or(10),
56 command: get_canonical_shell(),
57 ..crate::shadow_terminal::Config::default()
58 };
59 Box::pin(crate::steppable_terminal::SteppableTerminal::start(config))
60 .await
61 .unwrap()
62}