]> git.proxmox.com Git - rustc.git/blobdiff - vendor/pretty_assertions/src/lib.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / vendor / pretty_assertions / src / lib.rs
index a2482998fac856994350eda7b1bd4de5ed287cfa..2661396912959d8bd8cc38569c44d5275edde04e 100644 (file)
@@ -2,7 +2,7 @@
 //!\r
 //! When writing tests in Rust, you'll probably use `assert_eq!(a, b)` _a lot_.\r
 //!\r
-//! If such a test fails, it will present all the details of `a` and `b`. \r
+//! If such a test fails, it will present all the details of `a` and `b`.\r
 //! But you have to spot the differences yourself, which is not always straightforward,\r
 //! like here:\r
 //!\r
@@ -15,7 +15,7 @@
 //! Yep — and you only need **one line of code** to make it happen:\r
 //!\r
 //! ```rust,ignore\r
-//! #[macro_use] extern crate pretty_assertions;\r
+//! use pretty_assertions::{assert_eq, assert_ne};\r
 //! ```\r
 //!\r
 //! <details>\r
@@ -23,8 +23,8 @@
 //!\r
 //! ```rust,ignore\r
 //! // 1. add the `pretty_assertions` dependency to `Cargo.toml`.\r
-//! // 2. insert this line at the top of your crate root or integration test\r
-//! #[macro_use] extern crate pretty_assertions;\r
+//! // 2. insert this line at the top of each module, as needed\r
+//! use pretty_assertions::{assert_eq, assert_ne};\r
 //!\r
 //! fn main() {\r
 //!     #[derive(Debug, PartialEq)]\r
 //! and it will only be used for compiling tests, examples, and benchmarks.\r
 //! This way the compile time of `cargo build` won't be affected!\r
 //!\r
-//! In your crate root, also add `#[cfg(test)]` to the crate import, like this:\r
+//! Also add `#[cfg(test)]` to your `use` statements, like this:\r
 //!\r
 //! ```rust,ignore\r
-//! #[cfg(test)] // <-- not needed in examples + integration tests\r
-//! #[macro_use]\r
-//! extern crate pretty_assertions;\r
+//! #[cfg(test)]\r
+//! use pretty_assertions::{assert_eq, assert_ne};\r
 //! ```\r
 //!\r
 //! ## Note\r
 //!\r
-//! * Each example and integration test also needs `#[macro_use] extern crate\r
-//!   pretty_assertions`, if you want colorful diffs there.\r
+//! * Since `Rust 2018` edition, you need to declare\r
+//!   `use pretty_assertions::{assert_eq, assert_ne};` per module.\r
+//!   Before you would write `#[macro_use] extern crate pretty_assertions;`.\r
 //! * The replacement is only effective in your own crate, not in other libraries\r
 //!   you include.\r
 //! * `assert_ne` is also switched to multi-line presentation, but does _not_ show\r
 //!   a diff.\r
 \r
-extern crate difference;\r
 extern crate ansi_term;\r
+extern crate difference;\r
+\r
+#[cfg(windows)]\r
+extern crate ctor;\r
+#[cfg(windows)]\r
+extern crate output_vt100;\r
+\r
 mod format_changeset;\r
 \r
-use std::fmt::{self, Debug, Display};\r
 use difference::Changeset;\r
+use std::fmt::{self, Debug, Display};\r
 \r
-use format_changeset::format_changeset;\r
+use crate::format_changeset::format_changeset;\r
 pub use ansi_term::Style;\r
 \r
+#[cfg(windows)]\r
+use ctor::*;\r
+#[cfg(windows)]\r
+#[ctor]\r
+fn init() {\r
+    output_vt100::try_init().ok(); // Do not panic on fail\r
+}\r
+\r
 #[doc(hidden)]\r
 pub struct Comparison(Changeset);\r
 \r
@@ -129,9 +143,17 @@ macro_rules! assert_eq {
 }\r
 \r
 #[macro_export]\r
-#[doc(hidden)]\r
-macro_rules! __assert_ne {\r
-    ($left:expr, $right:expr, $maybe_semicolon:expr, $($arg:tt)+) => ({\r
+macro_rules! assert_ne {\r
+    ($left:expr, $right:expr) => ({\r
+        assert_ne!(@ $left, $right, "", "");\r
+    });\r
+    ($left:expr, $right:expr,) => ({\r
+        assert_ne!(@ $left, $right, "", "");\r
+    });\r
+    ($left:expr, $right:expr, $($arg:tt)+) => ({\r
+        assert_ne!(@ $left, $right, ": ", $($arg)+);\r
+    });\r
+    (@ $left:expr, $right:expr, $maybe_semicolon:expr, $($arg:tt)+) => ({\r
         match (&($left), &($right)) {\r
             (left_val, right_val) => {\r
                 if *left_val == *right_val {\r
@@ -170,16 +192,3 @@ macro_rules! __assert_ne {
         }\r
     });\r
 }\r
-\r
-#[macro_export]\r
-macro_rules! assert_ne {\r
-    ($left:expr, $right:expr) => ({\r
-        __assert_ne!($left, $right, "", "");\r
-    });\r
-    ($left:expr, $right:expr,) => ({\r
-        __assert_ne!($left, $right, "", "");\r
-    });\r
-    ($left:expr, $right:expr, $($arg:tt)+) => ({\r
-        __assert_ne!($left, $right, ": ", $($arg)+);\r
-    });\r
-}\r