summaryrefslogtreecommitdiff
path: root/test_util/src
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-08-18 21:29:32 +0100
committerGitHub <noreply@github.com>2020-08-18 16:29:32 -0400
commit015fa0bd41ce51afbee4a1413cb90534155c041f (patch)
tree3220c821156a011225392d2361fdf7272c7be952 /test_util/src
parentf6e9150b33168ab8c5e48238860e2c3f3bf625f3 (diff)
refactor: permissions (#7074)
Diffstat (limited to 'test_util/src')
-rw-r--r--test_util/src/lib.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs
index bd75133b2..9b029c355 100644
--- a/test_util/src/lib.rs
+++ b/test_util/src/lib.rs
@@ -7,6 +7,8 @@ extern crate lazy_static;
use futures::future::{self, FutureExt};
use os_pipe::pipe;
+#[cfg(unix)]
+pub use pty;
use regex::Regex;
use std::env;
use std::io::Read;
@@ -767,7 +769,7 @@ impl CheckOutputIntegrationTest {
}
}
-fn wildcard_match(pattern: &str, s: &str) -> bool {
+pub fn wildcard_match(pattern: &str, s: &str) -> bool {
pattern_match(pattern, s, "[WILDCARD]")
}
@@ -820,6 +822,39 @@ pub fn pattern_match(pattern: &str, s: &str, wildcard: &str) -> bool {
t.1.is_empty()
}
+/// Kind of reflects `itest!()`. Note that the pty's output (which also contains
+/// stdin content) is compared against the content of the `output` path.
+#[cfg(unix)]
+pub fn test_pty(args: &str, output_path: &str, input: &[u8]) {
+ use pty::fork::Fork;
+
+ let tests_path = tests_path();
+ let fork = Fork::from_ptmx().unwrap();
+ if let Ok(mut master) = fork.is_parent() {
+ let mut output_actual = String::new();
+ master.write_all(input).unwrap();
+ master.read_to_string(&mut output_actual).unwrap();
+ fork.wait().unwrap();
+
+ let output_expected =
+ std::fs::read_to_string(tests_path.join(output_path)).unwrap();
+ if !wildcard_match(&output_expected, &output_actual) {
+ println!("OUTPUT\n{}\nOUTPUT", output_actual);
+ println!("EXPECTED\n{}\nEXPECTED", output_expected);
+ panic!("pattern match failed");
+ }
+ } else {
+ deno_cmd()
+ .current_dir(tests_path)
+ .env("NO_COLOR", "1")
+ .args(args.split_whitespace())
+ .spawn()
+ .unwrap()
+ .wait()
+ .unwrap();
+ }
+}
+
#[test]
fn test_wildcard_match() {
let fixtures = vec![