| 1 |
use std::borrow::Cow; |
| 2 |
use std::env; |
| 3 |
use std::path::{Path, PathBuf}; |
| 4 |
|
| 5 |
/// The directory containing this test binary. |
| 6 |
pub fn exe_dir() -> PathBuf { |
| 7 |
let exe = env::current_exe().unwrap(); |
| 8 |
exe.parent().unwrap().to_path_buf() |
| 9 |
} |
| 10 |
|
| 11 |
/// The directory to use for test probes. |
| 12 |
pub fn out_dir() -> Cow<'static, Path> { |
| 13 |
if let Some(tmpdir) = option_env!("CARGO_TARGET_TMPDIR") { |
| 14 |
Cow::Borrowed(tmpdir.as_ref()) |
| 15 |
} else if let Some(tmpdir) = env::var_os("TESTS_TARGET_DIR") { |
| 16 |
Cow::Owned(tmpdir.into()) |
| 17 |
} else { |
| 18 |
// Use the same path as this test binary. |
| 19 |
Cow::Owned(exe_dir()) |
| 20 |
} |
| 21 |
} |