Fix a bunch of repl test trimming issues

This commit is contained in:
Richard Feldman 2022-10-30 15:06:36 -04:00
parent 8b4e864a90
commit ea67b729c3
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 30 additions and 48 deletions

View file

@ -124,16 +124,24 @@ fn repl_eval(input: &str) -> Out {
}
pub fn expect_success(input: &str, expected: &str) {
let out = repl_eval(input);
let out = repl_eval(input.trim());
assert_multiline_str_eq!("", out.stderr.as_str());
// Don't consider the auto variable name (e.g. "# val1") at the end.
// The state.rs tests do that!
let line = out.stdout.lines().last().unwrap();
let mut iter = out.stdout.lines().rev();
let line = iter.next().unwrap();
let comment_index = line.rfind("#").unwrap_or_else(|| line.len());
let line_without_comment = line[0..comment_index].trim_end();
assert_multiline_str_eq!(expected, line[0..comment_index].trim_end());
// Sometimes the "# val1" wraps around to its own line; if this happens,
// we just use the preceding line instead.
if line_without_comment.is_empty() {
assert_multiline_str_eq!(expected, iter.next().unwrap().trim_end());
} else {
assert_multiline_str_eq!(expected, line_without_comment);
}
assert!(out.status.success());
}