Skip to content

Commit

Permalink
Fix nested string interpolation test
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfeldman committed Jul 30, 2023
1 parent 7d491f1 commit 22d2e02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
18 changes: 17 additions & 1 deletion crates/repl_test/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 => {
Expand Down
17 changes: 1 addition & 16 deletions crates/repl_test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,22 +1380,7 @@ fn interpolation_with_nested_interpolation() {
You can learn more about string interpolation at
<https://www.roc-lang.org/tutorial#string-interpolation>
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.
);
}

0 comments on commit 22d2e02

Please sign in to comment.