diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-10-19 19:41:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 13:41:25 +0200 |
commit | f5c23f8058ed7ce85846c6b1e623329a09fa1a76 (patch) | |
tree | 665ecf11b2f339f0151f187867cc6249e68b94b8 | |
parent | d3dea24560f7434bd1020f0d9dc4c787f79479da (diff) |
fix(cli/repl): write all results to stdout (#7893)
This writes all evaluaton results to stdout regardless if the result is
an error or not.
This matches the behavior of other read-eval-print-loops like Node.
-rw-r--r-- | cli/repl.rs | 17 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 36 |
2 files changed, 25 insertions, 28 deletions
diff --git a/cli/repl.rs b/cli/repl.rs index 2e41b0565..be887e941 100644 --- a/cli/repl.rs +++ b/cli/repl.rs @@ -391,16 +391,13 @@ pub async fn run( let inspect_result = inspect_response.get("result").unwrap(); - match evaluate_exception_details { - Some(_) => eprintln!( - "Uncaught {}", - inspect_result.get("value").unwrap().as_str().unwrap() - ), - None => println!( - "{}", - inspect_result.get("value").unwrap().as_str().unwrap() - ), - } + let value = inspect_result.get("value").unwrap().as_str().unwrap(); + let output = match evaluate_exception_details { + Some(_) => format!("Uncaught {}", value), + None => value.to_string(), + }; + + println!("{}", output); editor.lock().unwrap().add_history_entry(line.as_str()); } diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index d375ba1a1..5bf1a5a85 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1232,7 +1232,7 @@ fn repl_test_eof() { #[test] fn repl_test_strict() { - let (_, err) = util::run_and_collect_output( + let (out, err) = util::run_and_collect_output( true, "repl", Some(vec![ @@ -1243,13 +1243,12 @@ fn repl_test_strict() { None, false, ); - assert!(err.contains( + assert!(out.contains( "Uncaught TypeError: Cannot add property c, object is not extensible" )); + assert!(err.is_empty()); } -const REPL_MSG: &str = "exit using ctrl+d or close()\n"; - #[test] fn repl_test_close_command() { let (out, err) = util::run_and_collect_output( @@ -1312,8 +1311,8 @@ fn repl_test_eval_unterminated() { None, false, ); - assert!(out.ends_with(REPL_MSG)); - assert!(err.contains("Unexpected end of input")); + assert!(out.contains("Unexpected end of input")); + assert!(err.is_empty()); } #[test] @@ -1325,8 +1324,8 @@ fn repl_test_reference_error() { None, false, ); - assert!(out.ends_with(REPL_MSG)); - assert!(err.contains("not_a_variable is not defined")); + assert!(out.contains("not_a_variable is not defined")); + assert!(err.is_empty()); } #[test] @@ -1338,8 +1337,8 @@ fn repl_test_syntax_error() { None, false, ); - assert!(out.ends_with(REPL_MSG)); - assert!(err.contains("Unexpected identifier")); + assert!(out.contains("Unexpected identifier")); + assert!(err.is_empty()); } #[test] @@ -1351,8 +1350,8 @@ fn repl_test_type_error() { None, false, ); - assert!(out.ends_with(REPL_MSG)); - assert!(err.contains("console is not a function")); + assert!(out.contains("console is not a function")); + assert!(err.is_empty()); } #[test] @@ -1425,8 +1424,8 @@ fn repl_test_save_last_thrown() { Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), false, ); - assert!(out.ends_with("1\n")); - assert_eq!(err, "Uncaught 1\n"); + assert!(out.ends_with("Uncaught 1\n1\n")); + assert!(err.is_empty()); } #[test] @@ -1453,10 +1452,11 @@ fn repl_test_assign_underscore_error() { Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), false, ); - assert!( - out.ends_with("Last thrown error is no longer saved to _error.\n1\n1\n") - ); - assert_eq!(err, "Uncaught 2\n"); + println!("{}", out); + assert!(out.ends_with( + "Last thrown error is no longer saved to _error.\n1\nUncaught 2\n1\n" + )); + assert!(err.is_empty()); } #[test] |