diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-06-10 11:09:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-10 11:09:45 -0400 |
commit | 7f15126f23d97f20a4fb33e43136cd4d13825863 (patch) | |
tree | 85d77389969b31999680059e65954a9fa863758e /cli/tests | |
parent | f3326eebd6af2aaca1543e8cb543a7b16762bc96 (diff) |
chore(tests): test_util - Add `PathRef` (#19450)
This adds a new `PathRef` struct to test_util for making it easier to
work with paths in test code. I'm going to expand on this more in the
future.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/cache_tests.rs | 6 | ||||
-rw-r--r-- | cli/tests/integration/cert_tests.rs | 12 | ||||
-rw-r--r-- | cli/tests/integration/check_tests.rs | 10 | ||||
-rw-r--r-- | cli/tests/integration/compile_tests.rs | 52 | ||||
-rw-r--r-- | cli/tests/integration/coverage_tests.rs | 51 | ||||
-rw-r--r-- | cli/tests/integration/fmt_tests.rs | 65 | ||||
-rw-r--r-- | cli/tests/integration/install_tests.rs | 10 | ||||
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 2 | ||||
-rw-r--r-- | cli/tests/integration/npm_tests.rs | 2 | ||||
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 30 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 107 | ||||
-rw-r--r-- | cli/tests/integration/upgrade_tests.rs | 16 | ||||
-rw-r--r-- | cli/tests/integration/watcher_tests.rs | 14 |
13 files changed, 129 insertions, 248 deletions
diff --git a/cli/tests/integration/cache_tests.rs b/cli/tests/integration/cache_tests.rs index e8449ca05..3d387f15e 100644 --- a/cli/tests/integration/cache_tests.rs +++ b/cli/tests/integration/cache_tests.rs @@ -61,13 +61,11 @@ fn relative_home_dir() { use test_util as util; use test_util::TempDir; - let deno_dir = TempDir::new_in(&util::testdata_path()); - let path = deno_dir.path().strip_prefix(util::testdata_path()).unwrap(); - + let deno_dir = TempDir::new(); let mut deno_cmd = util::deno_cmd(); let output = deno_cmd .current_dir(util::testdata_path()) - .env("XDG_CACHE_HOME", path) + .env("XDG_CACHE_HOME", deno_dir.path()) .env_remove("HOME") .env_remove("DENO_DIR") .arg("cache") diff --git a/cli/tests/integration/cert_tests.rs b/cli/tests/integration/cert_tests.rs index b04f2d35e..ffd4b449d 100644 --- a/cli/tests/integration/cert_tests.rs +++ b/cli/tests/integration/cert_tests.rs @@ -82,7 +82,7 @@ fn cafile_env_fetch() { context .new_command() .args(format!("cache {module_url}")) - .env("DENO_CERT", cafile.to_string_lossy()) + .env("DENO_CERT", cafile) .run() .assert_exit_code(0) .skip_output_check(); @@ -96,11 +96,7 @@ fn cafile_fetch() { let cafile = context.testdata_path().join("tls/RootCA.pem"); context .new_command() - .args(format!( - "cache --quiet --cert {} {}", - cafile.to_string_lossy(), - module_url, - )) + .args(format!("cache --quiet --cert {} {}", cafile, module_url,)) .run() .assert_exit_code(0) .assert_matches_text(""); @@ -116,13 +112,13 @@ fn cafile_compile() { temp_dir.join("cert") }; let output = context.new_command() - .args(format!("compile --quiet --cert ./tls/RootCA.pem --allow-net --output {} ./cert/cafile_ts_fetch.ts", output_exe.to_string_lossy())) + .args(format!("compile --quiet --cert ./tls/RootCA.pem --allow-net --output {} ./cert/cafile_ts_fetch.ts", output_exe)) .run(); output.skip_output_check(); context .new_command() - .command_name(output_exe.to_string_lossy()) + .command_name(output_exe) .run() .assert_matches_text("[WILDCARD]\nHello\n"); } diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 84ed92990..41c568ad3 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -204,10 +204,10 @@ fn typecheck_core() { format!( "import \"{}\";", deno_core::resolve_path( - util::root_path() - .join("core/lib.deno_core.d.ts") - .to_str() - .unwrap(), + &util::root_path() + .join("core") + .join("lib.deno_core.d.ts") + .to_string(), &std::env::current_dir().unwrap() ) .unwrap() @@ -215,7 +215,7 @@ fn typecheck_core() { ) .unwrap(); - let args = vec!["run".to_string(), test_file.to_string_lossy().into_owned()]; + let args = vec!["run".to_string(), test_file.to_string()]; let output = context.new_command().args_vec(args).split_output().run(); println!("stdout: {}", output.stdout()); diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index c3a5048a1..022148ce4 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1,7 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::fs::File; -use std::path::Path; use std::process::Command; use test_util as util; use test_util::TempDir; @@ -30,37 +29,24 @@ fn compile_basic() { .run(); output.assert_exit_code(0); output.skip_output_check(); - let output = context - .new_command() - .command_name(exe.to_string_lossy()) - .run(); + let output = context.new_command().command_name(&exe).run(); output.assert_matches_text("Welcome to Deno!\n"); } // now ensure this works when the deno_dir is readonly let readonly_dir = dir.path().join("readonly"); - make_dir_readonly(&readonly_dir); + readonly_dir.make_dir_readonly(); let readonly_sub_dir = readonly_dir.join("sub"); let output = context .new_command() // it should fail creating this, but still work - .env("DENO_DIR", readonly_sub_dir.to_string_lossy()) - .command_name(exe.to_string_lossy()) + .env("DENO_DIR", readonly_sub_dir) + .command_name(exe) .run(); output.assert_matches_text("Welcome to Deno!\n"); } -fn make_dir_readonly(dir: &Path) { - std::fs::create_dir_all(dir).unwrap(); - eprintln!("DIR: {}", dir.display()); - if cfg!(windows) { - Command::new("attrib").arg("+r").arg(dir).output().unwrap(); - } else if cfg!(unix) { - Command::new("chmod").arg("555").arg(dir).output().unwrap(); - } -} - #[test] fn standalone_args() { let dir = TempDir::new(); @@ -272,7 +258,7 @@ fn compile_with_file_exists_error() { "is an existing file. You can use the `--output <file-path>` flag to ", "provide an alternative name.\n", ), - file_path.display(), + file_path, ); let stderr = String::from_utf8(output.stderr).unwrap(); assert_contains!(stderr, &expected_stderr); @@ -305,7 +291,7 @@ fn compile_with_directory_exists_error() { "the same name. You can use the `--output <file-path>` flag to ", "provide an alternative name." ), - exe.display() + exe ); let stderr = String::from_utf8(output.stderr).unwrap(); assert_contains!(stderr, &expected_stderr); @@ -338,7 +324,7 @@ fn compile_with_conflict_file_exists_error() { "and cannot be overwritten. Please delete the existing file or ", "use the `--output <file-path>` flag to provide an alternative name." ), - exe.display() + exe ); let stderr = String::from_utf8(output.stderr).unwrap(); assert_contains!(stderr, &expected_stderr); @@ -704,7 +690,7 @@ fn workers_not_in_module_map() { let output = context .new_command() - .command_name(exe.to_string_lossy()) + .command_name(exe) .env("NO_COLOR", "") .run(); output.assert_exit_code(1); @@ -842,10 +828,7 @@ fn compile_npm_specifiers() { output.assert_exit_code(0); output.skip_output_check(); - let output = context - .new_command() - .command_name(binary_path.to_string_lossy()) - .run(); + let output = context.new_command().command_name(&binary_path).run(); output.assert_matches_text( r#"Node esm importing node cjs =========================== @@ -901,10 +884,7 @@ testing[WILDCARD]this output.assert_exit_code(0); output.skip_output_check(); - let output = context - .new_command() - .command_name(binary_path.to_string_lossy()) - .run(); + let output = context.new_command().command_name(binary_path).run(); output.assert_matches_text("2\n"); } @@ -1042,10 +1022,7 @@ fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) { let main_specifier = if opts.input_specifier.starts_with("npm:") { opts.input_specifier.to_string() } else { - testdata_path - .join(opts.input_specifier) - .to_string_lossy() - .to_string() + testdata_path.join(opts.input_specifier).to_string() }; let mut args = vec!["compile".to_string()]; @@ -1079,7 +1056,7 @@ fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) { }; let output = context .new_command() - .command_name(binary_path.to_string_lossy()) + .command_name(binary_path) .args_vec(opts.run_args) .run(); output.assert_matches_file(opts.output_file); @@ -1144,9 +1121,6 @@ fn compile_node_modules_symlink_outside() { // run let binary_path = project_dir.join(if cfg!(windows) { "bin.exe" } else { "bin" }); - let output = context - .new_command() - .command_name(binary_path.to_string_lossy()) - .run(); + let output = context.new_command().command_name(binary_path).run(); output.assert_matches_file("compile/node_modules_symlink_outside/main.out"); } diff --git a/cli/tests/integration/coverage_tests.rs b/cli/tests/integration/coverage_tests.rs index 7443a8f37..0ac5974a6 100644 --- a/cli/tests/integration/coverage_tests.rs +++ b/cli/tests/integration/coverage_tests.rs @@ -68,7 +68,7 @@ fn error_if_invalid_cache() { .args_vec(vec![ "test".to_string(), "--quiet".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), ]) .run(); @@ -80,10 +80,7 @@ fn error_if_invalid_cache() { let output = context .new_command() - .args_vec(vec![ - "coverage".to_string(), - format!("{}/", tempdir.to_str().unwrap()), - ]) + .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) .run(); output.assert_exit_code(1); @@ -106,7 +103,7 @@ fn run_coverage_text(test_name: &str, extension: &str) { "test".to_string(), "-A".to_string(), "--quiet".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), format!("coverage/{test_name}_test.{extension}"), ]) .run(); @@ -116,10 +113,7 @@ fn run_coverage_text(test_name: &str, extension: &str) { let output = context .new_command() - .args_vec(vec![ - "coverage".to_string(), - format!("{}/", tempdir.to_str().unwrap()), - ]) + .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) .split_output() .run(); @@ -147,7 +141,7 @@ fn run_coverage_text(test_name: &str, extension: &str) { "coverage".to_string(), "--quiet".to_string(), "--lcov".to_string(), - format!("{}/", tempdir.to_str().unwrap()), + format!("{}/", tempdir), ]) .run(); @@ -178,7 +172,7 @@ fn multifile_coverage() { .args_vec(vec![ "test".to_string(), "--quiet".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), format!("coverage/multifile/"), ]) .run(); @@ -188,10 +182,7 @@ fn multifile_coverage() { let output = context .new_command() - .args_vec(vec![ - "coverage".to_string(), - format!("{}/", tempdir.to_str().unwrap()), - ]) + .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) .split_output() .run(); @@ -218,7 +209,7 @@ fn multifile_coverage() { "coverage".to_string(), "--quiet".to_string(), "--lcov".to_string(), - format!("{}/", tempdir.to_str().unwrap()), + format!("{}/", tempdir), ]) .run(); @@ -249,7 +240,7 @@ fn no_snaps_included(test_name: &str, extension: &str) { "test".to_string(), "--quiet".to_string(), "--allow-read".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), format!("coverage/no_snaps_included/{test_name}_test.{extension}"), ]) .run(); @@ -262,7 +253,7 @@ fn no_snaps_included(test_name: &str, extension: &str) { .args_vec(vec![ "coverage".to_string(), "--include=no_snaps_included.ts".to_string(), - format!("{}/", tempdir.to_str().unwrap()), + format!("{}/", tempdir), ]) .split_output() .run(); @@ -297,7 +288,7 @@ fn no_tests_included(test_name: &str, extension: &str) { "test".to_string(), "--quiet".to_string(), "--allow-read".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), format!("coverage/no_tests_included/{test_name}.test.{extension}"), ]) .run(); @@ -309,11 +300,8 @@ fn no_tests_included(test_name: &str, extension: &str) { .new_command() .args_vec(vec![ "coverage".to_string(), - format!( - "--exclude={}", - util::std_path().canonicalize().unwrap().to_string_lossy() - ), - format!("{}/", tempdir.to_str().unwrap()), + format!("--exclude={}", util::std_path().canonicalize()), + format!("{}/", tempdir), ]) .split_output() .run(); @@ -349,7 +337,7 @@ fn no_npm_cache_coverage() { "test".to_string(), "--quiet".to_string(), "--allow-read".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), format!("coverage/no_npm_coverage/no_npm_coverage_test.ts"), ]) .run(); @@ -359,10 +347,7 @@ fn no_npm_cache_coverage() { let output = context .new_command() - .args_vec(vec![ - "coverage".to_string(), - format!("{}/", tempdir.to_str().unwrap()), - ]) + .args_vec(vec!["coverage".to_string(), format!("{}/", tempdir)]) .split_output() .run(); @@ -396,7 +381,7 @@ fn no_transpiled_lines() { .args_vec(vec![ "test".to_string(), "--quiet".to_string(), - format!("--coverage={}", tempdir.to_str().unwrap()), + format!("--coverage={}", tempdir), "coverage/no_transpiled_lines/".to_string(), ]) .run(); @@ -409,7 +394,7 @@ fn no_transpiled_lines() { .args_vec(vec![ "coverage".to_string(), "--include=no_transpiled_lines/index.ts".to_string(), - format!("{}/", tempdir.to_str().unwrap()), + format!("{}/", tempdir), ]) .run(); @@ -434,7 +419,7 @@ fn no_transpiled_lines() { "coverage".to_string(), "--lcov".to_string(), "--include=no_transpiled_lines/index.ts".to_string(), - format!("{}/", tempdir.to_str().unwrap()), + format!("{}/", tempdir), ]) .run(); diff --git a/cli/tests/integration/fmt_tests.rs b/cli/tests/integration/fmt_tests.rs index e674f4a52..ef0ad3f3e 100644 --- a/cli/tests/integration/fmt_tests.rs +++ b/cli/tests/integration/fmt_tests.rs @@ -3,6 +3,7 @@ use test_util as util; use test_util::TempDir; use util::assert_contains; +use util::PathRef; use util::TestContext; use util::TestContextBuilder; @@ -15,34 +16,30 @@ fn fmt_test() { let badly_formatted_original_js = testdata_fmt_dir.join("badly_formatted.mjs"); let badly_formatted_js = t.path().join("badly_formatted.js"); - let badly_formatted_js_str = badly_formatted_js.to_str().unwrap(); - std::fs::copy(badly_formatted_original_js, &badly_formatted_js).unwrap(); + badly_formatted_original_js.copy(&badly_formatted_js); let fixed_md = testdata_fmt_dir.join("badly_formatted_fixed.md"); let badly_formatted_original_md = testdata_fmt_dir.join("badly_formatted.md"); let badly_formatted_md = t.path().join("badly_formatted.md"); - let badly_formatted_md_str = badly_formatted_md.to_str().unwrap(); - std::fs::copy(badly_formatted_original_md, &badly_formatted_md).unwrap(); + badly_formatted_original_md.copy(&badly_formatted_md); let fixed_json = testdata_fmt_dir.join("badly_formatted_fixed.json"); let badly_formatted_original_json = testdata_fmt_dir.join("badly_formatted.json"); let badly_formatted_json = t.path().join("badly_formatted.json"); - let badly_formatted_json_str = badly_formatted_json.to_str().unwrap(); - std::fs::copy(badly_formatted_original_json, &badly_formatted_json).unwrap(); + badly_formatted_original_json.copy(&badly_formatted_json); // First, check formatting by ignoring the badly formatted file. - let s = testdata_fmt_dir.as_os_str().to_str().unwrap(); let output = context .new_command() - .cwd(s) + .cwd(&testdata_fmt_dir) .args_vec(vec![ "fmt".to_string(), format!( - "--ignore={badly_formatted_js_str},{badly_formatted_md_str},{badly_formatted_json_str}", + "--ignore={badly_formatted_js},{badly_formatted_md},{badly_formatted_json}", ), format!( - "--check {badly_formatted_js_str} {badly_formatted_md_str} {badly_formatted_json_str}", + "--check {badly_formatted_js} {badly_formatted_md} {badly_formatted_json}", ), ]) .run(); @@ -54,13 +51,13 @@ fn fmt_test() { // Check without ignore. let output = context .new_command() - .cwd(s) + .cwd(&testdata_fmt_dir) .args_vec(vec![ "fmt".to_string(), "--check".to_string(), - badly_formatted_js_str.to_string(), - badly_formatted_md_str.to_string(), - badly_formatted_json_str.to_string(), + badly_formatted_js.to_string(), + badly_formatted_md.to_string(), + badly_formatted_json.to_string(), ]) .run(); @@ -70,24 +67,24 @@ fn fmt_test() { // Format the source file. let output = context .new_command() - .cwd(s) + .cwd(&testdata_fmt_dir) .args_vec(vec![ "fmt".to_string(), - badly_formatted_js_str.to_string(), - badly_formatted_md_str.to_string(), - badly_formatted_json_str.to_string(), + badly_formatted_js.to_string(), + badly_formatted_md.to_string(), + badly_formatted_json.to_string(), ]) .run(); output.assert_exit_code(0); output.skip_output_check(); - let expected_js = std::fs::read_to_string(fixed_js).unwrap(); - let expected_md = std::fs::read_to_string(fixed_md).unwrap(); - let expected_json = std::fs::read_to_string(fixed_json).unwrap(); - let actual_js = std::fs::read_to_string(badly_formatted_js).unwrap(); - let actual_md = std::fs::read_to_string(badly_formatted_md).unwrap(); - let actual_json = std::fs::read_to_string(badly_formatted_json).unwrap(); + let expected_js = fixed_js.read_to_string(); + let expected_md = fixed_md.read_to_string(); + let expected_json = fixed_json.read_to_string(); + let actual_js = badly_formatted_js.read_to_string(); + let actual_md = badly_formatted_md.read_to_string(); + let actual_json = badly_formatted_json.read_to_string(); assert_eq!(expected_js, actual_js); assert_eq!(expected_md, actual_md); assert_eq!(expected_json, actual_json); @@ -130,25 +127,21 @@ fn fmt_ignore_unexplicit_files() { #[test] fn fmt_auto_ignore_git_and_node_modules() { - use std::fs::create_dir_all; - use std::fs::File; - use std::io::Write; - use std::path::PathBuf; - fn create_bad_json(t: PathBuf) { + fn create_bad_json(t: PathRef) { let bad_json_path = t.join("bad.json"); - let mut bad_json_file = File::create(bad_json_path).unwrap(); - writeln!(bad_json_file, "bad json").unwrap(); + bad_json_path.write("bad json\n"); } + 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"); let nest_node_modules = t.join("nest").join("node_modules"); let node_modules_dir = t.join("node_modules"); - create_dir_all(&nest_git).unwrap(); - create_dir_all(&git_dir).unwrap(); - create_dir_all(&nest_node_modules).unwrap(); - create_dir_all(&node_modules_dir).unwrap(); + nest_git.create_dir_all(); + git_dir.create_dir_all(); + nest_node_modules.create_dir_all(); + node_modules_dir.create_dir_all(); create_bad_json(nest_git); create_bad_json(git_dir); create_bad_json(nest_node_modules); @@ -157,7 +150,7 @@ fn fmt_auto_ignore_git_and_node_modules() { let context = TestContext::default(); let output = context .new_command() - .cwd(t.as_os_str().to_str().unwrap()) + .cwd(t) .env("NO_COLOR", "1") .args("fmt") .run(); diff --git a/cli/tests/integration/install_tests.rs b/cli/tests/integration/install_tests.rs index af4edd2ee..0756d460c 100644 --- a/cli/tests/integration/install_tests.rs +++ b/cli/tests/integration/install_tests.rs @@ -11,7 +11,7 @@ use test_util::TempDir; fn install_basic() { let _guard = util::http_server(); let temp_dir = TempDir::new(); - let temp_dir_str = temp_dir.path().to_string_lossy().to_string(); + let temp_dir_str = temp_dir.path().to_string(); // ensure a lockfile doesn't get created or updated locally temp_dir.write("deno.json", "{}"); @@ -44,7 +44,7 @@ fn install_basic() { file_path = file_path.with_extension("cmd"); } - let content = fs::read_to_string(&file_path).unwrap(); + let content = file_path.read_to_string(); // ensure there's a trailing newline so the shell script can be // more versatile. assert_eq!(content.chars().last().unwrap(), '\n'); @@ -87,7 +87,7 @@ fn install_basic() { fn install_custom_dir_env_var() { let _guard = util::http_server(); let temp_dir = TempDir::new(); - let temp_dir_str = temp_dir.path().to_string_lossy().to_string(); + let temp_dir_str = temp_dir.path().to_string(); let status = util::deno_cmd() .current_dir(util::root_path()) // different cwd @@ -205,7 +205,7 @@ fn installer_test_remote_module_run() { fn check_local_by_default() { let _guard = util::http_server(); let temp_dir = TempDir::new(); - let temp_dir_str = temp_dir.path().to_string_lossy().to_string(); + let temp_dir_str = temp_dir.path().to_string(); let status = util::deno_cmd() .current_dir(temp_dir.path()) @@ -225,7 +225,7 @@ fn check_local_by_default() { fn check_local_by_default2() { let _guard = util::http_server(); let temp_dir = TempDir::new(); - let temp_dir_str = temp_dir.path().to_string_lossy().to_string(); + let temp_dir_str = temp_dir.path().to_string(); let status = util::deno_cmd() .current_dir(temp_dir.path()) diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index fa8cb6a3c..bd5bc409a 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -7670,7 +7670,7 @@ fn lsp_node_modules_dir() { .as_str() .unwrap(); // canonicalize for mac - let path = temp_dir.path().join("node_modules").canonicalize().unwrap(); + let path = temp_dir.path().join("node_modules").canonicalize(); assert_starts_with!( uri, ModuleSpecifier::from_file_path(&path).unwrap().as_str() diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 3a18c13dc..c38e4f75f 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -880,7 +880,7 @@ fn ensure_registry_files_local() { if file_text.contains("https://registry.npmjs.org/") { panic!( "file {} contained a reference to the npm registry", - registry_json_path.display(), + registry_json_path ); } } diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 77a534d2e..c25a151a1 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -316,7 +316,15 @@ fn repl_cwd() { .args_vec(["repl", "-A"]) .with_pty(|mut console| { console.write_line("Deno.cwd()"); - console.expect(temp_dir.path().file_name().unwrap().to_str().unwrap()); + console.expect( + temp_dir + .path() + .as_path() + .file_name() + .unwrap() + .to_str() + .unwrap(), + ); }); } @@ -535,10 +543,7 @@ fn missing_deno_dir() { "repl", Some(vec!["1"]), Some(vec![ - ( - "DENO_DIR".to_owned(), - deno_dir_path.to_str().unwrap().to_owned(), - ), + ("DENO_DIR".to_owned(), deno_dir_path.to_string()), ("NO_COLOR".to_owned(), "1".to_owned()), ]), false, @@ -558,10 +563,7 @@ fn custom_history_path() { "repl", Some(vec!["1"]), Some(vec![ - ( - "DENO_REPL_HISTORY".to_owned(), - history_path.to_str().unwrap().to_owned(), - ), + ("DENO_REPL_HISTORY".to_owned(), history_path.to_string()), ("NO_COLOR".to_owned(), "1".to_owned()), ]), false, @@ -580,10 +582,7 @@ fn disable_history_file() { "repl", Some(vec!["1"]), Some(vec![ - ( - "DENO_DIR".to_owned(), - deno_dir.path().to_str().unwrap().to_owned(), - ), + ("DENO_DIR".to_owned(), deno_dir.path().to_string()), ("DENO_REPL_HISTORY".to_owned(), "".to_owned()), ("NO_COLOR".to_owned(), "1".to_owned()), ]), @@ -877,10 +876,7 @@ fn npm_packages() { let mut env_vars = util::env_vars_for_npm_tests(); env_vars.push(("NO_COLOR".to_owned(), "1".to_owned())); let temp_dir = TempDir::new(); - env_vars.push(( - "DENO_DIR".to_string(), - temp_dir.path().to_string_lossy().to_string(), - )); + env_vars.push(("DENO_DIR".to_string(), temp_dir.path().to_string())); { let (out, err) = util::run_and_collect_output_with_args( diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 3fa2f9896..476849b2a 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -14,6 +14,7 @@ use trust_dns_client::serialize::txt::Parser; use util::assert_contains; use util::assert_not_contains; use util::env_vars_for_npm_tests_no_sync_download; +use util::PathRef; use util::TestContext; use util::TestContextBuilder; @@ -520,8 +521,8 @@ fn _083_legacy_external_source_map() { .unwrap(); // Write a faulty old external source map. let faulty_map_path = deno_dir.path().join("gen/http/localhost_PORT4545/9576bd5febd0587c5c4d88d57cb3ac8ebf2600c529142abe3baa9a751d20c334.js.map"); - std::fs::create_dir_all(faulty_map_path.parent().unwrap()).unwrap(); - std::fs::write(faulty_map_path, "{\"version\":3,\"file\":\"\",\"sourceRoot\":\"\",\"sources\":[\"http://localhost:4545/083_legacy_external_source_map.ts\"],\"names\":[],\"mappings\":\";AAAA,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC\"}").unwrap(); + faulty_map_path.parent().create_dir_all(); + faulty_map_path.write(r#"{\"version\":3,\"file\":\"\",\"sourceRoot\":\"\",\"sources\":[\"http://localhost:4545/083_legacy_external_source_map.ts\"],\"names\":[],\"mappings\":\";AAAA,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC\"}"#); let output = Command::new(util::deno_exe_path()) .env("DENO_DIR", deno_dir.path()) .current_dir(util::testdata_path()) @@ -1925,8 +1926,8 @@ fn exec_path() { .unwrap(); assert!(output.status.success()); let stdout_str = std::str::from_utf8(&output.stdout).unwrap().trim(); - let actual = std::fs::canonicalize(std::path::Path::new(stdout_str)).unwrap(); - let expected = std::fs::canonicalize(util::deno_exe_path()).unwrap(); + let actual = PathRef::new(std::path::Path::new(stdout_str)).canonicalize(); + let expected = util::deno_exe_path().canonicalize(); assert_eq!(expected, actual); } @@ -1991,7 +1992,7 @@ enum WinProcConstraints { #[cfg(windows)] fn run_deno_script_constrained( - script_path: std::path::PathBuf, + script_path: test_util::PathRef, constraints: WinProcConstraints, ) -> Result<(), i64> { let file_path = "assets/DenoWinRunner.ps1"; @@ -2000,13 +2001,8 @@ fn run_deno_script_constrained( WinProcConstraints::NoStdOut => "2", WinProcConstraints::NoStdErr => "4", }; - let deno_exe_path = util::deno_exe_path() - .into_os_string() - .into_string() - .unwrap(); - - let deno_script_path = script_path.into_os_string().into_string().unwrap(); - + let deno_exe_path = util::deno_exe_path().to_string(); + let deno_script_path = script_path.to_string(); let args = vec![&deno_exe_path[..], &deno_script_path[..], constraints]; util::run_powershell_script_file(file_path, args) } @@ -2199,9 +2195,6 @@ mod permissions { "--allow-{0}={1}", permission, util::testdata_path() - .into_os_string() - .into_string() - .unwrap() )) .arg("run/complex_permissions_test.ts") .arg(permission) @@ -2223,15 +2216,8 @@ mod permissions { &format!( "run --allow-{0}={1} run/complex_permissions_test.ts {0} {2}", permission, - util::testdata_path() - .into_os_string() - .into_string() - .unwrap(), - util::root_path() - .join("Cargo.toml") - .into_os_string() - .into_string() - .unwrap(), + util::testdata_path(), + util::root_path().join("Cargo.toml"), ), None, None, @@ -2251,10 +2237,7 @@ mod permissions { .arg(format!( "--allow-{0}={1}", permission, - util::testdata_path() - .into_os_string() - .into_string() - .unwrap() + util::testdata_path(), )) .arg("run/complex_permissions_test.ts") .arg(permission) @@ -2270,15 +2253,8 @@ mod permissions { #[test] fn rw_outside_test_and_js_dir() { const PERMISSION_VARIANTS: [&str; 2] = ["read", "write"]; - let test_dir = util::testdata_path() - .into_os_string() - .into_string() - .unwrap(); - let js_dir = util::root_path() - .join("js") - .into_os_string() - .into_string() - .unwrap(); + let test_dir = util::testdata_path(); + let js_dir = util::root_path().join("js"); for permission in &PERMISSION_VARIANTS { let (_, err) = util::run_and_collect_output( false, @@ -2287,11 +2263,7 @@ mod permissions { permission, test_dir, js_dir, - util::root_path() - .join("Cargo.toml") - .into_os_string() - .into_string() - .unwrap(), + util::root_path().join("Cargo.toml"), ), None, None, @@ -2304,15 +2276,8 @@ mod permissions { #[test] fn rw_inside_test_and_js_dir() { const PERMISSION_VARIANTS: [&str; 2] = ["read", "write"]; - let test_dir = util::testdata_path() - .into_os_string() - .into_string() - .unwrap(); - let js_dir = util::root_path() - .join("js") - .into_os_string() - .into_string() - .unwrap(); + let test_dir = util::testdata_path(); + let js_dir = util::root_path().join("js"); for permission in &PERMISSION_VARIANTS { let status = util::deno_cmd() .current_dir(&util::testdata_path()) @@ -3551,35 +3516,23 @@ fn cache_test() { fn cache_invalidation_test() { let deno_dir = TempDir::new(); let fixture_path = deno_dir.path().join("fixture.ts"); - { - let mut file = std::fs::File::create(fixture_path.clone()) - .expect("could not create fixture"); - file - .write_all(b"console.log(\"42\");") - .expect("could not write fixture"); - } + fixture_path.write("console.log(\"42\");"); let output = Command::new(util::deno_exe_path()) .env("DENO_DIR", deno_dir.path()) .current_dir(util::testdata_path()) .arg("run") - .arg(fixture_path.to_str().unwrap()) + .arg(&fixture_path) .output() .expect("Failed to spawn script"); assert!(output.status.success()); let actual = std::str::from_utf8(&output.stdout).unwrap(); assert_eq!(actual, "42\n"); - { - let mut file = std::fs::File::create(fixture_path.clone()) - .expect("could not create fixture"); - file - .write_all(b"console.log(\"43\");") - .expect("could not write fixture"); - } + fixture_path.write("console.log(\"43\");"); let output = Command::new(util::deno_exe_path()) .env("DENO_DIR", deno_dir.path()) .current_dir(util::testdata_path()) .arg("run") - .arg(fixture_path.to_str().unwrap()) + .arg(fixture_path) .output() .expect("Failed to spawn script"); assert!(output.status.success()); @@ -3591,37 +3544,25 @@ fn cache_invalidation_test() { fn cache_invalidation_test_no_check() { let deno_dir = TempDir::new(); let fixture_path = deno_dir.path().join("fixture.ts"); - { - let mut file = std::fs::File::create(fixture_path.clone()) - .expect("could not create fixture"); - file - .write_all(b"console.log(\"42\");") - .expect("could not write fixture"); - } + fixture_path.write("console.log(\"42\");"); let output = Command::new(util::deno_exe_path()) .env("DENO_DIR", deno_dir.path()) .current_dir(util::testdata_path()) .arg("run") .arg("--no-check") - .arg(fixture_path.to_str().unwrap()) + .arg(&fixture_path) .output() .expect("Failed to spawn script"); assert!(output.status.success()); let actual = std::str::from_utf8(&output.stdout).unwrap(); assert_eq!(actual, "42\n"); - { - let mut file = std::fs::File::create(fixture_path.clone()) - .expect("could not create fixture"); - file - .write_all(b"console.log(\"43\");") - .expect("could not write fixture"); - } + fixture_path.write("console.log(\"43\");"); let output = Command::new(util::deno_exe_path()) .env("DENO_DIR", deno_dir.path()) .current_dir(util::testdata_path()) .arg("run") .arg("--no-check") - .arg(fixture_path.to_str().unwrap()) + .arg(fixture_path) .output() .expect("Failed to spawn script"); assert!(output.status.success()); diff --git a/cli/tests/integration/upgrade_tests.rs b/cli/tests/integration/upgrade_tests.rs index f4eaa03c9..6eed9e7a1 100644 --- a/cli/tests/integration/upgrade_tests.rs +++ b/cli/tests/integration/upgrade_tests.rs @@ -12,7 +12,7 @@ use test_util::TempDir; fn upgrade_in_tmpdir() { let temp_dir = TempDir::new(); let exe_path = temp_dir.path().join("deno"); - let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let _mtime1 = std::fs::metadata(&exe_path).unwrap().modified().unwrap(); let status = Command::new(&exe_path) @@ -34,7 +34,7 @@ fn upgrade_in_tmpdir() { fn upgrade_with_space_in_path() { 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(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let status = Command::new(&exe_path) .arg("upgrade") @@ -54,7 +54,7 @@ fn upgrade_with_space_in_path() { fn upgrade_with_version_in_tmpdir() { let temp_dir = TempDir::new(); let exe_path = temp_dir.path().join("deno"); - let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let _mtime1 = std::fs::metadata(&exe_path).unwrap().modified().unwrap(); let status = Command::new(&exe_path) @@ -83,7 +83,7 @@ fn upgrade_with_version_in_tmpdir() { fn upgrade_with_canary_in_tmpdir() { let temp_dir = TempDir::new(); let exe_path = temp_dir.path().join("deno"); - let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let _mtime1 = std::fs::metadata(&exe_path).unwrap().modified().unwrap(); let status = Command::new(&exe_path) @@ -113,7 +113,7 @@ fn upgrade_with_out_in_tmpdir() { 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(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let mtime1 = std::fs::metadata(&exe_path).unwrap().modified().unwrap(); let status = Command::new(&exe_path) @@ -121,7 +121,7 @@ fn upgrade_with_out_in_tmpdir() { .arg("--version") .arg("1.11.5") .arg("--output") - .arg(new_exe_path.to_str().unwrap()) + .arg(&new_exe_path) .spawn() .unwrap() .wait() @@ -149,7 +149,7 @@ fn upgrade_with_out_in_tmpdir() { fn upgrade_invalid_stable_version() { let temp_dir = TempDir::new(); let exe_path = temp_dir.path().join("deno"); - let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let output = Command::new(&exe_path) .arg("upgrade") @@ -174,7 +174,7 @@ fn upgrade_invalid_stable_version() { fn upgrade_invalid_canary_version() { let temp_dir = TempDir::new(); let exe_path = temp_dir.path().join("deno"); - let _ = std::fs::copy(util::deno_exe_path(), &exe_path).unwrap(); + util::deno_exe_path().copy(&exe_path); assert!(exe_path.exists()); let output = Command::new(&exe_path) .arg("upgrade") diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs index 2d41a74ed..ab3005f73 100644 --- a/cli/tests/integration/watcher_tests.rs +++ b/cli/tests/integration/watcher_tests.rs @@ -743,11 +743,7 @@ async fn run_watch_external_watch_files() { write(&external_file_to_watch, "Hello world").unwrap(); let mut watch_arg = "--watch=".to_owned(); - let external_file_to_watch_str = external_file_to_watch - .clone() - .into_os_string() - .into_string() - .unwrap(); + let external_file_to_watch_str = external_file_to_watch.to_string(); watch_arg.push_str(&external_file_to_watch_str); let mut child = util::deno_cmd() @@ -893,13 +889,15 @@ async fn run_watch_with_import_map_and_relative_paths() { let absolute_path = directory.path().join(filename); write(&absolute_path, filecontent).unwrap(); let relative_path = absolute_path - .strip_prefix(util::testdata_path()) + .as_path() + .strip_prefix(directory.path()) .unwrap() .to_owned(); assert!(relative_path.is_relative()); relative_path } - let temp_directory = TempDir::new_in(&util::testdata_path()); + + let temp_directory = TempDir::new(); let file_to_watch = create_relative_tmp_file( &temp_directory, "file_to_watch.js", @@ -912,7 +910,7 @@ async fn run_watch_with_import_map_and_relative_paths() { ); let mut child = util::deno_cmd() - .current_dir(util::testdata_path()) + .current_dir(temp_directory.path()) .arg("run") .arg("--unstable") .arg("--watch") |