From 864ce6e83224fb9fedfc83d5647fb103c219c8af Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 6 Aug 2021 17:30:28 -0400 Subject: feat(repl): add --eval flag for evaluating code when the repl starts (#11590) --- cli/tests/integration/repl_tests.rs | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index b96b398ae..7ce91d406 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -436,7 +436,7 @@ fn exports_stripped() { } #[test] -fn eval_unterminated() { +fn call_eval_unterminated() { let (out, err) = util::run_and_collect_output( true, "repl", @@ -644,3 +644,45 @@ fn custom_inspect() { assert!(out.contains("Oops custom inspect error")); assert!(err.is_empty()); } + +#[test] +fn eval_flag_valid_input() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval", "const t = 10;"], + Some(vec!["t * 500;"]), + None, + false, + ); + assert!(out.contains("5000")); + assert!(err.is_empty()); +} + +#[test] +fn eval_flag_parse_error() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval", "const %"], + Some(vec!["250 * 10"]), + None, + false, + ); + assert!(test_util::strip_ansi_codes(&out) + .contains("error in --eval flag. parse error: Unexpected token `%`.")); + assert!(out.contains("2500")); // should not prevent input + assert!(err.is_empty()); +} + +#[test] +fn eval_flag_runtime_error() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval", "throw new Error('Testing')"], + Some(vec!["250 * 10"]), + None, + false, + ); + assert!(out.contains("error in --eval flag. Uncaught Error: Testing")); + assert!(out.contains("2500")); // should not prevent input + assert!(err.is_empty()); +} -- cgit v1.2.3