diff options
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r-- | cli/tests/integration_tests.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index eeffb0097..cb6dfad6d 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -4650,3 +4650,101 @@ fn standalone_no_module_load() { assert!(util::strip_ansi_codes(&stderr_str) .contains("Self-contained binaries don't support module loading")); } + +#[test] +fn compile_with_directory_exists_error() { + let dir = TempDir::new().expect("tempdir fail"); + let exe = if cfg!(windows) { + dir.path().join("args.exe") + } else { + dir.path().join("args") + }; + std::fs::create_dir(&exe).expect("cannot create directory"); + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--unstable") + .arg("./cli/tests/028_args.ts") + .arg("--output") + .arg(&exe) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(!output.status.success()); + let expected_stderr = + format!("Could not compile: {:?} is a directory.\n", &exe); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert!(stderr.contains(&expected_stderr)); +} + +#[test] +fn compile_with_conflict_file_exists_error() { + let dir = TempDir::new().expect("tempdir fail"); + 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"); + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--unstable") + .arg("./cli/tests/028_args.ts") + .arg("--output") + .arg(&exe) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(!output.status.success()); + let expected_stderr = + format!("Could not compile: cannot overwrite {:?}.\n", &exe); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert!(stderr.contains(&expected_stderr)); + assert!(std::fs::read(&exe) + .expect("cannot read file") + .eq(b"SHOULD NOT BE OVERWRITTEN")); +} + +#[test] +fn compile_and_overwrite_file() { + let dir = TempDir::new().expect("tempdir fail"); + let exe = if cfg!(windows) { + dir.path().join("args.exe") + } else { + dir.path().join("args") + }; + let output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--unstable") + .arg("./cli/tests/028_args.ts") + .arg("--output") + .arg(&exe) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + assert!(&exe.exists()); + + let recompile_output = util::deno_cmd() + .current_dir(util::root_path()) + .arg("compile") + .arg("--unstable") + .arg("./cli/tests/028_args.ts") + .arg("--output") + .arg(&exe) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(recompile_output.status.success()); +} |