Skip to content

Commit 9d6c087

Browse files
Joe Grundjohnsonw
andauthored
- Currently, when pulling this crate in as a dependency I am not able to (#1)
* - 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 <[email protected]> * - replace `panic` with `anyhow` Signed-off-by: William Johnson <[email protected]> --------- Signed-off-by: William Johnson <[email protected]> Co-authored-by: William Johnson <[email protected]>
1 parent dd32529 commit 9d6c087

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

commandeer-test/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Result, anyhow};
22
use escargot::CargoBuild;
33
use serde::{Deserialize, Serialize};
44
use std::{
@@ -50,6 +50,13 @@ impl RecordedCommands {
5050

5151
pub async fn load_recordings(file_path: &PathBuf) -> Result<RecordedCommands> {
5252
if !file_path.exists() {
53+
tokio::fs::create_dir_all(
54+
file_path.parent().ok_or_else(|| {
55+
anyhow!("Couldn't get parent of recording {}", file_path.display())
56+
})?,
57+
)
58+
.await?;
59+
5360
return Ok(RecordedCommands::default());
5461
}
5562

@@ -139,7 +146,9 @@ impl fmt::Display for Mode {
139146

140147
impl Commandeer {
141148
pub fn new(test_name: impl AsRef<Path>, mode: Mode) -> Self {
142-
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
149+
let dir = PathBuf::from(
150+
std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get crate directory."),
151+
);
143152

144153
DirBuilder::new()
145154
.recursive(true)
@@ -149,7 +158,7 @@ impl Commandeer {
149158
let fixture = dir.join("testcmds").join(test_name);
150159

151160
let mock_runner = CargoBuild::new()
152-
.manifest_path(dir.join("Cargo.toml"))
161+
.manifest_path(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("Cargo.toml"))
153162
.package("commandeer-cli")
154163
.bin("commandeer")
155164
.run()

0 commit comments

Comments
 (0)