diff options
author | Yosi Pramajaya <yosi.pramajaya@gmail.com> | 2020-12-13 02:41:43 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-12 20:41:43 +0100 |
commit | 84ef9bd21fb48fb6b5fbc8dafc3de9f361bade3b (patch) | |
tree | 45c5f2c46425f72f07e92ee1f212ac522732279e /cli/tests/integration_tests.rs | |
parent | 623bc22ad0aa7446bc383dc93d7c8da3c4c2fe22 (diff) |
fix(cli/compile): error when the output path already exists (#8681)
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()); +} |