1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// This demonstrated Issue #84561: function-like macros produce unintuitive coverage results.
// expect-exit-status-101
#[derive(PartialEq, Eq)]
struct Foo(u32);
fn test3() {
let is_true = std::env::args().len() == 1;
let bar = Foo(1);
assert_eq!(bar, Foo(1));
let baz = Foo(0);
assert_ne!(baz, Foo(1));
println!("{:?}", Foo(1));
println!("{:?}", bar);
println!("{:?}", baz);
assert_eq!(Foo(1), Foo(1));
assert_ne!(Foo(0), Foo(1));
assert_eq!(Foo(2), Foo(2));
let bar = Foo(0);
assert_ne!(bar, Foo(3));
assert_ne!(Foo(0), Foo(4));
assert_eq!(Foo(3), Foo(3), "with a message");
println!("{:?}", bar);
println!("{:?}", Foo(1));
assert_ne!(Foo(0), Foo(5), "{}", if is_true { "true message" } else { "false message" });
assert_ne!(
Foo(0)
,
Foo(5)
,
"{}"
,
if
is_true
{
"true message"
} else {
"false message"
}
);
let is_true = std::env::args().len() == 1;
assert_eq!(
Foo(1),
Foo(1)
);
assert_ne!(
Foo(0),
Foo(1)
);
assert_eq!(
Foo(2),
Foo(2)
);
let bar = Foo(1);
assert_ne!(
bar,
Foo(3)
);
if is_true {
assert_ne!(
Foo(0),
Foo(4)
);
} else {
assert_eq!(
Foo(3),
Foo(3)
);
}
if is_true {
assert_ne!(
Foo(0),
Foo(4),
"with a message"
);
} else {
assert_eq!(
Foo(3),
Foo(3),
"with a message"
);
}
assert_ne!(
if is_true {
Foo(0)
} else {
Foo(1)
},
Foo(5)
);
assert_ne!(
Foo(5),
if is_true {
Foo(0)
} else {
Foo(1)
}
);
assert_ne!(
if is_true {
assert_eq!(
Foo(3),
Foo(3)
);
Foo(0)
} else {
assert_ne!(
if is_true {
Foo(0)
} else {
Foo(1)
},
Foo(5)
);
Foo(1)
},
Foo(5),
"with a message"
);
assert_eq!(
Foo(1),
Foo(3),
"this assert should fail"
);
assert_eq!(
Foo(3),
Foo(3),
"this assert should not be reached"
);
}
impl std::fmt::Debug for Foo {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "try and succeed")?;
Ok(())
}
}
static mut DEBUG_LEVEL_ENABLED: bool = false;
macro_rules! debug {
($($arg:tt)+) => (
if unsafe { DEBUG_LEVEL_ENABLED } {
println!($($arg)+);
}
);
}
fn test1() {
debug!("debug is enabled");
debug!("debug is enabled");
let _ = 0;
debug!("debug is enabled");
unsafe {
DEBUG_LEVEL_ENABLED = true;
}
debug!("debug is enabled");
}
macro_rules! call_debug {
($($arg:tt)+) => (
fn call_print(s: &str) {
print!("{}", s);
}
call_print("called from call_debug: ");
debug!($($arg)+);
);
}
fn test2() {
call_debug!("debug is enabled");
}
fn main() {
test1();
test2();
test3();
}
|