From b36f6b8e37a76d395dd44de5c5325e99fe16b621 Mon Sep 17 00:00:00 2001 From: William Johnson Date: Wed, 20 Aug 2025 17:36:07 -0400 Subject: [PATCH 1/2] - Currently, when pulling this crate in as a dependency I am not able to create a recording because it looks for the recordings under ~/.cargo.../testcmds/recording-name.json. Instead, we should use the runtime CARGO_MANIFEST_DIR, which will point to the crate where commandeer is being imported. Signed-off-by: William Johnson --- commandeer-test/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/commandeer-test/src/lib.rs b/commandeer-test/src/lib.rs index 9f267c6..3e8ed80 100644 --- a/commandeer-test/src/lib.rs +++ b/commandeer-test/src/lib.rs @@ -50,6 +50,13 @@ impl RecordedCommands { pub async fn load_recordings(file_path: &PathBuf) -> Result { if !file_path.exists() { + tokio::fs::create_dir_all( + file_path.parent().unwrap_or_else(|| { + panic!("Couldn't get parent of recording {}", file_path.display()) + }), + ) + .await?; + return Ok(RecordedCommands::default()); } @@ -139,7 +146,9 @@ impl fmt::Display for Mode { impl Commandeer { pub fn new(test_name: impl AsRef, mode: Mode) -> Self { - let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let dir = PathBuf::from( + std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get crate directory."), + ); DirBuilder::new() .recursive(true) @@ -149,7 +158,7 @@ impl Commandeer { let fixture = dir.join("testcmds").join(test_name); let mock_runner = CargoBuild::new() - .manifest_path(dir.join("Cargo.toml")) + .manifest_path(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml")) .package("commandeer-cli") .bin("commandeer") .run() From bb6022b93e2273ea19b4965d55a24bb1a1ddf231 Mon Sep 17 00:00:00 2001 From: William Johnson Date: Thu, 21 Aug 2025 11:44:26 -0400 Subject: [PATCH 2/2] - replace `panic` with `anyhow` Signed-off-by: William Johnson --- commandeer-test/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commandeer-test/src/lib.rs b/commandeer-test/src/lib.rs index 3e8ed80..7b870bb 100644 --- a/commandeer-test/src/lib.rs +++ b/commandeer-test/src/lib.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use anyhow::{Result, anyhow}; use escargot::CargoBuild; use serde::{Deserialize, Serialize}; use std::{ @@ -51,9 +51,9 @@ impl RecordedCommands { pub async fn load_recordings(file_path: &PathBuf) -> Result { if !file_path.exists() { tokio::fs::create_dir_all( - file_path.parent().unwrap_or_else(|| { - panic!("Couldn't get parent of recording {}", file_path.display()) - }), + file_path.parent().ok_or_else(|| { + anyhow!("Couldn't get parent of recording {}", file_path.display()) + })?, ) .await?;