From 5ee2ce1b1c37f08b11a25e6c0d190f3c397c7ec2 Mon Sep 17 00:00:00 2001 From: Jaap Aarts Date: Thu, 11 Jun 2020 16:58:09 +0200 Subject: feat: allow reading the entry file from stdin (#6130) --- cli/tests/integration_tests.rs | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'cli/tests/integration_tests.rs') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 9c59e2a74..5ecd6d35b 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -8,7 +8,7 @@ extern crate pty; extern crate tempfile; use futures::prelude::*; -use std::io::BufRead; +use std::io::{BufRead, Write}; use std::process::Command; use tempfile::TempDir; @@ -70,6 +70,50 @@ fn eval_p() { assert_eq!("3", stdout_str); } +#[test] + +fn run_from_stdin() { + let mut deno = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg("-") + .stdout(std::process::Stdio::piped()) + .stdin(std::process::Stdio::piped()) + .spawn() + .unwrap(); + deno + .stdin + .as_mut() + .unwrap() + .write_all(b"console.log(\"Hello World\");") + .unwrap(); + let output = deno.wait_with_output().unwrap(); + assert!(output.status.success()); + + let deno_out = std::str::from_utf8(&output.stdout).unwrap().trim(); + assert_eq!("Hello World", deno_out); + + let mut deno = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg("-") + .stdout(std::process::Stdio::piped()) + .stdin(std::process::Stdio::piped()) + .spawn() + .unwrap(); + deno + .stdin + .as_mut() + .unwrap() + .write_all(b"console.log(\"Bye cached code\");") + .unwrap(); + let output = deno.wait_with_output().unwrap(); + assert!(output.status.success()); + + let deno_out = std::str::from_utf8(&output.stdout).unwrap().trim(); + assert_eq!("Bye cached code", deno_out); +} + #[test] fn no_color() { let output = util::deno_cmd() -- cgit v1.2.3