mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
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.
This commit is contained in:
parent
d3dea24560
commit
f5c23f8058
2 changed files with 25 additions and 28 deletions
17
cli/repl.rs
17
cli/repl.rs
|
@ -391,16 +391,13 @@ pub async fn run(
|
||||||
|
|
||||||
let inspect_result = inspect_response.get("result").unwrap();
|
let inspect_result = inspect_response.get("result").unwrap();
|
||||||
|
|
||||||
match evaluate_exception_details {
|
let value = inspect_result.get("value").unwrap().as_str().unwrap();
|
||||||
Some(_) => eprintln!(
|
let output = match evaluate_exception_details {
|
||||||
"Uncaught {}",
|
Some(_) => format!("Uncaught {}", value),
|
||||||
inspect_result.get("value").unwrap().as_str().unwrap()
|
None => value.to_string(),
|
||||||
),
|
};
|
||||||
None => println!(
|
|
||||||
"{}",
|
println!("{}", output);
|
||||||
inspect_result.get("value").unwrap().as_str().unwrap()
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.lock().unwrap().add_history_entry(line.as_str());
|
editor.lock().unwrap().add_history_entry(line.as_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1232,7 +1232,7 @@ fn repl_test_eof() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn repl_test_strict() {
|
fn repl_test_strict() {
|
||||||
let (_, err) = util::run_and_collect_output(
|
let (out, err) = util::run_and_collect_output(
|
||||||
true,
|
true,
|
||||||
"repl",
|
"repl",
|
||||||
Some(vec![
|
Some(vec![
|
||||||
|
@ -1243,13 +1243,12 @@ fn repl_test_strict() {
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(err.contains(
|
assert!(out.contains(
|
||||||
"Uncaught TypeError: Cannot add property c, object is not extensible"
|
"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]
|
#[test]
|
||||||
fn repl_test_close_command() {
|
fn repl_test_close_command() {
|
||||||
let (out, err) = util::run_and_collect_output(
|
let (out, err) = util::run_and_collect_output(
|
||||||
|
@ -1312,8 +1311,8 @@ fn repl_test_eval_unterminated() {
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(out.ends_with(REPL_MSG));
|
assert!(out.contains("Unexpected end of input"));
|
||||||
assert!(err.contains("Unexpected end of input"));
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1325,8 +1324,8 @@ fn repl_test_reference_error() {
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(out.ends_with(REPL_MSG));
|
assert!(out.contains("not_a_variable is not defined"));
|
||||||
assert!(err.contains("not_a_variable is not defined"));
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1338,8 +1337,8 @@ fn repl_test_syntax_error() {
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(out.ends_with(REPL_MSG));
|
assert!(out.contains("Unexpected identifier"));
|
||||||
assert!(err.contains("Unexpected identifier"));
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1351,8 +1350,8 @@ fn repl_test_type_error() {
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(out.ends_with(REPL_MSG));
|
assert!(out.contains("console is not a function"));
|
||||||
assert!(err.contains("console is not a function"));
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1425,8 +1424,8 @@ fn repl_test_save_last_thrown() {
|
||||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(out.ends_with("1\n"));
|
assert!(out.ends_with("Uncaught 1\n1\n"));
|
||||||
assert_eq!(err, "Uncaught 1\n");
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1453,10 +1452,11 @@ fn repl_test_assign_underscore_error() {
|
||||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
assert!(
|
println!("{}", out);
|
||||||
out.ends_with("Last thrown error is no longer saved to _error.\n1\n1\n")
|
assert!(out.ends_with(
|
||||||
);
|
"Last thrown error is no longer saved to _error.\n1\nUncaught 2\n1\n"
|
||||||
assert_eq!(err, "Uncaught 2\n");
|
));
|
||||||
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue