@@ -4,6 +4,7 @@ use core::panic::Location;
44const RED : & str = "\x1b [31m" ;
55const YELLOW : & str = "\x1b [33m" ;
66const BLUE : & str = "\x1b [34m" ;
7+ const MAGENTA : & str = "\x1b [35m" ;
78const CYAN : & str = "\x1b [36m" ;
89const BOLD : & str = "\x1b [1m" ;
910const RESET : & str = "\x1b [0m" ;
@@ -13,20 +14,21 @@ const RESET: &str = "\x1b[0m";
1314/// If `ansi_colors` is true, this function unconditionally prints ANSI color codes.
1415/// It should only be set to true only if it is known that the terminal supports it.
1516pub fn pretty_print_assertion ( assert : & AssertInfo < ' _ > , loc : Location < ' _ > , ansi_colors : bool ) {
17+ let macro_name = assert. macro_name ;
1618 if ansi_colors {
1719 print_pretty_header ( loc) ;
1820 match & assert. assertion {
19- Assertion :: Bool ( assert) => print_pretty_bool_assertion ( assert) ,
20- Assertion :: Binary ( assert) => print_pretty_binary_assertion ( assert) ,
21+ Assertion :: Bool ( assert) => print_pretty_bool_assertion ( macro_name , assert) ,
22+ Assertion :: Binary ( assert) => print_pretty_binary_assertion ( macro_name , assert) ,
2123 }
2224 if let Some ( msg) = & assert. message {
2325 print_pretty_message ( msg) ;
2426 }
2527 } else {
2628 print_plain_header ( loc) ;
2729 match & assert. assertion {
28- Assertion :: Bool ( assert) => print_plain_bool_assertion ( assert) ,
29- Assertion :: Binary ( assert) => print_plain_binary_assertion ( assert) ,
30+ Assertion :: Bool ( assert) => print_plain_bool_assertion ( macro_name , assert) ,
31+ Assertion :: Binary ( assert) => print_plain_binary_assertion ( macro_name , assert) ,
3032 }
3133 if let Some ( msg) = & assert. message {
3234 print_plain_message ( msg) ;
@@ -50,55 +52,111 @@ fn print_pretty_header(loc: Location<'_>) {
5052 ) ;
5153}
5254
53- fn print_plain_bool_assertion ( assert : & BoolAssertion ) {
54- eprintln ! ( "Assertion:\n {}" , assert. expr) ;
55- eprintln ! ( "Expansion:\n false" ) ;
55+ fn print_plain_bool_assertion ( macro_name : & ' static str , assert : & BoolAssertion ) {
56+ eprint ! (
57+ concat!(
58+ "Assertion:\n " ,
59+ " {macro_name}!( {expr} )\n " ,
60+ "Expansion:\n " ,
61+ " {macro_name}!( false )\n " ,
62+ ) ,
63+ macro_name = macro_name,
64+ expr = assert. expr,
65+ )
5666}
5767
58- fn print_pretty_bool_assertion ( assert : & BoolAssertion ) {
59- eprintln ! (
60- "{bold}Assertion:{reset}\n {cyan}{expr}{reset}" ,
68+ fn print_pretty_bool_assertion ( macro_name : & ' static str , assert : & BoolAssertion ) {
69+ eprint ! (
70+ concat!(
71+ "{bold}Assertion:{reset}\n " ,
72+ " {magenta}{macro_name}!( {cyan}{expr} {magenta}){reset}\n " ,
73+ "{bold}Expansion:{reset}\n " ,
74+ " {magenta}{macro_name}!( {cyan}false {magenta}){reset}\n " ,
75+ ) ,
76+ magenta = MAGENTA ,
6177 cyan = CYAN ,
6278 reset = RESET ,
6379 bold = BOLD ,
80+ macro_name = macro_name,
6481 expr = assert. expr,
6582 ) ;
66- eprintln ! (
67- "{bold}Expansion:{reset}\n {cyan}false{reset}" ,
68- cyan = CYAN ,
69- bold = BOLD ,
70- reset = RESET ,
71- ) ;
7283}
7384
74- fn print_plain_binary_assertion ( assert : & BinaryAssertion < ' _ > ) {
75- eprintln ! ( "Assertion:\n {} {} {}" , assert. left_expr, assert. op, assert. right_expr) ;
76- eprintln ! ( "Expansion:\n {:?} {} {:?}" , assert. left_val, assert. op, assert. right_val) ;
85+ fn print_plain_binary_assertion ( macro_name : & ' static str , assert : & BinaryAssertion < ' _ > ) {
86+ if macro_name == "assert_eq" || macro_name == "assert_ne" {
87+ eprint ! (
88+ concat!(
89+ "Assertion:\n " ,
90+ " {macro_name}!( {left_expr}, {right_expr} )\n " ,
91+ "Expansion:\n " ,
92+ " {macro_name}!( {left_val:?}, {right_val:?} )\n " ,
93+ ) ,
94+ macro_name = macro_name,
95+ left_expr = assert. left_expr,
96+ right_expr = assert. right_expr,
97+ left_val = assert. left_val,
98+ right_val = assert. right_val,
99+ ) ;
100+ } else {
101+ eprint ! (
102+ concat!(
103+ "Assertion:\n " ,
104+ " {macro_name}!( {left_expr} {op} {right_expr} )\n " ,
105+ "Expansion:\n " ,
106+ " {macro_name}!( {left_val:?} {op} {right_val:?} )\n " ,
107+ ) ,
108+ macro_name = macro_name,
109+ op = assert. op,
110+ left_expr = assert. left_expr,
111+ right_expr = assert. right_expr,
112+ left_val = assert. left_val,
113+ right_val = assert. right_val,
114+ ) ;
115+ } ;
77116}
78117
79- fn print_pretty_binary_assertion ( assert : & BinaryAssertion < ' _ > ) {
80- eprintln ! (
81- "{bold}Assertion:{reset}\n {cyan}{left} {bold}{blue}{op}{reset} {yellow}{right}{reset}" ,
82- cyan = CYAN ,
83- blue = BLUE ,
84- yellow = YELLOW ,
85- bold = BOLD ,
86- reset = RESET ,
87- left = assert. left_expr,
88- op = assert. op,
89- right = assert. right_expr,
90- ) ;
91- eprintln ! (
92- "{bold}Expansion:{reset}\n {cyan}{left:?} {bold}{blue}{op}{reset} {yellow}{right:?}{reset}" ,
93- cyan = CYAN ,
94- blue = BLUE ,
95- yellow = YELLOW ,
96- bold = BOLD ,
97- reset = RESET ,
98- left = assert. left_val,
99- op = assert. op,
100- right = assert. right_val,
101- ) ;
118+ fn print_pretty_binary_assertion ( macro_name : & ' static str , assert : & BinaryAssertion < ' _ > ) {
119+ if macro_name == "assert_eq" || macro_name == "assert_ne" {
120+ eprint ! (
121+ concat!(
122+ "{bold}Assertion:{reset}\n " ,
123+ " {magenta}{macro_name}!( {cyan}{left_expr}{magenta}, {yellow}{right_expr} {magenta}){reset}\n " ,
124+ "{bold}Expansion:{reset}\n " ,
125+ " {magenta}{macro_name}!( {cyan}{left_val:?}{magenta}, {yellow}{right_val:?} {magenta}){reset}\n " ,
126+ ) ,
127+ cyan = CYAN ,
128+ magenta = MAGENTA ,
129+ yellow = YELLOW ,
130+ bold = BOLD ,
131+ reset = RESET ,
132+ macro_name = macro_name,
133+ left_expr = assert. left_expr,
134+ right_expr = assert. right_expr,
135+ left_val = assert. left_val,
136+ right_val = assert. right_val,
137+ ) ;
138+ } else {
139+ eprint ! (
140+ concat!(
141+ "{bold}Assertion:{reset}\n " ,
142+ " {magenta}{macro_name}!( {cyan}{left_expr} {bold}{blue}{op}{reset} {yellow}{right_expr} {magenta}){reset}\n " ,
143+ "{bold}Expansion:{reset}\n " ,
144+ " {magenta}{macro_name}!( {cyan}{left_val:?} {bold}{blue}{op}{reset} {yellow}{right_val:?} {magenta}){reset}\n " ,
145+ ) ,
146+ blue = BLUE ,
147+ cyan = CYAN ,
148+ magenta = MAGENTA ,
149+ yellow = YELLOW ,
150+ bold = BOLD ,
151+ reset = RESET ,
152+ macro_name = macro_name,
153+ op = assert. op,
154+ left_expr = assert. left_expr,
155+ right_expr = assert. right_expr,
156+ left_val = assert. left_val,
157+ right_val = assert. right_val,
158+ ) ;
159+ } ;
102160}
103161
104162fn print_plain_message ( message : & std:: fmt:: Arguments < ' _ > ) {
0 commit comments