#![allow(dead_code)]
use std::path::PathBuf;
pub fn project_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("CARGO_MANIFEST_DIR should have a parent (crates/)")
.parent()
.expect("crates/ should have a parent (workspace root)")
.to_path_buf()
}
pub fn test_fixtures_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures")
}
pub fn rledger_binary() -> Option<PathBuf> {
if let Ok(path) = std::env::var("CARGO_BIN_EXE_rledger") {
return Some(PathBuf::from(path));
}
let release_path = project_root().join("target/release/rledger");
if release_path.exists() {
return Some(release_path);
}
let debug_path = project_root().join("target/debug/rledger");
if debug_path.exists() {
return Some(debug_path);
}
None
}
#[macro_export]
macro_rules! require_rledger {
() => {
match common::rledger_binary() {
Some(path) => path,
None => {
eprintln!("Skipping: rledger binary not found");
return;
}
}
};
}