mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
chore(tests): use custom temp dir creation for the tests (#14153)
This commit is contained in:
parent
8ca4c1819f
commit
1c37ac3352
33 changed files with 385 additions and 247 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4455,6 +4455,7 @@ dependencies = [
|
|||
"futures",
|
||||
"hyper",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"os_pipe",
|
||||
"parking_lot 0.11.2",
|
||||
"pretty_assertions",
|
||||
|
@ -4463,7 +4464,6 @@ dependencies = [
|
|||
"rustls-pemfile 0.2.1",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-tungstenite",
|
||||
|
|
|
@ -86,11 +86,11 @@ regex = "=1.5.5"
|
|||
ring = "=0.16.20"
|
||||
rustyline = { version = "=9.1.2", default-features = false }
|
||||
rustyline-derive = "=0.6.0"
|
||||
secure_tempfile = { version = "=3.2.0", package = "tempfile" } # different name to discourage use in tests
|
||||
semver-parser = "=0.10.2"
|
||||
serde = { version = "=1.0.136", features = ["derive"] }
|
||||
shell-escape = "=0.1.5"
|
||||
sourcemap = "=6.0.1"
|
||||
tempfile = "=3.2.0"
|
||||
text-size = "=1.1.0"
|
||||
text_lines = "=0.4.1"
|
||||
tokio = { version = "=1.14", features = ["full"] }
|
||||
|
|
|
@ -351,7 +351,7 @@ fn run_strace_benchmarks(
|
|||
let mut syscall_count = HashMap::<String, u64>::new();
|
||||
|
||||
for (name, args, expected_exit_code) in EXEC_TIME_BENCHMARKS {
|
||||
let mut file = tempfile::NamedTempFile::new()?;
|
||||
let mut file = secure_tempfile::NamedTempFile::new()?;
|
||||
|
||||
let exit_status = Command::new("strace")
|
||||
.args(&[
|
||||
|
|
|
@ -150,11 +150,11 @@ impl DiskCache {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_create_cache_if_dir_exits() {
|
||||
let cache_location = TempDir::new().unwrap();
|
||||
let cache_location = TempDir::new();
|
||||
let mut cache_path = cache_location.path().to_owned();
|
||||
cache_path.push("foo");
|
||||
let cache = DiskCache::new(&cache_path);
|
||||
|
@ -166,7 +166,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_create_cache_if_dir_not_exits() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut cache_location = temp_dir.path().to_owned();
|
||||
assert!(fs::remove_dir(&cache_location).is_ok());
|
||||
cache_location.push("foo");
|
||||
|
|
|
@ -745,13 +745,12 @@ mod tests {
|
|||
use deno_core::resolve_url_or_path;
|
||||
use deno_runtime::deno_web::Blob;
|
||||
use deno_runtime::deno_web::InMemoryBlobPart;
|
||||
use std::rc::Rc;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn setup(
|
||||
cache_setting: CacheSetting,
|
||||
maybe_temp_dir: Option<Rc<TempDir>>,
|
||||
) -> (FileFetcher, Rc<TempDir>) {
|
||||
maybe_temp_dir: Option<TempDir>,
|
||||
) -> (FileFetcher, TempDir) {
|
||||
let (file_fetcher, temp_dir, _) =
|
||||
setup_with_blob_store(cache_setting, maybe_temp_dir);
|
||||
(file_fetcher, temp_dir)
|
||||
|
@ -759,10 +758,9 @@ mod tests {
|
|||
|
||||
fn setup_with_blob_store(
|
||||
cache_setting: CacheSetting,
|
||||
maybe_temp_dir: Option<Rc<TempDir>>,
|
||||
) -> (FileFetcher, Rc<TempDir>, BlobStore) {
|
||||
let temp_dir =
|
||||
maybe_temp_dir.unwrap_or_else(|| Rc::new(TempDir::new().unwrap()));
|
||||
maybe_temp_dir: Option<TempDir>,
|
||||
) -> (FileFetcher, TempDir, BlobStore) {
|
||||
let temp_dir = maybe_temp_dir.unwrap_or_default();
|
||||
let location = temp_dir.path().join("deps");
|
||||
let blob_store = BlobStore::default();
|
||||
let file_fetcher = FileFetcher::new(
|
||||
|
@ -1227,7 +1225,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_fetch_uses_cache() {
|
||||
let _http_server_guard = test_util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("deps");
|
||||
let file_fetcher_01 = FileFetcher::new(
|
||||
HttpCache::new(&location),
|
||||
|
@ -1397,7 +1395,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_fetch_uses_cache_with_redirects() {
|
||||
let _http_server_guard = test_util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("deps");
|
||||
let file_fetcher_01 = FileFetcher::new(
|
||||
HttpCache::new(&location),
|
||||
|
@ -1526,7 +1524,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_fetch_no_remote() {
|
||||
let _http_server_guard = test_util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("deps");
|
||||
let file_fetcher = FileFetcher::new(
|
||||
HttpCache::new(&location),
|
||||
|
@ -1551,7 +1549,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_fetch_cache_only() {
|
||||
let _http_server_guard = test_util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("deps");
|
||||
let file_fetcher_01 = FileFetcher::new(
|
||||
HttpCache::new(&location),
|
||||
|
@ -1618,7 +1616,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_respect_cache_revalidates() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = Rc::new(TempDir::new().unwrap());
|
||||
let temp_dir = TempDir::new();
|
||||
let (file_fetcher, _) =
|
||||
setup(CacheSetting::RespectHeaders, Some(temp_dir.clone()));
|
||||
let specifier =
|
||||
|
@ -1645,7 +1643,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_respect_cache_still_fresh() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = Rc::new(TempDir::new().unwrap());
|
||||
let temp_dir = TempDir::new();
|
||||
let (file_fetcher, _) =
|
||||
setup(CacheSetting::RespectHeaders, Some(temp_dir.clone()));
|
||||
let specifier =
|
||||
|
|
10
cli/flags.rs
10
cli/flags.rs
|
@ -3796,8 +3796,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn allow_read_allowlist() {
|
||||
use tempfile::TempDir;
|
||||
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
||||
use test_util::TempDir;
|
||||
let temp_dir_guard = TempDir::new();
|
||||
let temp_dir = temp_dir_guard.path().to_path_buf();
|
||||
|
||||
let r = flags_from_vec(svec![
|
||||
"deno",
|
||||
|
@ -3819,8 +3820,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn allow_write_allowlist() {
|
||||
use tempfile::TempDir;
|
||||
let temp_dir = TempDir::new().expect("tempdir fail").path().to_path_buf();
|
||||
use test_util::TempDir;
|
||||
let temp_dir_guard = TempDir::new();
|
||||
let temp_dir = temp_dir_guard.path().to_path_buf();
|
||||
|
||||
let r = flags_from_vec(svec![
|
||||
"deno",
|
||||
|
|
|
@ -406,7 +406,7 @@ pub fn path_with_stem_suffix(path: &Path, suffix: &str) -> PathBuf {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn resolve_from_cwd_child() {
|
||||
|
@ -548,7 +548,7 @@ mod tests {
|
|||
// ├── g.d.ts
|
||||
// └── .gitignore
|
||||
|
||||
let t = TempDir::new().expect("tempdir fail");
|
||||
let t = TempDir::new();
|
||||
|
||||
let root_dir_path = t.path().join("dir.ts");
|
||||
let root_dir_files = ["a.ts", "b.js", "c.tsx", "d.jsx"];
|
||||
|
@ -609,7 +609,7 @@ mod tests {
|
|||
// ├── g.d.ts
|
||||
// └── .gitignore
|
||||
|
||||
let t = TempDir::new().expect("tempdir fail");
|
||||
let t = TempDir::new();
|
||||
|
||||
let root_dir_path = t.path().join("dir.ts");
|
||||
let root_dir_files = ["a.ts", "b.js", "c.tsx", "d.jsx"];
|
||||
|
|
|
@ -188,11 +188,11 @@ mod tests {
|
|||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Read;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_create_cache() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let mut cache_path = dir.path().to_owned();
|
||||
cache_path.push("foobar");
|
||||
// HttpCache should be created lazily on first use:
|
||||
|
@ -219,7 +219,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_set() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let cache = HttpCache::new(dir.path());
|
||||
let url = Url::parse("https://deno.land/x/welcome.ts").unwrap();
|
||||
let mut headers = HashMap::new();
|
||||
|
|
|
@ -138,11 +138,9 @@ mod tests {
|
|||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::io::Write;
|
||||
use tempfile::TempDir;
|
||||
|
||||
fn setup() -> (TempDir, PathBuf) {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
use test_util::TempDir;
|
||||
|
||||
fn setup(temp_dir: &TempDir) -> PathBuf {
|
||||
let file_path = temp_dir.path().join("valid_lockfile.json");
|
||||
let mut file = File::create(file_path).expect("write file fail");
|
||||
|
||||
|
@ -153,13 +151,7 @@ mod tests {
|
|||
|
||||
file.write_all(value.to_string().as_bytes()).unwrap();
|
||||
|
||||
let file_path = temp_dir.path().join("valid_lockfile.json");
|
||||
|
||||
(temp_dir, file_path)
|
||||
}
|
||||
|
||||
fn teardown(temp_dir: TempDir) {
|
||||
temp_dir.close().expect("file close error");
|
||||
temp_dir.path().join("valid_lockfile.json")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -170,7 +162,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn new_valid_lockfile() {
|
||||
let (temp_dir, file_path) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let file_path = setup(&temp_dir);
|
||||
|
||||
let result = Lockfile::new(file_path, false).unwrap();
|
||||
|
||||
|
@ -182,13 +175,12 @@ mod tests {
|
|||
|
||||
assert_eq!(keys.len(), 2);
|
||||
assert_eq!(keys, expected_keys);
|
||||
|
||||
teardown(temp_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_lockfile_from_file_and_insert() {
|
||||
let (temp_dir, file_path) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let file_path = setup(&temp_dir);
|
||||
|
||||
let mut lockfile = Lockfile::new(file_path, false).unwrap();
|
||||
|
||||
|
@ -205,13 +197,12 @@ mod tests {
|
|||
];
|
||||
assert_eq!(keys.len(), 3);
|
||||
assert_eq!(keys, expected_keys);
|
||||
|
||||
teardown(temp_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_lockfile_and_write() {
|
||||
let (temp_dir, file_path) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let file_path = setup(&temp_dir);
|
||||
|
||||
let mut lockfile = Lockfile::new(file_path, true).unwrap();
|
||||
|
||||
|
@ -264,13 +255,12 @@ mod tests {
|
|||
Some("https://deno.land/std@0.71.0/textproto/mod.ts")
|
||||
);
|
||||
assert!(keys.next().is_none());
|
||||
|
||||
teardown(temp_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_or_insert_lockfile_false() {
|
||||
let (temp_dir, file_path) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let file_path = setup(&temp_dir);
|
||||
|
||||
let mut lockfile = Lockfile::new(file_path, false).unwrap();
|
||||
|
||||
|
@ -290,7 +280,5 @@ mod tests {
|
|||
"This is new Source code",
|
||||
);
|
||||
assert!(!check_false);
|
||||
|
||||
teardown(temp_dir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -578,7 +578,7 @@ mod tests {
|
|||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn mock_documents(
|
||||
fixtures: &[(&str, &str, i32, LanguageId)],
|
||||
|
@ -612,10 +612,10 @@ mod tests {
|
|||
}
|
||||
|
||||
fn setup(
|
||||
temp_dir: &TempDir,
|
||||
documents: &[(&str, &str, i32, LanguageId)],
|
||||
sources: &[(&str, &str)],
|
||||
) -> Documents {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
let location = temp_dir.path().join("deps");
|
||||
mock_documents(documents, sources, &location)
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_local_completions() {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
let temp_dir = TempDir::new();
|
||||
let fixtures = temp_dir.path().join("fixtures");
|
||||
std::fs::create_dir(&fixtures).expect("could not create");
|
||||
let dir_a = fixtures.join("a");
|
||||
|
@ -776,7 +776,9 @@ mod tests {
|
|||
character: 21,
|
||||
},
|
||||
};
|
||||
let temp_dir = TempDir::new();
|
||||
let documents = setup(
|
||||
&temp_dir,
|
||||
&[
|
||||
(
|
||||
"file:///a/b/c.ts",
|
||||
|
|
|
@ -884,7 +884,7 @@ mod tests {
|
|||
use crate::lsp::language_server::StateSnapshot;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn mock_state_snapshot(
|
||||
fixtures: &[(&str, &str, i32, LanguageId)],
|
||||
|
@ -922,9 +922,9 @@ mod tests {
|
|||
}
|
||||
|
||||
fn setup(
|
||||
temp_dir: &TempDir,
|
||||
sources: &[(&str, &str, i32, LanguageId)],
|
||||
) -> (StateSnapshot, PathBuf) {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
let location = temp_dir.path().join("deps");
|
||||
let state_snapshot = mock_state_snapshot(sources, &location);
|
||||
(state_snapshot, location)
|
||||
|
@ -932,16 +932,20 @@ mod tests {
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_enabled_then_disabled_specifier() {
|
||||
let temp_dir = TempDir::new();
|
||||
let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap();
|
||||
let (snapshot, _) = setup(&[(
|
||||
"file:///a.ts",
|
||||
r#"import * as b from "./b.ts";
|
||||
let (snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
&[(
|
||||
"file:///a.ts",
|
||||
r#"import * as b from "./b.ts";
|
||||
let a: any = "a";
|
||||
let c: number = "a";
|
||||
"#,
|
||||
1,
|
||||
LanguageId::TypeScript,
|
||||
)]);
|
||||
1,
|
||||
LanguageId::TypeScript,
|
||||
)],
|
||||
);
|
||||
let snapshot = Arc::new(snapshot);
|
||||
let ts_server = TsServer::new(Default::default());
|
||||
|
||||
|
@ -1026,12 +1030,16 @@ let c: number = "a";
|
|||
|
||||
#[tokio::test]
|
||||
async fn test_cancelled_ts_diagnostics_request() {
|
||||
let (snapshot, _) = setup(&[(
|
||||
"file:///a.ts",
|
||||
r#"export let a: string = 5;"#,
|
||||
1,
|
||||
LanguageId::TypeScript,
|
||||
)]);
|
||||
let temp_dir = TempDir::new();
|
||||
let (snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
&[(
|
||||
"file:///a.ts",
|
||||
r#"export let a: string = 5;"#,
|
||||
1,
|
||||
LanguageId::TypeScript,
|
||||
)],
|
||||
);
|
||||
let snapshot = Arc::new(snapshot);
|
||||
let ts_server = TsServer::new(Default::default());
|
||||
|
||||
|
|
|
@ -1134,10 +1134,9 @@ impl Documents {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn setup() -> (Documents, PathBuf) {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
fn setup(temp_dir: &TempDir) -> (Documents, PathBuf) {
|
||||
let location = temp_dir.path().join("deps");
|
||||
let documents = Documents::new(&location);
|
||||
(documents, location)
|
||||
|
@ -1145,7 +1144,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_documents_open() {
|
||||
let (mut documents, _) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut documents, _) = setup(&temp_dir);
|
||||
let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap();
|
||||
let content = Arc::new(
|
||||
r#"import * as b from "./b.ts";
|
||||
|
@ -1161,7 +1161,8 @@ console.log(b);
|
|||
|
||||
#[test]
|
||||
fn test_documents_change() {
|
||||
let (mut documents, _) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut documents, _) = setup(&temp_dir);
|
||||
let specifier = ModuleSpecifier::parse("file:///a.ts").unwrap();
|
||||
let content = Arc::new(
|
||||
r#"import * as b from "./b.ts";
|
||||
|
@ -1207,7 +1208,8 @@ console.log(b, "hello deno");
|
|||
fn test_documents_ensure_no_duplicates() {
|
||||
// it should never happen that a user of this API causes this to happen,
|
||||
// but we'll guard against it anyway
|
||||
let (mut documents, documents_path) = setup();
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut documents, documents_path) = setup(&temp_dir);
|
||||
let file_path = documents_path.join("file.ts");
|
||||
let file_specifier = ModuleSpecifier::from_file_path(&file_path).unwrap();
|
||||
fs::create_dir_all(&documents_path).unwrap();
|
||||
|
|
|
@ -1050,7 +1050,7 @@ impl ModuleRegistry {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_validate_registry_configuration() {
|
||||
|
@ -1205,7 +1205,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_registry_completions_origin_match() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let mut module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
@ -1266,7 +1266,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_registry_completions() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let mut module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
@ -1489,7 +1489,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_registry_completions_key_first() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let mut module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
@ -1559,7 +1559,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_registry_completions_complex() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let mut module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
@ -1610,7 +1610,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_check_origin_supported() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
@ -1621,7 +1621,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_check_origin_not_supported() {
|
||||
let _g = test_util::http_server();
|
||||
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||
let temp_dir = TempDir::new();
|
||||
let location = temp_dir.path().join("registries");
|
||||
let module_registry =
|
||||
ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap();
|
||||
|
|
|
@ -3298,7 +3298,7 @@ mod tests {
|
|||
use crate::lsp::text::LineIndex;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::TempDir;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn mock_state_snapshot(
|
||||
fixtures: &[(&str, &str, i32, LanguageId)],
|
||||
|
@ -3322,11 +3322,11 @@ mod tests {
|
|||
}
|
||||
|
||||
fn setup(
|
||||
temp_dir: &TempDir,
|
||||
debug: bool,
|
||||
config: Value,
|
||||
sources: &[(&str, &str, i32, LanguageId)],
|
||||
) -> (JsRuntime, Arc<StateSnapshot>, PathBuf) {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
let location = temp_dir.path().join("deps");
|
||||
let state_snapshot = Arc::new(mock_state_snapshot(sources, &location));
|
||||
let mut runtime = js_runtime(Default::default());
|
||||
|
@ -3363,7 +3363,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_project_configure() {
|
||||
let temp_dir = TempDir::new();
|
||||
setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3376,7 +3378,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_project_reconfigure() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3404,7 +3408,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_diagnostics() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3453,7 +3459,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_get_diagnostics_lib() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3483,7 +3491,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_module_resolution() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3518,7 +3528,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bad_module_specifiers() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3569,7 +3581,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_remote_modules() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3604,7 +3618,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_partial_modules() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3676,7 +3692,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_no_debug_failure() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3726,7 +3744,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_request_asset() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3752,7 +3772,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_modify_sources() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, location) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3839,7 +3861,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_op_exists() {
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut rt, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
@ -3910,7 +3934,9 @@ mod tests {
|
|||
character: 16,
|
||||
})
|
||||
.unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let (mut runtime, state_snapshot, _) = setup(
|
||||
&temp_dir,
|
||||
false,
|
||||
json!({
|
||||
"target": "esnext",
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::itest;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn bundle_exports() {
|
||||
// First we have to generate a bundle of some module that has exports.
|
||||
let mod1 = util::testdata_path().join("subdir/mod1.ts");
|
||||
assert!(mod1.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod1.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -51,7 +51,7 @@ fn bundle_exports_no_check() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let mod1 = util::testdata_path().join("subdir/mod1.ts");
|
||||
assert!(mod1.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod1.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -94,7 +94,7 @@ fn bundle_circular() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let circular1 = util::testdata_path().join("subdir/circular1.ts");
|
||||
assert!(circular1.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("circular1.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -126,7 +126,7 @@ fn bundle_single_module() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let single_module = util::testdata_path().join("subdir/single_module.ts");
|
||||
assert!(single_module.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("single_module.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -158,7 +158,7 @@ fn bundle_tla() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let tla_import = util::testdata_path().join("subdir/tla.ts");
|
||||
assert!(tla_import.is_file());
|
||||
let t = tempfile::TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("tla.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -200,7 +200,7 @@ fn bundle_js() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let mod6 = util::testdata_path().join("subdir/mod6.js");
|
||||
assert!(mod6.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod6.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -228,7 +228,7 @@ fn bundle_dynamic_import() {
|
|||
let _g = util::http_server();
|
||||
let dynamic_import = util::testdata_path().join("bundle_dynamic_import.ts");
|
||||
assert!(dynamic_import.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("bundle_dynamic_import.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -262,7 +262,7 @@ fn bundle_import_map() {
|
|||
let import = util::testdata_path().join("bundle_im.ts");
|
||||
let import_map_path = util::testdata_path().join("bundle_im.json");
|
||||
assert!(import.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("import_map.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -306,7 +306,7 @@ fn bundle_import_map_no_check() {
|
|||
let import = util::testdata_path().join("bundle_im.ts");
|
||||
let import_map_path = util::testdata_path().join("bundle_im.json");
|
||||
assert!(import.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("import_map.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -351,7 +351,7 @@ fn bundle_json_module() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let mod7 = util::testdata_path().join("subdir/mod7.js");
|
||||
assert!(mod7.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod7.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -383,7 +383,7 @@ fn bundle_json_module_escape_sub() {
|
|||
// First we have to generate a bundle of some module that has exports.
|
||||
let mod8 = util::testdata_path().join("subdir/mod8.js");
|
||||
assert!(mod8.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod8.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
|
|
@ -54,10 +54,10 @@ itest!(ignore_require {
|
|||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn relative_home_dir() {
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
let deno_dir = TempDir::new_in(util::testdata_path()).unwrap();
|
||||
let deno_dir = TempDir::new_in(&util::testdata_path());
|
||||
let path = deno_dir.path().strip_prefix(util::testdata_path()).unwrap();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd();
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
use std::fs::File;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn compile() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("welcome.exe")
|
||||
} else {
|
||||
|
@ -38,7 +38,7 @@ fn compile() {
|
|||
|
||||
#[test]
|
||||
fn standalone_args() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("args.exe")
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ fn standalone_args() {
|
|||
|
||||
#[test]
|
||||
fn standalone_error() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("error.exe")
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ fn standalone_error() {
|
|||
|
||||
#[test]
|
||||
fn standalone_error_module_with_imports() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("error.exe")
|
||||
} else {
|
||||
|
@ -156,7 +156,7 @@ fn standalone_error_module_with_imports() {
|
|||
|
||||
#[test]
|
||||
fn standalone_load_datauri() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("load_datauri.exe")
|
||||
} else {
|
||||
|
@ -221,7 +221,7 @@ fn standalone_follow_redirects() {
|
|||
|
||||
#[test]
|
||||
fn standalone_compiler_ops() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("standalone_compiler_ops.exe")
|
||||
} else {
|
||||
|
@ -253,7 +253,7 @@ fn standalone_compiler_ops() {
|
|||
|
||||
#[test]
|
||||
fn compile_with_directory_output_flag() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let output_path = if cfg!(windows) {
|
||||
dir.path().join(r"args\random\")
|
||||
} else {
|
||||
|
@ -291,7 +291,7 @@ fn compile_with_directory_output_flag() {
|
|||
|
||||
#[test]
|
||||
fn compile_with_file_exists_error() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let output_path = if cfg!(windows) {
|
||||
dir.path().join(r"args\")
|
||||
} else {
|
||||
|
@ -326,7 +326,7 @@ fn compile_with_file_exists_error() {
|
|||
|
||||
#[test]
|
||||
fn compile_with_directory_exists_error() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("args.exe")
|
||||
} else {
|
||||
|
@ -360,7 +360,7 @@ fn compile_with_directory_exists_error() {
|
|||
|
||||
#[test]
|
||||
fn compile_with_conflict_file_exists_error() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("args.exe")
|
||||
} else {
|
||||
|
@ -398,7 +398,7 @@ fn compile_with_conflict_file_exists_error() {
|
|||
|
||||
#[test]
|
||||
fn compile_and_overwrite_file() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("args.exe")
|
||||
} else {
|
||||
|
@ -436,7 +436,7 @@ fn compile_and_overwrite_file() {
|
|||
|
||||
#[test]
|
||||
fn standalone_runtime_flags() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("flags.exe")
|
||||
} else {
|
||||
|
@ -475,7 +475,7 @@ fn standalone_runtime_flags() {
|
|||
|
||||
#[test]
|
||||
fn standalone_import_map() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("import_map.exe")
|
||||
} else {
|
||||
|
@ -510,7 +510,7 @@ fn standalone_import_map() {
|
|||
#[test]
|
||||
// https://github.com/denoland/deno/issues/12670
|
||||
fn skip_rebundle() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let dir = TempDir::new();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("hello_world.exe")
|
||||
} else {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::fs;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn branch() {
|
||||
|
@ -20,11 +20,11 @@ fn final_blankline() {
|
|||
}
|
||||
|
||||
fn run_coverage_text(test_name: &str, extension: &str) {
|
||||
let deno_dir = TempDir::new().unwrap();
|
||||
let tempdir = TempDir::new().unwrap();
|
||||
let deno_dir = TempDir::new();
|
||||
let tempdir = TempDir::new();
|
||||
let tempdir = tempdir.path().join("cov");
|
||||
|
||||
let status = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("test")
|
||||
.arg("--quiet")
|
||||
|
@ -38,7 +38,7 @@ fn run_coverage_text(test_name: &str, extension: &str) {
|
|||
|
||||
assert!(status.success());
|
||||
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("coverage")
|
||||
.arg("--unstable")
|
||||
|
@ -68,7 +68,7 @@ fn run_coverage_text(test_name: &str, extension: &str) {
|
|||
|
||||
assert!(output.status.success());
|
||||
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("coverage")
|
||||
.arg("--quiet")
|
||||
|
@ -100,11 +100,11 @@ fn run_coverage_text(test_name: &str, extension: &str) {
|
|||
|
||||
#[test]
|
||||
fn multifile_coverage() {
|
||||
let deno_dir = TempDir::new().unwrap();
|
||||
let tempdir = TempDir::new().unwrap();
|
||||
let deno_dir = TempDir::new();
|
||||
let tempdir = TempDir::new();
|
||||
let tempdir = tempdir.path().join("cov");
|
||||
|
||||
let status = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let status = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("test")
|
||||
.arg("--quiet")
|
||||
|
@ -118,7 +118,7 @@ fn multifile_coverage() {
|
|||
|
||||
assert!(status.success());
|
||||
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("coverage")
|
||||
.arg("--unstable")
|
||||
|
@ -148,7 +148,7 @@ fn multifile_coverage() {
|
|||
|
||||
assert!(output.status.success());
|
||||
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("coverage")
|
||||
.arg("--quiet")
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::itest;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn fmt_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let fixed_js = util::testdata_path().join("badly_formatted_fixed.js");
|
||||
let badly_formatted_original_js =
|
||||
util::testdata_path().join("badly_formatted.mjs");
|
||||
|
@ -135,7 +135,8 @@ fn fmt_auto_ignore_git() {
|
|||
let mut bad_json_file = File::create(bad_json_path).unwrap();
|
||||
writeln!(bad_json_file, "bad json").unwrap();
|
||||
}
|
||||
let t = TempDir::new().unwrap().path().join("target");
|
||||
let temp_dir = TempDir::new();
|
||||
let t = temp_dir.path().join("target");
|
||||
let nest_git = t.join("nest").join(".git");
|
||||
let git_dir = t.join(".git");
|
||||
create_dir_all(&nest_git).unwrap();
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::itest;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn info_with_compiled_source() {
|
||||
let _g = util::http_server();
|
||||
let module_path = "http://127.0.0.1:4545/048_media_types_jsx.ts";
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
|
||||
let mut deno = util::deno_cmd()
|
||||
.env("DENO_DIR", t.path())
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn install_basic() {
|
||||
let _guard = util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
||||
|
||||
let status = util::deno_cmd()
|
||||
|
@ -50,7 +50,7 @@ fn install_basic() {
|
|||
#[test]
|
||||
fn install_custom_dir_env_var() {
|
||||
let _guard = util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
|
||||
|
||||
let status = util::deno_cmd()
|
||||
|
@ -87,7 +87,7 @@ fn install_custom_dir_env_var() {
|
|||
|
||||
#[test]
|
||||
fn installer_test_local_module_run() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
let status = util::deno_cmd()
|
||||
|
@ -124,7 +124,7 @@ fn installer_test_local_module_run() {
|
|||
#[test]
|
||||
fn installer_test_remote_module_run() {
|
||||
let _g = util::http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
let status = util::deno_cmd()
|
||||
|
|
|
@ -12,11 +12,11 @@ use lspower::lsp;
|
|||
use pretty_assertions::assert_eq;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use tempfile::TempDir;
|
||||
use test_util::deno_exe_path;
|
||||
use test_util::http_server;
|
||||
use test_util::lsp::LspClient;
|
||||
use test_util::testdata_path;
|
||||
use test_util::TempDir;
|
||||
|
||||
fn load_fixture(path: &str) -> Value {
|
||||
load_fixture_as(path)
|
||||
|
@ -233,7 +233,7 @@ fn lsp_startup_shutdown() {
|
|||
|
||||
#[test]
|
||||
fn lsp_init_tsconfig() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let tsconfig =
|
||||
|
@ -276,7 +276,7 @@ fn lsp_init_tsconfig() {
|
|||
fn lsp_tsconfig_types() {
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let tsconfig =
|
||||
serde_json::to_vec_pretty(&load_fixture("types.tsconfig.json")).unwrap();
|
||||
fs::write(temp_dir.path().join("types.tsconfig.json"), tsconfig).unwrap();
|
||||
|
@ -341,9 +341,9 @@ fn lsp_tsconfig_bad_config_path() {
|
|||
|
||||
#[test]
|
||||
fn lsp_triple_slash_types() {
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let a_dts = load_fixture_str("a.d.ts");
|
||||
fs::write(temp_dir.path().join("a.d.ts"), a_dts).unwrap();
|
||||
|
||||
|
@ -377,7 +377,7 @@ fn lsp_triple_slash_types() {
|
|||
|
||||
#[test]
|
||||
fn lsp_import_map() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let import_map =
|
||||
|
@ -488,7 +488,7 @@ fn lsp_import_map_data_url() {
|
|||
|
||||
#[test]
|
||||
fn lsp_import_map_config_file() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
|
||||
|
@ -581,7 +581,7 @@ fn lsp_import_map_config_file() {
|
|||
|
||||
#[test]
|
||||
fn lsp_deno_task() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let workspace_root = temp_dir.path().canonicalize().unwrap();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
|
@ -704,7 +704,7 @@ fn lsp_import_assertions() {
|
|||
|
||||
#[test]
|
||||
fn lsp_import_map_import_completions() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let import_map =
|
||||
|
@ -1073,7 +1073,7 @@ fn lsp_workspace_enable_paths() {
|
|||
// we aren't actually writing anything to the tempdir in this test, but we
|
||||
// just need a legitimate file path on the host system so that logic that
|
||||
// tries to convert to and from the fs paths works on all env
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
|
||||
let root_specifier =
|
||||
ensure_directory_specifier(Url::from_file_path(temp_dir.path()).unwrap());
|
||||
|
@ -1458,7 +1458,8 @@ fn lsp_hover_change_mbc() {
|
|||
|
||||
#[test]
|
||||
fn lsp_hover_closed_document() {
|
||||
let temp_dir = TempDir::new().unwrap().into_path();
|
||||
let temp_dir_guard = TempDir::new();
|
||||
let temp_dir = temp_dir_guard.path();
|
||||
let a_path = temp_dir.join("a.ts");
|
||||
fs::write(a_path, r#"export const a = "a";"#).unwrap();
|
||||
let b_path = temp_dir.join("b.ts");
|
||||
|
@ -3669,7 +3670,7 @@ fn lsp_auto_discover_registry() {
|
|||
#[test]
|
||||
fn lsp_cache_location() {
|
||||
let _g = http_server();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params_registry.json"))
|
||||
.unwrap();
|
||||
|
@ -4395,7 +4396,7 @@ fn lsp_format_mbc() {
|
|||
|
||||
#[test]
|
||||
fn lsp_format_exclude_with_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let deno_fmt_jsonc =
|
||||
|
@ -4450,7 +4451,7 @@ fn lsp_format_exclude_with_config() {
|
|||
|
||||
#[test]
|
||||
fn lsp_format_exclude_default_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let workspace_root = temp_dir.path().canonicalize().unwrap();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
|
@ -4675,7 +4676,7 @@ fn lsp_format_markdown() {
|
|||
|
||||
#[test]
|
||||
fn lsp_format_with_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let deno_fmt_jsonc =
|
||||
|
@ -5154,7 +5155,7 @@ console.log(snake_case);
|
|||
|
||||
#[test]
|
||||
fn lsp_lint_with_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let deno_lint_jsonc =
|
||||
|
@ -5186,7 +5187,7 @@ fn lsp_lint_with_config() {
|
|||
|
||||
#[test]
|
||||
fn lsp_lint_exclude_with_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let deno_lint_jsonc =
|
||||
|
@ -5346,7 +5347,7 @@ struct TestRunResponseParams {
|
|||
fn lsp_testing_api() {
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
|
||||
let root_specifier =
|
||||
ensure_directory_specifier(Url::from_file_path(temp_dir.path()).unwrap());
|
||||
|
|
|
@ -12,8 +12,8 @@ use std::io::Cursor;
|
|||
use std::io::{Read, Write};
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
use tokio::task::LocalSet;
|
||||
|
||||
#[macro_export]
|
||||
|
@ -139,7 +139,7 @@ itest!(types {
|
|||
#[test]
|
||||
fn cache_test() {
|
||||
let _g = util::http_server();
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let module_url =
|
||||
url::Url::parse("http://localhost:4545/006_url_imports.ts").unwrap();
|
||||
let output = Command::new(util::deno_exe_path())
|
||||
|
@ -184,7 +184,7 @@ fn cache_test() {
|
|||
|
||||
#[test]
|
||||
fn cache_invalidation_test() {
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let fixture_path = deno_dir.path().join("fixture.ts");
|
||||
{
|
||||
let mut file = std::fs::File::create(fixture_path.clone())
|
||||
|
@ -224,7 +224,7 @@ fn cache_invalidation_test() {
|
|||
|
||||
#[test]
|
||||
fn cache_invalidation_test_no_check() {
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let fixture_path = deno_dir.path().join("fixture.ts");
|
||||
{
|
||||
let mut file = std::fs::File::create(fixture_path.clone())
|
||||
|
@ -266,7 +266,7 @@ fn cache_invalidation_test_no_check() {
|
|||
|
||||
#[test]
|
||||
fn ts_dependency_recompilation() {
|
||||
let t = TempDir::new().expect("tempdir fail");
|
||||
let t = TempDir::new();
|
||||
let ats = t.path().join("a.ts");
|
||||
|
||||
std::fs::write(
|
||||
|
@ -365,8 +365,8 @@ fn ts_reload() {
|
|||
let hello_ts = util::testdata_path().join("002_hello.ts");
|
||||
assert!(hello_ts.is_file());
|
||||
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let mut initial = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let deno_dir = TempDir::new();
|
||||
let mut initial = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("cache")
|
||||
.arg(&hello_ts)
|
||||
|
@ -376,7 +376,7 @@ fn ts_reload() {
|
|||
initial.wait().expect("failed to wait for child process");
|
||||
assert!(status_initial.success());
|
||||
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("cache")
|
||||
.arg("--reload")
|
||||
|
@ -539,7 +539,7 @@ itest!(localhost_unsafe_ssl {
|
|||
fn cafile_env_fetch() {
|
||||
use deno_core::url::Url;
|
||||
let _g = util::http_server();
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let module_url =
|
||||
Url::parse("https://localhost:5545/cafile_url_imports.ts").unwrap();
|
||||
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
||||
|
@ -558,7 +558,7 @@ fn cafile_env_fetch() {
|
|||
fn cafile_fetch() {
|
||||
use deno_core::url::Url;
|
||||
let _g = util::http_server();
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let module_url =
|
||||
Url::parse("http://localhost:4545/cafile_url_imports.ts").unwrap();
|
||||
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
||||
|
@ -579,10 +579,10 @@ fn cafile_fetch() {
|
|||
#[flaky_test::flaky_test]
|
||||
fn cafile_install_remote_module() {
|
||||
let _g = util::http_server();
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
||||
|
||||
let install_output = Command::new(util::deno_exe_path())
|
||||
|
@ -625,7 +625,7 @@ fn cafile_bundle_remote_exports() {
|
|||
// First we have to generate a bundle of some remote module that has exports.
|
||||
let mod1 = "https://localhost:5545/subdir/mod1.ts";
|
||||
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
||||
let t = TempDir::new().expect("tempdir fail");
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod1.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -1095,7 +1095,7 @@ fn typecheck_declarations_unstable() {
|
|||
|
||||
#[test]
|
||||
fn typecheck_core() {
|
||||
let deno_dir = TempDir::new().expect("tempdir fail");
|
||||
let deno_dir = TempDir::new();
|
||||
let test_file = deno_dir.path().join("test_deno_core_types.ts");
|
||||
std::fs::write(
|
||||
&test_file,
|
||||
|
@ -1111,7 +1111,7 @@ fn typecheck_core() {
|
|||
),
|
||||
)
|
||||
.unwrap();
|
||||
let output = util::deno_cmd_with_deno_dir(deno_dir.path())
|
||||
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
||||
.arg("run")
|
||||
.arg(test_file.to_str().unwrap())
|
||||
.output()
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use deno_core::url;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
itest!(stdout_write_all {
|
||||
args: "run --quiet stdout_write_all.ts",
|
||||
|
@ -253,7 +253,7 @@ itest!(webstorage_serialization {
|
|||
fn webstorage_location_shares_origin() {
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -268,7 +268,7 @@ fn webstorage_location_shares_origin() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -290,7 +290,7 @@ fn webstorage_location_shares_origin() {
|
|||
fn webstorage_config_file() {
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -305,7 +305,7 @@ fn webstorage_config_file() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -320,7 +320,7 @@ fn webstorage_config_file() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -342,7 +342,7 @@ fn webstorage_config_file() {
|
|||
fn webstorage_location_precedes_config() {
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -359,7 +359,7 @@ fn webstorage_location_precedes_config() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -383,7 +383,7 @@ fn webstorage_location_precedes_config() {
|
|||
fn webstorage_main_module() {
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -396,7 +396,7 @@ fn webstorage_main_module() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -409,7 +409,7 @@ fn webstorage_main_module() {
|
|||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Storage { length: 0 }\n");
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -466,7 +466,7 @@ itest!(_082_prepare_stack_trace_throw {
|
|||
#[test]
|
||||
fn _083_legacy_external_source_map() {
|
||||
let _g = util::http_server();
|
||||
let deno_dir = TempDir::new().unwrap();
|
||||
let deno_dir = TempDir::new();
|
||||
let module_url =
|
||||
url::Url::parse("http://localhost:4545/083_legacy_external_source_map.ts")
|
||||
.unwrap();
|
||||
|
@ -1804,7 +1804,7 @@ fn rust_log() {
|
|||
fn dont_cache_on_check_fail() {
|
||||
let deno_dir = util::new_deno_dir();
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -1818,7 +1818,7 @@ fn dont_cache_on_check_fail() {
|
|||
assert!(!output.status.success());
|
||||
assert!(!output.stderr.is_empty());
|
||||
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let output = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -2368,7 +2368,7 @@ itest!(eval_context_throw_dom_exception {
|
|||
fn issue12453() {
|
||||
let _g = util::http_server();
|
||||
let deno_dir = util::new_deno_dir();
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(deno_dir.path());
|
||||
let mut deno_cmd = util::deno_cmd_with_deno_dir(&deno_dir);
|
||||
let status = deno_cmd
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("run")
|
||||
|
@ -2385,7 +2385,7 @@ fn issue12453() {
|
|||
/// Regression test for https://github.com/denoland/deno/issues/12740.
|
||||
#[test]
|
||||
fn issue12740() {
|
||||
let mod_dir = TempDir::new().unwrap();
|
||||
let mod_dir = TempDir::new();
|
||||
let mod1_path = mod_dir.path().join("mod1.ts");
|
||||
let mod2_path = mod_dir.path().join("mod2.ts");
|
||||
let mut deno_cmd = util::deno_cmd();
|
||||
|
@ -2419,7 +2419,7 @@ fn issue12740() {
|
|||
/// Regression test for https://github.com/denoland/deno/issues/12807.
|
||||
#[test]
|
||||
fn issue12807() {
|
||||
let mod_dir = TempDir::new().unwrap();
|
||||
let mod_dir = TempDir::new();
|
||||
let mod1_path = mod_dir.path().join("mod1.ts");
|
||||
let mod2_path = mod_dir.path().join("mod2.ts");
|
||||
let mut deno_cmd = util::deno_cmd();
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use std::process::{Command, Stdio};
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
// Warning: this test requires internet access.
|
||||
// TODO(#7412): reenable. test is flaky
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_in_tmpdir() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
@ -31,10 +31,7 @@ fn upgrade_in_tmpdir() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_with_space_in_path() {
|
||||
let temp_dir = tempfile::Builder::new()
|
||||
.prefix("directory with spaces")
|
||||
.tempdir()
|
||||
.unwrap();
|
||||
let temp_dir = TempDir::new_with_prefix("directory with spaces");
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
@ -54,7 +51,7 @@ fn upgrade_with_space_in_path() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_with_version_in_tmpdir() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
@ -83,7 +80,7 @@ fn upgrade_with_version_in_tmpdir() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_with_canary_in_tmpdir() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
@ -112,7 +109,7 @@ fn upgrade_with_canary_in_tmpdir() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_with_out_in_tmpdir() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let new_exe_path = temp_dir.path().join("foo");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
|
@ -149,7 +146,7 @@ fn upgrade_with_out_in_tmpdir() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_invalid_stable_version() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
@ -174,7 +171,7 @@ fn upgrade_invalid_stable_version() {
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn upgrade_invalid_canary_version() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let exe_path = temp_dir.path().join("deno");
|
||||
let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap();
|
||||
assert!(exe_path.exists());
|
||||
|
|
|
@ -6,13 +6,13 @@ use pretty_assertions::assert_eq;
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Stdio;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
use util::http_server;
|
||||
|
||||
#[test]
|
||||
fn output_dir_exists() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor");
|
||||
fs::write(t.path().join("mod.ts"), "").unwrap();
|
||||
fs::create_dir_all(&vendor_dir).unwrap();
|
||||
|
@ -75,7 +75,7 @@ fn output_dir_exists() {
|
|||
|
||||
#[test]
|
||||
fn import_map_output_dir() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor");
|
||||
fs::write(t.path().join("mod.ts"), "").unwrap();
|
||||
fs::create_dir_all(&vendor_dir).unwrap();
|
||||
|
@ -109,7 +109,7 @@ fn import_map_output_dir() {
|
|||
#[test]
|
||||
fn standard_test() {
|
||||
let _server = http_server();
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor2");
|
||||
fs::write(
|
||||
t.path().join("my_app.ts"),
|
||||
|
@ -186,7 +186,7 @@ fn standard_test() {
|
|||
#[test]
|
||||
fn remote_module_test() {
|
||||
let _server = http_server();
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor");
|
||||
|
||||
let deno = util::deno_cmd()
|
||||
|
@ -239,7 +239,7 @@ fn remote_module_test() {
|
|||
#[test]
|
||||
fn existing_import_map() {
|
||||
let _server = http_server();
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor");
|
||||
fs::write(
|
||||
t.path().join("mod.ts"),
|
||||
|
@ -274,7 +274,7 @@ fn existing_import_map() {
|
|||
#[test]
|
||||
fn dynamic_import() {
|
||||
let _server = http_server();
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let vendor_dir = t.path().join("vendor");
|
||||
fs::write(
|
||||
t.path().join("mod.ts"),
|
||||
|
@ -327,7 +327,7 @@ fn dynamic_import() {
|
|||
#[test]
|
||||
fn dynamic_non_analyzable_import() {
|
||||
let _server = http_server();
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
fs::write(
|
||||
t.path().join("mod.ts"),
|
||||
"import {Logger} from 'http://localhost:4545/vendor/dynamic_non_analyzable.ts'; new Logger().log('outputted');",
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
use flaky_test::flaky_test;
|
||||
use std::fs::write;
|
||||
use std::io::BufRead;
|
||||
use tempfile::TempDir;
|
||||
use test_util as util;
|
||||
use test_util::TempDir;
|
||||
|
||||
const CLEAR_SCREEN: &str = r#"[2J"#;
|
||||
|
||||
|
@ -88,7 +88,7 @@ fn child_lines(
|
|||
|
||||
#[test]
|
||||
fn lint_watch_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let badly_linted_original =
|
||||
util::testdata_path().join("lint/watch/badly_linted.js");
|
||||
let badly_linted_output =
|
||||
|
@ -147,7 +147,7 @@ fn lint_watch_test() {
|
|||
|
||||
#[test]
|
||||
fn lint_watch_without_args_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let badly_linted_original =
|
||||
util::testdata_path().join("lint/watch/badly_linted.js");
|
||||
let badly_linted_output =
|
||||
|
@ -206,7 +206,7 @@ fn lint_watch_without_args_test() {
|
|||
|
||||
#[test]
|
||||
fn lint_all_files_on_each_change_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let badly_linted_fixed0 =
|
||||
util::testdata_path().join("lint/watch/badly_linted.js");
|
||||
let badly_linted_fixed1 =
|
||||
|
@ -245,7 +245,7 @@ fn lint_all_files_on_each_change_test() {
|
|||
|
||||
#[test]
|
||||
fn fmt_watch_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let fixed = util::testdata_path().join("badly_formatted_fixed.js");
|
||||
let badly_formatted_original =
|
||||
util::testdata_path().join("badly_formatted.mjs");
|
||||
|
@ -295,7 +295,7 @@ fn fmt_watch_test() {
|
|||
|
||||
#[test]
|
||||
fn fmt_watch_without_args_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let fixed = util::testdata_path().join("badly_formatted_fixed.js");
|
||||
let badly_formatted_original =
|
||||
util::testdata_path().join("badly_formatted.mjs");
|
||||
|
@ -343,7 +343,7 @@ fn fmt_watch_without_args_test() {
|
|||
|
||||
#[test]
|
||||
fn fmt_check_all_files_on_each_change_test() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let badly_formatted_original =
|
||||
util::testdata_path().join("badly_formatted.mjs");
|
||||
let badly_formatted_1 = t.path().join("badly_formatted_1.js");
|
||||
|
@ -384,11 +384,11 @@ fn fmt_check_all_files_on_each_change_test() {
|
|||
fn bundle_js_watch() {
|
||||
use std::path::PathBuf;
|
||||
// Test strategy extends this of test bundle_js by adding watcher
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.ts");
|
||||
write(&file_to_watch, "console.log('Hello world');").unwrap();
|
||||
assert!(file_to_watch.is_file());
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let bundle = t.path().join("mod6.bundle.js");
|
||||
let mut deno = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -439,7 +439,7 @@ fn bundle_js_watch() {
|
|||
/// Confirm that the watcher continues to work even if module resolution fails at the *first* attempt
|
||||
#[test]
|
||||
fn bundle_watch_not_exit() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.ts");
|
||||
write(&file_to_watch, "syntax error ^^").unwrap();
|
||||
let target_file = t.path().join("target.js");
|
||||
|
@ -485,7 +485,7 @@ fn bundle_watch_not_exit() {
|
|||
|
||||
#[flaky_test::flaky_test]
|
||||
fn run_watch() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(&file_to_watch, "console.log('Hello world');").unwrap();
|
||||
|
||||
|
@ -568,7 +568,7 @@ fn run_watch() {
|
|||
|
||||
#[test]
|
||||
fn run_watch_external_watch_files() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(&file_to_watch, "console.log('Hello world');").unwrap();
|
||||
|
||||
|
@ -609,7 +609,7 @@ fn run_watch_external_watch_files() {
|
|||
|
||||
#[test]
|
||||
fn run_watch_load_unload_events() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(
|
||||
&file_to_watch,
|
||||
|
@ -677,7 +677,7 @@ fn run_watch_load_unload_events() {
|
|||
/// Confirm that the watcher continues to work even if module resolution fails at the *first* attempt
|
||||
#[test]
|
||||
fn run_watch_not_exit() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(&file_to_watch, "syntax error ^^").unwrap();
|
||||
|
||||
|
@ -727,7 +727,7 @@ fn run_watch_with_import_map_and_relative_paths() {
|
|||
assert!(relative_path.is_relative());
|
||||
relative_path
|
||||
}
|
||||
let temp_directory = TempDir::new_in(util::testdata_path()).unwrap();
|
||||
let temp_directory = TempDir::new_in(&util::testdata_path());
|
||||
let file_to_watch = create_relative_tmp_file(
|
||||
&temp_directory,
|
||||
"file_to_watch.js",
|
||||
|
@ -764,7 +764,7 @@ fn run_watch_with_import_map_and_relative_paths() {
|
|||
|
||||
#[flaky_test]
|
||||
fn test_watch() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
|
||||
let mut child = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -908,7 +908,7 @@ fn test_watch() {
|
|||
|
||||
#[flaky_test]
|
||||
fn test_watch_doc() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
|
||||
let mut child = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
|
@ -961,7 +961,7 @@ fn test_watch_doc() {
|
|||
|
||||
#[test]
|
||||
fn test_watch_module_graph_error_referrer() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(&file_to_watch, "import './nonexistent.js';").unwrap();
|
||||
let mut child = util::deno_cmd()
|
||||
|
@ -991,7 +991,7 @@ fn test_watch_module_graph_error_referrer() {
|
|||
|
||||
#[test]
|
||||
fn watch_with_no_clear_screen_flag() {
|
||||
let t = TempDir::new().unwrap();
|
||||
let t = TempDir::new();
|
||||
let file_to_watch = t.path().join("file_to_watch.js");
|
||||
write(&file_to_watch, "export const foo = 0;").unwrap();
|
||||
|
||||
|
|
|
@ -401,8 +401,8 @@ mod tests {
|
|||
use super::*;
|
||||
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
use test_util::testdata_path;
|
||||
use test_util::TempDir;
|
||||
|
||||
#[test]
|
||||
fn install_infer_name_from_url() {
|
||||
|
@ -479,7 +479,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_unstable() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
||||
|
@ -663,7 +663,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_local_module() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
let local_module = env::current_dir().unwrap().join("echo_server.ts");
|
||||
|
@ -694,7 +694,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_force() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
||||
|
@ -755,7 +755,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_with_config() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
let config_file_path = temp_dir.path().join("test_tsconfig.json");
|
||||
let config = "{}";
|
||||
|
@ -791,7 +791,7 @@ mod tests {
|
|||
#[cfg(not(windows))]
|
||||
#[test]
|
||||
fn install_shell_escaping() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
||||
|
@ -826,7 +826,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_unicode() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
let unicode_dir = temp_dir.path().join("Magnús");
|
||||
|
@ -866,7 +866,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn install_with_import_map() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
let import_map_path = temp_dir.path().join("import_map.json");
|
||||
let import_map_url = Url::from_file_path(&import_map_path).unwrap();
|
||||
|
@ -914,7 +914,7 @@ mod tests {
|
|||
// Regression test for https://github.com/denoland/deno/issues/10556.
|
||||
#[test]
|
||||
fn install_file_url() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
let module_path = fs::canonicalize(testdata_path().join("cat.ts")).unwrap();
|
||||
let file_module_string =
|
||||
|
@ -950,7 +950,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn uninstall_basic() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let temp_dir = TempDir::new();
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ use std::io::Write;
|
|||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
static ARCHIVE_NAME: Lazy<String> =
|
||||
Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
|
||||
|
@ -230,7 +229,7 @@ pub fn unpack(
|
|||
// We use into_path so that the tempdir is not automatically deleted. This is
|
||||
// useful for debugging upgrade, but also so this function can return a path
|
||||
// to the newly uncompressed file without fear of the tempdir being deleted.
|
||||
let temp_dir = TempDir::new()?.into_path();
|
||||
let temp_dir = secure_tempfile::TempDir::new()?.into_path();
|
||||
let exe_ext = if is_windows { "exe" } else { "" };
|
||||
let archive_path = temp_dir.join(EXE_NAME).with_extension("zip");
|
||||
let exe_path = temp_dir.join(EXE_NAME).with_extension(exe_ext);
|
||||
|
|
|
@ -19,6 +19,7 @@ base64 = "0.13.0"
|
|||
futures = "0.3.21"
|
||||
hyper = { version = "0.14.12", features = ["server", "http1", "http2", "runtime"] }
|
||||
lazy_static = "1.4.0"
|
||||
once_cell = "1.10.0"
|
||||
os_pipe = "1.0.1"
|
||||
parking_lot = "0.11.1"
|
||||
pretty_assertions = "=1.2.0"
|
||||
|
@ -26,7 +27,6 @@ regex = "1.5.5"
|
|||
rustls-pemfile = "0.2.1"
|
||||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
serde_json = "1.0.65"
|
||||
tempfile = "3.2.0"
|
||||
tokio = { version = "1.10.1", features = ["full"] }
|
||||
tokio-rustls = "0.23"
|
||||
tokio-tungstenite = "0.16"
|
||||
|
|
|
@ -28,6 +28,8 @@ use std::io::Read;
|
|||
use std::io::Write;
|
||||
use std::mem::replace;
|
||||
use std::net::SocketAddr;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::process::Child;
|
||||
|
@ -40,7 +42,6 @@ use std::sync::Mutex;
|
|||
use std::sync::MutexGuard;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use tempfile::TempDir;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::net::TcpStream;
|
||||
|
@ -50,6 +51,9 @@ use tokio_tungstenite::accept_async;
|
|||
|
||||
pub mod lsp;
|
||||
pub mod pty;
|
||||
mod temp_dir;
|
||||
|
||||
pub use temp_dir::TempDir;
|
||||
|
||||
const PORT: u16 = 4545;
|
||||
const TEST_AUTH_TOKEN: &str = "abcdef123456789";
|
||||
|
@ -1654,20 +1658,42 @@ pub fn run_and_collect_output_with_args(
|
|||
}
|
||||
|
||||
pub fn new_deno_dir() -> TempDir {
|
||||
TempDir::new().expect("tempdir fail")
|
||||
TempDir::new()
|
||||
}
|
||||
|
||||
pub fn deno_cmd() -> Command {
|
||||
pub struct DenoCmd {
|
||||
// keep the deno dir directory alive for the duration of the command
|
||||
_deno_dir: TempDir,
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
impl Deref for DenoCmd {
|
||||
type Target = Command;
|
||||
fn deref(&self) -> &Command {
|
||||
&self.cmd
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for DenoCmd {
|
||||
fn deref_mut(&mut self) -> &mut Command {
|
||||
&mut self.cmd
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deno_cmd() -> DenoCmd {
|
||||
let deno_dir = new_deno_dir();
|
||||
deno_cmd_with_deno_dir(deno_dir.path())
|
||||
deno_cmd_with_deno_dir(&deno_dir)
|
||||
}
|
||||
|
||||
pub fn deno_cmd_with_deno_dir(deno_dir: &std::path::Path) -> Command {
|
||||
let e = deno_exe_path();
|
||||
assert!(e.exists());
|
||||
let mut c = Command::new(e);
|
||||
c.env("DENO_DIR", deno_dir);
|
||||
c
|
||||
pub fn deno_cmd_with_deno_dir(deno_dir: &TempDir) -> DenoCmd {
|
||||
let exe_path = deno_exe_path();
|
||||
assert!(exe_path.exists());
|
||||
let mut cmd = Command::new(exe_path);
|
||||
cmd.env("DENO_DIR", deno_dir.path());
|
||||
DenoCmd {
|
||||
_deno_dir: deno_dir.clone(),
|
||||
cmd,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_powershell_script_file(
|
||||
|
@ -1735,7 +1761,8 @@ impl CheckOutputIntegrationTest {
|
|||
|
||||
let (mut reader, writer) = pipe().unwrap();
|
||||
let testdata_dir = testdata_path();
|
||||
let mut command = deno_cmd();
|
||||
let deno_dir = new_deno_dir(); // keep this alive for the test
|
||||
let mut command = deno_cmd_with_deno_dir(&deno_dir);
|
||||
println!("deno_exe args {}", self.args);
|
||||
println!("deno_exe testdata path {:?}", &testdata_dir);
|
||||
command.args(args.iter());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::new_deno_dir;
|
||||
use super::TempDir;
|
||||
|
||||
use anyhow::Result;
|
||||
use lazy_static::lazy_static;
|
||||
|
@ -23,7 +24,6 @@ use std::process::Stdio;
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use tempfile::TempDir;
|
||||
|
||||
lazy_static! {
|
||||
static ref CONTENT_TYPE_REG: Regex =
|
||||
|
|
87
test_util/src/temp_dir.rs
Normal file
87
test_util/src/temp_dir.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use anyhow::Context;
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
static TEMP_DIR_SESSION: OnceCell<TempDirSession> = OnceCell::new();
|
||||
|
||||
struct TempDirSession {
|
||||
default_prefix: String,
|
||||
counter: AtomicU32,
|
||||
}
|
||||
|
||||
/// For creating temporary directories in tests.
|
||||
///
|
||||
/// This was done because `tempfiles::TempDir` was very slow on Windows.
|
||||
///
|
||||
/// Note: Do not use this in actual code as this does not protect against
|
||||
/// "insecure temporary file" security vulnerabilities.
|
||||
#[derive(Clone)]
|
||||
pub struct TempDir(Arc<TempDirInner>);
|
||||
|
||||
struct TempDirInner(PathBuf);
|
||||
|
||||
impl Drop for TempDirInner {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TempDir {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl TempDir {
|
||||
pub fn new() -> Self {
|
||||
Self::new_inner(&std::env::temp_dir(), None)
|
||||
}
|
||||
|
||||
pub fn new_in(path: &Path) -> Self {
|
||||
Self::new_inner(path, None)
|
||||
}
|
||||
|
||||
pub fn new_with_prefix(prefix: &str) -> Self {
|
||||
Self::new_inner(&std::env::temp_dir(), Some(prefix))
|
||||
}
|
||||
|
||||
fn new_inner(parent_dir: &Path, prefix: Option<&str>) -> Self {
|
||||
let session = TEMP_DIR_SESSION.get_or_init(|| {
|
||||
let default_prefix = format!(
|
||||
"deno-cli-test-{}",
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis()
|
||||
);
|
||||
TempDirSession {
|
||||
default_prefix,
|
||||
counter: Default::default(),
|
||||
}
|
||||
});
|
||||
Self({
|
||||
let count = session.counter.fetch_add(1, Ordering::SeqCst);
|
||||
let path = parent_dir.join(format!(
|
||||
"{}{}-{}",
|
||||
prefix.unwrap_or(""),
|
||||
session.default_prefix,
|
||||
count,
|
||||
));
|
||||
std::fs::create_dir_all(&path)
|
||||
.with_context(|| format!("Error creating temp dir: {}", path.display()))
|
||||
.unwrap();
|
||||
Arc::new(TempDirInner(path))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
let inner = &self.0;
|
||||
inner.0.as_path()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue