Skip to content

unit test miette_error depends on running in terminal #1139

@alexanderkjall

Description

@alexanderkjall

when running the test-suite for pest in Debians build system the test miette_error fails like this:

thread 'error::tests::miette_error' panicked at src/error.rs:1185:9:
assertion `left == right` failed
  left: "  × Failure to parse at Pos((2, 1))\n   ╭────\n 1 │ def\n   · ┬\n   · ╰── unexpected 4, 5, or 6; expected 1, 2, or 3\n   ╰────\n  help: unexpected 4, 5, or 6; expected 1,
2, or 3\n"
 right: "  \u{1b}[31m×\u{1b}[0m Failure to parse at Pos((2, 1))\n   ╭────\n \u{1b}[2m1\u{1b}[0m │ def\n   · \u{1b}[35;1m┬\u{1b}[0m\n   · \u{1b}[35;1m╰── \u{1b}[35;1munexpected 4, 5
, or 6; expected 1, 2, or 3\u{1b}[0m\u{1b}[0m\n   ╰────\n\u{1b}[36m  help: \u{1b}[0munexpected 4, 5, or 6; expected 1, 2, or 3\n"

It looks to be as the color escape information is missing. Would it be possible to make this less fragile?

The following patch fixes our problem, but I guess that it would break other types of invocations, so I'm not sending it as a PR:

diff --git a/src/error.rs b/src/error.rs
index 4012c4a..04cde3a 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1185,13 +1185,13 @@ mod tests {
         assert_eq!(
             format!("{:?}", miette_error),
             [
-                "  \u{1b}[31m×\u{1b}[0m Failure to parse at Pos((2, 1))",
+               "  × Failure to parse at Pos((2, 1))",
                 "   ╭────",
-                " \u{1b}[2m1\u{1b}[0m │ def",
-                "   · \u{1b}[35;1m┬\u{1b}[0m",
-                "   · \u{1b}[35;1m╰── \u{1b}[35;1munexpected 4, 5, or 6; expected 1, 2, or 3\u{1b}[0m\u{1b}[0m",
+                " 1 │ def",
+                "   · ┬",
+                "   · ╰── unexpected 4, 5, or 6; expected 1, 2, or 3",
                 "   ╰────",
-                "\u{1b}[36m  help: \u{1b}[0munexpected 4, 5, or 6; expected 1, 2, or 3\n"
+                "  help: unexpected 4, 5, or 6; expected 1, 2, or 3\n"
             ]
             .join("\n")
         );

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions