From 22d2e0223aa775f419c364ee87c7ba938eb5fc50 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 29 Jul 2023 22:19:14 -0400 Subject: [PATCH] Fix nested string interpolation test --- crates/repl_test/src/cli.rs | 18 +++++++++++++++++- crates/repl_test/src/tests.rs | 17 +---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/crates/repl_test/src/cli.rs b/crates/repl_test/src/cli.rs index 314d31ad868..2c95ba99b5e 100644 --- a/crates/repl_test/src/cli.rs +++ b/crates/repl_test/src/cli.rs @@ -3,6 +3,7 @@ use std::io::Write; use std::path::PathBuf; use std::process::{Command, ExitStatus, Stdio}; +use roc_repl_cli::repl_state::TIPS; use roc_repl_cli::{SHORT_INSTRUCTIONS, WELCOME_MESSAGE}; use roc_test_utils::assert_multiline_str_eq; @@ -152,7 +153,22 @@ pub fn expect_failure(input: &str, expected: &str) { match out.stdout.find(ERROR_MESSAGE_START) { Some(index) => { assert_multiline_str_eq!("", out.stderr.as_str()); - assert_multiline_str_eq!(expected, &out.stdout[index..]); + + // For some unknown reason, in the non-wasm tests, if there's a syntax error + // (e.g. in the nested string interpolation test), it prints the tips at the end. + // This doesn't happen in the actual CLI repl or in the wasm tests. + // + // Ideally we'd figure out why that's happening and stop it from happening, + // but since it only happens in the CLI tests, in the meantime this is an acceptable fix. + let tips_index = out + .stdout + .rfind(std::str::from_utf8(&strip_ansi_escapes::strip(TIPS).unwrap()).unwrap()) + .unwrap_or(out.stdout.len()); + + assert_multiline_str_eq!( + expected.trim_end(), + (&out.stdout[index..tips_index]).trim_end() + ); assert!(out.status.success()); } None => { diff --git a/crates/repl_test/src/tests.rs b/crates/repl_test/src/tests.rs index 9b4bb793399..ab9286e7e68 100644 --- a/crates/repl_test/src/tests.rs +++ b/crates/repl_test/src/tests.rs @@ -1380,22 +1380,7 @@ fn interpolation_with_nested_interpolation() { You can learn more about string interpolation at - - - Enter an expression to evaluate, or a definition (like x = 1) to use in future expressions. - - Unless there was a compile-time error, expressions get automatically named so you can refer to them later. - For example, if you see # val1 after an output, you can now refer to that expression as val1 in future expressions. - - Tips: - - - ctrl-v + ctrl-j makes a newline - - - :q to quit - - - :help"# + "# ), - // TODO figure out why the tests prints the repl help text at the end, but only after syntax errors or something? - // In the actual repl this doesn't happen, only in the test. ); }