summaryrefslogtreecommitdiff
path: root/cli/tests/integration/run_tests.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-06-10 11:09:45 -0400
committerGitHub <noreply@github.com>2023-06-10 11:09:45 -0400
commit7f15126f23d97f20a4fb33e43136cd4d13825863 (patch)
tree85d77389969b31999680059e65954a9fa863758e /cli/tests/integration/run_tests.rs
parentf3326eebd6af2aaca1543e8cb543a7b16762bc96 (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/integration/run_tests.rs')
-rw-r--r--cli/tests/integration/run_tests.rs107
1 files changed, 24 insertions, 83 deletions
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());