summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/compile_tests.rs40
-rw-r--r--cli/tests/integration/install_tests.rs81
2 files changed, 100 insertions, 21 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs
index a6cceb8a7..40bb250a0 100644
--- a/cli/tests/integration/compile_tests.rs
+++ b/cli/tests/integration/compile_tests.rs
@@ -7,7 +7,7 @@ use test_util as util;
#[test]
fn compile() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("welcome.exe")
} else {
@@ -36,12 +36,11 @@ fn compile() {
assert_eq!(output.stdout, "Welcome to Deno!\n".as_bytes());
}
-#[ignore]
#[test]
#[cfg(windows)]
// https://github.com/denoland/deno/issues/9667
fn compile_windows_ext() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = dir.path().join("welcome_9667");
let output = util::deno_cmd()
.current_dir(util::root_path())
@@ -65,7 +64,7 @@ fn compile_windows_ext() {
#[test]
fn standalone_args() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("args.exe")
} else {
@@ -101,7 +100,7 @@ fn standalone_args() {
#[test]
fn standalone_error() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("error.exe")
} else {
@@ -143,7 +142,7 @@ fn standalone_error() {
#[test]
fn standalone_error_module_with_imports() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("error.exe")
} else {
@@ -183,7 +182,7 @@ fn standalone_error_module_with_imports() {
#[test]
fn standalone_load_datauri() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("load_datauri.exe")
} else {
@@ -215,7 +214,7 @@ fn standalone_load_datauri() {
#[test]
fn standalone_compiler_ops() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("standalone_compiler_ops.exe")
} else {
@@ -247,7 +246,7 @@ fn standalone_compiler_ops() {
#[test]
fn compile_with_directory_output_flag() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let output_path = if cfg!(windows) {
dir.path().join(r"args\random\")
} else {
@@ -285,14 +284,14 @@ fn compile_with_directory_output_flag() {
#[test]
fn compile_with_file_exists_error() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let output_path = if cfg!(windows) {
dir.path().join(r"args\")
} else {
dir.path().join("args/")
};
let file_path = dir.path().join("args");
- File::create(&file_path).expect("cannot create file");
+ File::create(&file_path).unwrap();
let output = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("compile")
@@ -320,13 +319,13 @@ fn compile_with_file_exists_error() {
#[test]
fn compile_with_directory_exists_error() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("args.exe")
} else {
dir.path().join("args")
};
- std::fs::create_dir(&exe).expect("cannot create directory");
+ std::fs::create_dir(&exe).unwrap();
let output = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("compile")
@@ -354,14 +353,13 @@ fn compile_with_directory_exists_error() {
#[test]
fn compile_with_conflict_file_exists_error() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("args.exe")
} else {
dir.path().join("args")
};
- std::fs::write(&exe, b"SHOULD NOT BE OVERWRITTEN")
- .expect("cannot create file");
+ std::fs::write(&exe, b"SHOULD NOT BE OVERWRITTEN").unwrap();
let output = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("compile")
@@ -387,13 +385,13 @@ fn compile_with_conflict_file_exists_error() {
dbg!(&stderr);
assert!(stderr.contains(&expected_stderr));
assert!(std::fs::read(&exe)
- .expect("cannot read file")
+ .unwrap()
.eq(b"SHOULD NOT BE OVERWRITTEN"));
}
#[test]
fn compile_and_overwrite_file() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("args.exe")
} else {
@@ -431,7 +429,7 @@ fn compile_and_overwrite_file() {
#[test]
fn standalone_runtime_flags() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("flags.exe")
} else {
@@ -470,7 +468,7 @@ fn standalone_runtime_flags() {
#[test]
fn standalone_import_map() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("import_map.exe")
} else {
@@ -505,7 +503,7 @@ fn standalone_import_map() {
#[test]
// https://github.com/denoland/deno/issues/12670
fn skip_rebundle() {
- let dir = TempDir::new().expect("tempdir fail");
+ let dir = TempDir::new().unwrap();
let exe = if cfg!(windows) {
dir.path().join("hello_world.exe")
} else {
diff --git a/cli/tests/integration/install_tests.rs b/cli/tests/integration/install_tests.rs
index 68f519686..18f0cf9c0 100644
--- a/cli/tests/integration/install_tests.rs
+++ b/cli/tests/integration/install_tests.rs
@@ -1,10 +1,91 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+use std::fs;
use std::process::Command;
use tempfile::TempDir;
use test_util as util;
#[test]
+fn install_basic() {
+ let _guard = util::http_server();
+ let temp_dir = TempDir::new().unwrap();
+ let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
+
+ let status = util::deno_cmd()
+ .current_dir(temp_dir.path())
+ .arg("install")
+ .arg("--name")
+ .arg("echo_test")
+ .arg("http://localhost:4545/echo.ts")
+ .envs([
+ ("HOME", temp_dir_str.as_str()),
+ ("USERPROFILE", temp_dir_str.as_str()),
+ ("DENO_INSTALL_ROOT", ""),
+ ])
+ .spawn()
+ .unwrap()
+ .wait()
+ .unwrap();
+ assert!(status.success());
+
+ let mut file_path = temp_dir.path().join(".deno/bin/echo_test");
+ assert!(file_path.exists());
+
+ if cfg!(windows) {
+ file_path = file_path.with_extension("cmd");
+ }
+
+ let content = fs::read_to_string(file_path).unwrap();
+ // ensure there's a trailing newline so the shell script can be
+ // more versatile.
+ assert_eq!(content.chars().last().unwrap(), '\n');
+
+ if cfg!(windows) {
+ assert!(content.contains(r#""run" "http://localhost:4545/echo.ts""#));
+ } else {
+ assert!(content.contains(r#"run 'http://localhost:4545/echo.ts'"#));
+ }
+}
+
+#[test]
+fn install_custom_dir_env_var() {
+ let _guard = util::http_server();
+ let temp_dir = TempDir::new().unwrap();
+ let temp_dir_str = temp_dir.path().to_string_lossy().to_string();
+
+ let status = util::deno_cmd()
+ .current_dir(util::root_path()) // different cwd
+ .arg("install")
+ .arg("--name")
+ .arg("echo_test")
+ .arg("http://localhost:4545/echo.ts")
+ .envs([
+ ("HOME", temp_dir_str.as_str()),
+ ("USERPROFILE", temp_dir_str.as_str()),
+ ("DENO_INSTALL_ROOT", temp_dir_str.as_str()),
+ ])
+ .spawn()
+ .unwrap()
+ .wait()
+ .unwrap();
+ assert!(status.success());
+
+ let mut file_path = temp_dir.path().join("bin/echo_test");
+ assert!(file_path.exists());
+
+ if cfg!(windows) {
+ file_path = file_path.with_extension("cmd");
+ }
+
+ let content = fs::read_to_string(file_path).unwrap();
+ if cfg!(windows) {
+ assert!(content.contains(r#""run" "http://localhost:4545/echo.ts""#));
+ } else {
+ assert!(content.contains(r#"run 'http://localhost:4545/echo.ts'"#));
+ }
+}
+
+#[test]
fn installer_test_local_module_run() {
let temp_dir = TempDir::new().expect("tempdir fail");
let bin_dir = temp_dir.path().join("bin");