diff options
author | Rabin Gaire <rabingaire20@gmail.com> | 2022-01-11 10:09:39 +0545 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-10 23:24:39 -0500 |
commit | 605b8db8f61fc4c0c71d11cde873af18d87c49bf (patch) | |
tree | 63ecb48a02e2549aa8db941ecdd95147843a7b36 /cli/tests/integration/compile_tests.rs | |
parent | b66afa2518042cda239ef07f221722781ca660f6 (diff) |
cli(compile): fix output flag behaviour on compile command (#13299)
Diffstat (limited to 'cli/tests/integration/compile_tests.rs')
-rw-r--r-- | cli/tests/integration/compile_tests.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index d2abd04d5..bff03013f 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use std::fs::File; use std::process::Command; use tempfile::TempDir; use test_util as util; @@ -234,6 +235,73 @@ fn standalone_compiler_ops() { } #[test] +fn compile_with_directory_output_flag() { + let dir = TempDir::new().expect("tempdir fail"); + let output_path = if cfg!(windows) { + dir.path().join(r"args\random\") + } else { + dir.path().join("args/random/") + }; + let output = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("compile") + .arg("--unstable") + .arg("--output") + .arg(&output_path) + .arg("./standalone_compiler_ops.ts") + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let exe = if cfg!(windows) { + output_path.join("standalone_compiler_ops.exe") + } else { + output_path.join("standalone_compiler_ops") + }; + assert!(&exe.exists()); + let output = Command::new(exe) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + assert_eq!(output.stdout, b"Hello, Compiler API!\n"); +} + +#[test] +fn compile_with_file_exists_error() { + let dir = TempDir::new().expect("tempdir fail"); + 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"); + let output = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("compile") + .arg("--unstable") + .arg("--output") + .arg(&output_path) + .arg("./028_args.ts") + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(!output.status.success()); + let expected_stderr = + format!("Could not compile: {:?} is a file.\n", &file_path); + let stderr = String::from_utf8(output.stderr).unwrap(); + assert!(stderr.contains(&expected_stderr)); +} + +#[test] fn compile_with_directory_exists_error() { let dir = TempDir::new().expect("tempdir fail"); let exe = if cfg!(windows) { |