Skip to content

Multi-line diffs still show original strings #387

@mgeisler

Description

@mgeisler

Hello!

I find the multi-line diffs super useful and a main reason to depend on the crate. However, I think they could be made better if they would

  • hide the original strings, at least if the strings are very long
  • not diff the escaped debug output

Today, I see output like this from AOSP:

---- cargo::metadata::tests::parse_metadata stdout ----
thread 'cargo::metadata::tests::parse_metadata' panicked at development/tools/cargo_embargo/src/cargo/metadata.rs:495:13:

Value of: format!("{crates:#?}")
Expected: is equal to "[\n    [\n        Crate {\n            name: \"either\",\n            package_name: \"either\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Lib,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n        Crate {\n            name: \"either\",\n            package_name: \"either\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Test,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [\n                Extern {\n                    name: \"serde_json\",\n                    lib_name: \"serde_json\",\n                    extern_type: Rust,\n                },\n            ],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n    ],\n]"
Actual: "[\n    [\n        Crate {\n            name: \"either\",\n            package_name: \"either!\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Lib,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n        Crate {\n            name: \"either\",\n            package_name: \"either!\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Test,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [\n                Extern {\n                    name: \"serde_json\",\n                    lib_name: \"serde_json\",\n                    extern_type: Rust,\n                },\n            ],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n    ],\n]",
  which isn't equal to "[\n    [\n        Crate {\n            name: \"either\",\n            package_name: \"either\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Lib,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n        Crate {\n            name: \"either\",\n            package_name: \"either\",\n            version: Some(\n                \"1.9.0\",\n            ),\n            types: [\n                Test,\n            ],\n            target: Some(\n                \"x86_64-unknown-linux-gnu\",\n            ),\n            features: [\n                \"default\",\n                \"use_std\",\n            ],\n            cfgs: [],\n            externs: [\n                Extern {\n                    name: \"serde_json\",\n                    lib_name: \"serde_json\",\n                    extern_type: Rust,\n                },\n            ],\n            codegens: [],\n            cap_lints: \"\",\n            static_libs: [],\n            shared_libs: [],\n            edition: \"2018\",\n            package_dir: \".../external/rust/crates/either\",\n            main_src: \"src/lib.rs\",\n            empty_test: false,\n        },\n    ],\n]"
  Difference(-actual / +expected):
   [
       [
           Crate {
               name: \"either\",
  -            package_name: \"either!\",
  +            package_name: \"either\",
               version: Some(
                   \"1.9.0\",
   <---- 22 common lines omitted ---->
           Crate {
               name: \"either\",
  -            package_name: \"either!\",
  +            package_name: \"either\",
               version: Some(
                   \"1.9.0\",
   <---- 28 common lines omitted ---->
       ],
   ]
  at development/tools/cargo_embargo/src/cargo/metadata.rs:495:13

The \" in the diff output makes me think that there is some double-escaping going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions