mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 07:17:50 +03:00
Merge pull request #2111 from rtfeldman/joshuawarner32/multiline-string-asserts
Make assert output for fmt+parse tests more understandable
This commit is contained in:
commit
1c7671c9ab
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -3374,6 +3374,7 @@ dependencies = [
|
||||
"roc_module",
|
||||
"roc_parse",
|
||||
"roc_region",
|
||||
"roc_test_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3516,9 +3517,7 @@ dependencies = [
|
||||
name = "roc_parse"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"bumpalo",
|
||||
"diff",
|
||||
"encode_unicode",
|
||||
"indoc",
|
||||
"pretty_assertions",
|
||||
@ -3527,6 +3526,7 @@ dependencies = [
|
||||
"roc_collections",
|
||||
"roc_module",
|
||||
"roc_region",
|
||||
"roc_test_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3591,6 +3591,10 @@ dependencies = [
|
||||
name = "roc_std"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "roc_test_utils"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "roc_types"
|
||||
version = "0.1.0"
|
||||
|
@ -32,6 +32,7 @@ members = [
|
||||
"code_markup",
|
||||
"reporting",
|
||||
"roc_std",
|
||||
"test_utils",
|
||||
"utils",
|
||||
"docs",
|
||||
"linker",
|
||||
|
@ -47,7 +47,7 @@ install-zig-llvm-valgrind-clippy-rustfmt:
|
||||
|
||||
copy-dirs:
|
||||
FROM +install-zig-llvm-valgrind-clippy-rustfmt
|
||||
COPY --dir cli cli_utils compiler docs editor ast code_markup utils reporting roc_std vendor examples linker Cargo.toml Cargo.lock version.txt ./
|
||||
COPY --dir cli cli_utils compiler docs editor ast code_markup utils test_utils reporting roc_std vendor examples linker Cargo.toml Cargo.lock version.txt ./
|
||||
|
||||
test-zig:
|
||||
FROM +install-zig-llvm-valgrind-clippy-rustfmt
|
||||
|
@ -15,3 +15,4 @@ bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.0.0"
|
||||
indoc = "1.0.3"
|
||||
roc_test_utils = { path = "../../test_utils" }
|
||||
|
@ -1,6 +1,4 @@
|
||||
#[macro_use]
|
||||
extern crate pretty_assertions;
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
extern crate bumpalo;
|
||||
extern crate roc_fmt;
|
||||
@ -14,6 +12,7 @@ mod test_fmt {
|
||||
use roc_fmt::module::fmt_module;
|
||||
use roc_parse::module::{self, module_defs};
|
||||
use roc_parse::parser::{Parser, State};
|
||||
use roc_test_utils::assert_multiline_str_eq;
|
||||
|
||||
fn expr_formats_to(input: &str, expected: &str) {
|
||||
let arena = Bump::new();
|
||||
@ -26,7 +25,7 @@ mod test_fmt {
|
||||
|
||||
actual.format_with_options(&mut buf, Parens::NotNeeded, Newlines::Yes, 0);
|
||||
|
||||
assert_eq!(buf, expected)
|
||||
assert_multiline_str_eq!(expected, buf.as_str())
|
||||
}
|
||||
Err(error) => panic!("Unexpected parse failure when parsing this for formatting:\n\n{}\n\nParse error was:\n\n{:?}\n\n", input, error)
|
||||
};
|
||||
@ -56,7 +55,7 @@ mod test_fmt {
|
||||
Err(error) => panic!("Unexpected parse failure when parsing this for defs formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error)
|
||||
}
|
||||
|
||||
assert_eq!(buf, expected)
|
||||
assert_multiline_str_eq!(expected, buf.as_str())
|
||||
}
|
||||
Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error)
|
||||
};
|
||||
|
@ -17,5 +17,4 @@ pretty_assertions = "1.0.0"
|
||||
indoc = "1.0.3"
|
||||
quickcheck = "1.0.3"
|
||||
quickcheck_macros = "1.0.0"
|
||||
diff = "0.1.12"
|
||||
ansi_term = "0.12.1"
|
||||
roc_test_utils = { path = "../../test_utils" }
|
||||
|
@ -23,6 +23,7 @@ mod test_parse {
|
||||
use roc_parse::parser::{Parser, State, SyntaxError};
|
||||
use roc_parse::test_helpers::parse_expr_with;
|
||||
use roc_region::all::{Located, Region};
|
||||
use roc_test_utils::assert_multiline_str_eq;
|
||||
use std::{f64, i64};
|
||||
|
||||
macro_rules! snapshot_tests {
|
||||
@ -254,10 +255,7 @@ mod test_parse {
|
||||
} else {
|
||||
let expected_result = std::fs::read_to_string(&result_path).unwrap();
|
||||
|
||||
// TODO: do a diff over the "real" content of these strings, rather than
|
||||
// the debug-formatted content. As is, we get an ugly single-line diff
|
||||
// from pretty_assertions
|
||||
assert_eq!(expected_result, actual_result);
|
||||
assert_multiline_str_eq!(expected_result, actual_result);
|
||||
}
|
||||
}
|
||||
|
||||
|
11
test_utils/Cargo.toml
Normal file
11
test_utils/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "roc_test_utils"
|
||||
version = "0.1.0"
|
||||
authors = ["The Roc Contributors"]
|
||||
license = "UPL-1.0"
|
||||
edition = "2018"
|
||||
description = "Utility functions used all over the code base."
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
15
test_utils/src/lib.rs
Normal file
15
test_utils/src/lib.rs
Normal file
@ -0,0 +1,15 @@
|
||||
#[derive(PartialEq)]
|
||||
pub struct DebugAsDisplay<T>(pub T);
|
||||
|
||||
impl<T: std::fmt::Display> std::fmt::Debug for DebugAsDisplay<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_multiline_str_eq {
|
||||
($a:expr, $b:expr) => {
|
||||
assert_eq!($crate::DebugAsDisplay($a), $crate::DebugAsDisplay($b))
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user