summaryrefslogtreecommitdiff
path: root/test_util/src
diff options
context:
space:
mode:
Diffstat (limited to 'test_util/src')
-rw-r--r--test_util/src/assertions.rs39
-rw-r--r--test_util/src/lib.rs3
2 files changed, 41 insertions, 1 deletions
diff --git a/test_util/src/assertions.rs b/test_util/src/assertions.rs
new file mode 100644
index 000000000..ecee14b1f
--- /dev/null
+++ b/test_util/src/assertions.rs
@@ -0,0 +1,39 @@
+#[macro_export]
+macro_rules! assert_ends_with {
+ ($left:expr, $right:expr $(,)?) => {
+ match (&$left, &$right) {
+ (actual, expected) => {
+ let actual = if expected.len() > actual.len() {
+ actual
+ } else {
+ &actual[actual.len() - expected.len()..]
+ };
+ pretty_assertions::assert_eq!(
+ actual,
+ *expected,
+ "should end with expected."
+ );
+ }
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! assert_contains {
+ ($string:expr, $($test:expr),+ $(,)?) => {
+ let string = &$string; // This might be a function call or something
+ if !($(string.contains($test))||+) {
+ panic!("{:?} does not contain any of {:?}", string, [$($test),+]);
+ }
+ }
+}
+
+#[macro_export]
+macro_rules! assert_not_contains {
+ ($string:expr, $($test:expr),+ $(,)?) => {
+ let string = &$string; // This might be a function call or something
+ if !($(!string.contains($test))||+) {
+ panic!("{:?} contained {:?}", string, [$($test),+]);
+ }
+ }
+}
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs
index 1373f758d..8df222115 100644
--- a/test_util/src/lib.rs
+++ b/test_util/src/lib.rs
@@ -49,6 +49,7 @@ use tokio_rustls::rustls;
use tokio_rustls::TlsAcceptor;
use tokio_tungstenite::accept_async;
+pub mod assertions;
pub mod lsp;
pub mod pty;
mod temp_dir;
@@ -1924,7 +1925,7 @@ pub fn test_pty2(args: &str, data: Vec<PtyData>) {
println!("ECHO: {}", echo.escape_debug());
// Windows may also echo the previous line, so only check the end
- assert!(normalize_text(&echo).ends_with(&normalize_text(s)));
+ assert_ends_with!(normalize_text(&echo), normalize_text(s));
}
PtyData::Output(s) => {
let mut line = String::new();