mirror of
https://github.com/martinvonz/jj.git
synced 2024-09-21 02:38:46 +03:00
tests: add utility function to create temporary dir with stable prefix
I noticed lots of /tmp/.tmp* directories were left after running tests. This makes these directories more discoverable.
This commit is contained in:
parent
a33417fa35
commit
b0e9f1a852
@ -35,10 +35,17 @@ use crate::tree::Tree;
|
|||||||
use crate::tree_builder::TreeBuilder;
|
use crate::tree_builder::TreeBuilder;
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
|
|
||||||
|
pub fn new_temp_dir() -> TempDir {
|
||||||
|
tempfile::Builder::new()
|
||||||
|
.prefix("jj-test-")
|
||||||
|
.tempdir()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_user_home() -> TempDir {
|
pub fn new_user_home() -> TempDir {
|
||||||
// Set $HOME to some arbitrary place so libgit2 doesn't use ~/.gitignore
|
// Set $HOME to some arbitrary place so libgit2 doesn't use ~/.gitignore
|
||||||
// of the person running the tests.
|
// of the person running the tests.
|
||||||
let home_dir = tempfile::tempdir().unwrap();
|
let home_dir = new_temp_dir();
|
||||||
std::env::set_var("HOME", home_dir.path());
|
std::env::set_var("HOME", home_dir.path());
|
||||||
home_dir
|
home_dir
|
||||||
}
|
}
|
||||||
@ -62,7 +69,7 @@ pub struct TestRepo {
|
|||||||
impl TestRepo {
|
impl TestRepo {
|
||||||
pub fn init(use_git: bool) -> Self {
|
pub fn init(use_git: bool) -> Self {
|
||||||
let settings = user_settings();
|
let settings = user_settings();
|
||||||
let temp_dir = tempfile::tempdir().unwrap();
|
let temp_dir = new_temp_dir();
|
||||||
|
|
||||||
let repo_dir = temp_dir.path().join("repo");
|
let repo_dir = temp_dir.path().join("repo");
|
||||||
fs::create_dir(&repo_dir).unwrap();
|
fs::create_dir(&repo_dir).unwrap();
|
||||||
@ -94,7 +101,7 @@ pub struct TestWorkspace {
|
|||||||
|
|
||||||
impl TestWorkspace {
|
impl TestWorkspace {
|
||||||
pub fn init(settings: &UserSettings, use_git: bool) -> Self {
|
pub fn init(settings: &UserSettings, use_git: bool) -> Self {
|
||||||
let temp_dir = tempfile::tempdir().unwrap();
|
let temp_dir = new_temp_dir();
|
||||||
|
|
||||||
let workspace_root = temp_dir.path().join("repo");
|
let workspace_root = temp_dir.path().join("repo");
|
||||||
fs::create_dir(&workspace_root).unwrap();
|
fs::create_dir(&workspace_root).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user