Skip to content

Commit

Permalink
(tests): Use CARGO_TARGET_TMPDIR for temporary test code
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Jan 18, 2023
1 parent 4b75305 commit 963880d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use regex::Regex;
use std::collections::HashMap;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use tempfile::Builder;
use tempfile::TempDir;
Expand Down Expand Up @@ -40,10 +41,18 @@ lazy_static! {
static ref TAG_WITH_DISTANCE: Regex = Regex::new(r"^(.+)\+(\d+)$").unwrap();
}

fn test_base_dir() -> PathBuf {
let mut base = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
base.push("tests");
base.push("git-testament");
std::fs::create_dir_all(&base).expect("Unable to create test base directory");
base
}

pub fn prep_test(name: &str) -> TestSentinel {
let outdir = Builder::new()
.prefix(&format!("test-{name}-"))
.tempdir_in(env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_owned()))
.tempdir_in(test_base_dir())
.expect("Unable to create temporary directory for test");

let mut rng = thread_rng();
Expand Down

0 comments on commit 963880d

Please sign in to comment.