2022-10-25 16:57:20 -07:00
|
|
|
use super::*;
|
|
|
|
|
2023-10-16 20:07:09 -07:00
|
|
|
pub(crate) fn tempdir() -> TempDir {
|
2024-05-20 17:04:42 -07:00
|
|
|
let mut builder = tempfile::Builder::new();
|
|
|
|
|
|
|
|
builder.prefix("just-test-tempdir");
|
|
|
|
|
2024-06-05 12:03:14 -07:00
|
|
|
if let Some(runtime_dir) = dirs::runtime_dir() {
|
|
|
|
let path = runtime_dir.join("just");
|
2024-05-20 17:04:42 -07:00
|
|
|
fs::create_dir_all(&path).unwrap();
|
|
|
|
builder.tempdir_in(path)
|
|
|
|
} else {
|
|
|
|
builder.tempdir()
|
|
|
|
}
|
|
|
|
.expect("failed to create temporary directory")
|
2021-07-03 14:26:59 -07:00
|
|
|
}
|
2022-10-25 16:57:20 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tempdir_is_set() {
|
|
|
|
Test::new()
|
|
|
|
.justfile(
|
|
|
|
"
|
|
|
|
set tempdir := '.'
|
|
|
|
foo:
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
cat just*/foo
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.shell(false)
|
|
|
|
.tree(tree! {
|
|
|
|
foo: {
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.current_dir("foo")
|
2022-11-19 12:38:41 -08:00
|
|
|
.stdout(if cfg!(windows) {
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cat just*/foo
|
|
|
|
"
|
|
|
|
} else {
|
2022-10-25 16:57:20 -07:00
|
|
|
"
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
|
|
cat just*/foo
|
2022-11-19 12:38:41 -08:00
|
|
|
"
|
|
|
|
})
|
2022-10-25 16:57:20 -07:00
|
|
|
.run();
|
|
|
|
}
|