diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2021-08-06 17:30:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 17:30:28 -0400 |
commit | 864ce6e83224fb9fedfc83d5647fb103c219c8af (patch) | |
tree | 1cd07ae4dd14cb292759921a03d75034a120db72 /cli/tests/integration/repl_tests.rs | |
parent | 33c8d790c3d358a475c9ba828043e2c19e8d4b37 (diff) |
feat(repl): add --eval flag for evaluating code when the repl starts (#11590)
Diffstat (limited to 'cli/tests/integration/repl_tests.rs')
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 44 |
1 files changed, 43 insertions, 1 deletions
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()); +} |