just/tests/tempdir.rs
Casey Rodarmor d3492e6ffe
Use cache dir for temporary files (#2067)
Sometimes `/tmp` is mounted with the `noexec` option, which results
causes running shebang recipes to fail.

Instead of `/tmp`, use the cache directory as provided by the
[dirs crate](https://docs.rs/dirs/latest/src/dirs/lib.rs.html#77).
2024-05-21 00:04:42 +00:00

53 lines
818 B
Rust

use super::*;
pub(crate) fn tempdir() -> TempDir {
let mut builder = tempfile::Builder::new();
builder.prefix("just-test-tempdir");
if let Some(cache_dir) = dirs::cache_dir() {
let path = cache_dir.join("just");
fs::create_dir_all(&path).unwrap();
builder.tempdir_in(path)
} else {
builder.tempdir()
}
.expect("failed to create temporary directory")
}
#[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")
.stdout(if cfg!(windows) {
"
cat just*/foo
"
} else {
"
#!/usr/bin/env bash
cat just*/foo
"
})
.run();
}