diff options
-rw-r--r-- | cli/deno_dir.rs | 11 | ||||
-rw-r--r-- | cli/tests/integration/cache_tests.rs | 30 |
2 files changed, 36 insertions, 5 deletions
diff --git a/cli/deno_dir.rs b/cli/deno_dir.rs index 674d32c51..ca6f8b81f 100644 --- a/cli/deno_dir.rs +++ b/cli/deno_dir.rs @@ -16,11 +16,7 @@ pub struct DenoDir { impl DenoDir { pub fn new(maybe_custom_root: Option<PathBuf>) -> std::io::Result<Self> { let root: PathBuf = if let Some(root) = maybe_custom_root { - if root.is_absolute() { - root - } else { - std::env::current_dir()?.join(root) - } + root } else if let Some(cache_dir) = dirs::cache_dir() { // We use the OS cache dir because all files deno writes are cache files // Once that changes we need to start using different roots if DENO_DIR @@ -32,6 +28,11 @@ impl DenoDir { } else { panic!("Could not set the Deno root directory") }; + let root = if root.is_absolute() { + root + } else { + std::env::current_dir()?.join(root) + }; assert!(root.is_absolute()); let gen_path = root.join("gen"); diff --git a/cli/tests/integration/cache_tests.rs b/cli/tests/integration/cache_tests.rs index 773f98f6b..f7d9fb486 100644 --- a/cli/tests/integration/cache_tests.rs +++ b/cli/tests/integration/cache_tests.rs @@ -48,3 +48,33 @@ itest!(ignore_require { output_str: Some(""), exit_code: 0, }); + +// This test only runs on linux, because it hardcodes the XDG_CACHE_HOME env var +// which is only used on linux. +#[cfg(target_os = "linux")] +#[test] +fn relative_home_dir() { + use tempfile::TempDir; + use test_util as util; + + let deno_dir = TempDir::new_in(util::testdata_path()).unwrap(); + let path = deno_dir.path().strip_prefix(util::testdata_path()).unwrap(); + + let mut deno_cmd = util::deno_cmd(); + let output = deno_cmd + .current_dir(util::testdata_path()) + .env("XDG_CACHE_HOME", path) + .env_remove("HOME") + .env_remove("DENO_DIR") + .arg("cache") + .arg("--reload") + .arg("--no-check") + .arg("002_hello.ts") + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + assert_eq!(output.stdout, b""); +} |