From 07359b795758179e1cffee23eae86e859898054b Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Wed, 28 Oct 2020 03:03:17 -0700 Subject: fix(repl): don't hang on unpaired braces (#8151) Previously, entering a single ']' would cause repl to forever accepting new lines, due to that `ValidationResult::Invalid` would actually be consumed by the editor itself while continue building the lines. Instead we should mark it as `Valid` and send the bad input for evaluation to get the proper error from V8. Before: ``` > ] (you can keep entering new line here, and it will never consume input until you Ctrl-C) ``` After: ``` > ] Uncaught SyntaxError: Unexpected token ']' > ``` --- cli/tests/integration_tests.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index da0a311bb..f7b4c345a 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1268,6 +1268,40 @@ fn repl_test_pty_multiline() { } } +#[cfg(unix)] +#[test] +fn repl_test_pty_unpaired_braces() { + use std::io::Read; + use util::pty::fork::*; + + let tests_path = util::tests_path(); + let fork = Fork::from_ptmx().unwrap(); + if let Ok(mut master) = fork.is_parent() { + master.write_all(b")\n").unwrap(); + master.write_all(b"]\n").unwrap(); + master.write_all(b"}\n").unwrap(); + master.write_all(b"close();\n").unwrap(); + + let mut output = String::new(); + master.read_to_string(&mut output).unwrap(); + + assert!(output.contains("Unexpected token ')'")); + assert!(output.contains("Unexpected token ']'")); + assert!(output.contains("Unexpected token '}'")); + + fork.wait().unwrap(); + } else { + util::deno_cmd() + .current_dir(tests_path) + .env("NO_COLOR", "1") + .arg("repl") + .spawn() + .unwrap() + .wait() + .unwrap(); + } +} + #[test] fn run_watch_with_importmap_and_relative_paths() { fn create_relative_tmp_file( @@ -1516,6 +1550,21 @@ fn repl_test_eval_unterminated() { assert!(err.is_empty()); } +#[test] +fn repl_test_unpaired_braces() { + for right_brace in &[")", "]", "}"] { + let (out, err) = util::run_and_collect_output( + true, + "repl", + Some(vec![right_brace]), + None, + false, + ); + assert!(out.contains("Unexpected token")); + assert!(err.is_empty()); + } +} + #[test] fn repl_test_reference_error() { let (out, err) = util::run_and_collect_output( -- cgit v1.2.3