summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorMarcus Hultman <marcus.hultman1@gmail.com>2020-11-30 10:08:03 -0600
committerGitHub <noreply@github.com>2020-11-30 11:08:03 -0500
commitc7276e15e54b43aa6649ca149d92811059c6415f (patch)
treeb8566602042d225282f146ca1559ebab754b2907 /cli/tests
parent7a4d0fc22b08f71f17d6efbdd89a28fc8fcb452f (diff)
feat(unstable): add cbreak option to setRaw (#8383)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration_tests.rs33
-rw-r--r--cli/tests/raw_mode_cbreak.ts15
2 files changed, 48 insertions, 0 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 8ad4ea5ed..1f40acbcb 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -218,6 +218,39 @@ pub fn test_raw_tty() {
}
}
+#[cfg(unix)]
+#[test]
+pub fn test_raw_tty_cbreak() {
+ use std::io::{Read, Write};
+ use util::pty::fork::*;
+ let deno_exe = util::deno_exe_path();
+ let root_path = util::root_path();
+ let fork = Fork::from_ptmx().unwrap();
+
+ if let Ok(mut master) = fork.is_parent() {
+ let mut obytes: [u8; 100] = [0; 100];
+ let mut nread = master.read(&mut obytes).unwrap();
+ assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "S");
+ master.write_all(&[3]).unwrap(); // send SIGINT
+ master.flush().unwrap();
+ nread = master.read(&mut obytes).unwrap();
+ assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "A");
+ fork.wait().unwrap();
+ } else {
+ // Keep echo enabled such that 'C^' would be printed in non-raw mode.
+ std::env::set_current_dir(root_path).unwrap();
+ let err = exec::Command::new(deno_exe)
+ .arg("run")
+ .arg("--unstable")
+ .arg("--quiet")
+ .arg("--no-check")
+ .arg("cli/tests/raw_mode_cbreak.ts")
+ .exec();
+ println!("err {}", err);
+ unreachable!()
+ }
+}
+
#[test]
fn test_pattern_match() {
// foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy
diff --git a/cli/tests/raw_mode_cbreak.ts b/cli/tests/raw_mode_cbreak.ts
new file mode 100644
index 000000000..6506e89d7
--- /dev/null
+++ b/cli/tests/raw_mode_cbreak.ts
@@ -0,0 +1,15 @@
+Deno.setRaw(0, true);
+Deno.setRaw(0, true, { cbreak: true }); // Can be called multiple times
+
+const signal = Deno.signals.interrupt();
+
+Deno.stdout.writeSync(new TextEncoder().encode("S"));
+
+await signal;
+
+Deno.stdout.writeSync(new TextEncoder().encode("A"));
+
+signal.dispose();
+
+Deno.setRaw(0, false); // restores old mode.
+Deno.setRaw(0, false); // Can be safely called multiple times