-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
macro-comma-support-rpass.rs
349 lines (299 loc) · 7.53 KB
/
macro-comma-support-rpass.rs
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// run-pass
// This is meant to be a comprehensive test of invocations with/without
// trailing commas (or other, similar optionally-trailing separators).
// Every macro is accounted for, even those not tested in this file.
// (There will be a note indicating why).
// std and core are both tested because they may contain separate
// implementations for some macro_rules! macros as an implementation
// detail.
// ignore-pretty issue #37195
// compile-flags: --test -C debug_assertions=yes
// revisions: std core
#![cfg_attr(core, no_std)]
#![allow(deprecated)] // for deprecated `try!()` macro
#![feature(concat_idents)]
#[cfg(std)] use std::fmt;
#[cfg(core)] use core::fmt;
#[test]
fn assert() {
assert!(true);
assert!(true,);
assert!(true, "hello");
assert!(true, "hello",);
assert!(true, "hello {}", "world");
assert!(true, "hello {}", "world",);
}
#[test]
fn assert_eq() {
assert_eq!(1, 1);
assert_eq!(1, 1,);
assert_eq!(1, 1, "hello");
assert_eq!(1, 1, "hello",);
assert_eq!(1, 1, "hello {}", "world");
assert_eq!(1, 1, "hello {}", "world",);
}
#[test]
fn assert_ne() {
assert_ne!(1, 2);
assert_ne!(1, 2,);
assert_ne!(1, 2, "hello");
assert_ne!(1, 2, "hello",);
assert_ne!(1, 2, "hello {}", "world");
assert_ne!(1, 2, "hello {}", "world",);
}
#[test]
fn cfg() {
let _ = cfg!(pants);
let _ = cfg!(pants,);
let _ = cfg!(pants = "pants");
let _ = cfg!(pants = "pants",);
let _ = cfg!(all(pants));
let _ = cfg!(all(pants),);
let _ = cfg!(all(pants,));
let _ = cfg!(all(pants,),);
}
#[test]
fn column() {
let _ = column!();
}
// compile_error! is in a companion to this test in compile-fail
#[test]
fn concat() {
let _ = concat!();
let _ = concat!("hello");
let _ = concat!("hello",);
let _ = concat!("hello", " world");
let _ = concat!("hello", " world",);
}
#[test]
fn concat_idents() {
fn foo() {}
fn foobar() {}
concat_idents!(foo)();
concat_idents!(foo,)();
concat_idents!(foo, bar)();
concat_idents!(foo, bar,)();
}
#[test]
fn debug_assert() {
debug_assert!(true);
debug_assert!(true, );
debug_assert!(true, "hello");
debug_assert!(true, "hello",);
debug_assert!(true, "hello {}", "world");
debug_assert!(true, "hello {}", "world",);
}
#[test]
fn debug_assert_eq() {
debug_assert_eq!(1, 1);
debug_assert_eq!(1, 1,);
debug_assert_eq!(1, 1, "hello");
debug_assert_eq!(1, 1, "hello",);
debug_assert_eq!(1, 1, "hello {}", "world");
debug_assert_eq!(1, 1, "hello {}", "world",);
}
#[test]
fn debug_assert_ne() {
debug_assert_ne!(1, 2);
debug_assert_ne!(1, 2,);
debug_assert_ne!(1, 2, "hello");
debug_assert_ne!(1, 2, "hello",);
debug_assert_ne!(1, 2, "hello {}", "world");
debug_assert_ne!(1, 2, "hello {}", "world",);
}
#[test]
fn env() {
let _ = env!("PATH");
let _ = env!("PATH",);
let _ = env!("PATH", "not found");
let _ = env!("PATH", "not found",);
}
#[cfg(std)]
#[test]
fn eprint() {
eprint!("hello");
eprint!("hello",);
eprint!("hello {}", "world");
eprint!("hello {}", "world",);
}
#[cfg(std)]
#[test]
fn eprintln() {
eprintln!();
eprintln!("hello");
eprintln!("hello",);
eprintln!("hello {}", "world");
eprintln!("hello {}", "world",);
}
#[test]
fn file() {
let _ = file!();
}
#[cfg(std)]
#[test]
fn format() {
let _ = format!("hello");
let _ = format!("hello",);
let _ = format!("hello {}", "world");
let _ = format!("hello {}", "world",);
}
#[test]
fn format_args() {
let _ = format_args!("hello");
let _ = format_args!("hello",);
let _ = format_args!("hello {}", "world");
let _ = format_args!("hello {}", "world",);
}
#[test]
fn include() {
let _ = include!("auxiliary/macro-comma-support.rs");
let _ = include!("auxiliary/macro-comma-support.rs",);
}
#[test]
fn include_bytes() {
let _ = include_bytes!("auxiliary/macro-comma-support.rs");
let _ = include_bytes!("auxiliary/macro-comma-support.rs",);
}
#[test]
fn include_str() {
let _ = include_str!("auxiliary/macro-comma-support.rs");
let _ = include_str!("auxiliary/macro-comma-support.rs",);
}
#[test]
fn line() {
let _ = line!();
}
#[test]
fn module_path() {
let _ = module_path!();
}
#[test]
fn option_env() {
let _ = option_env!("PATH");
let _ = option_env!("PATH",);
}
#[test]
fn panic() {
// prevent 'unreachable code' warnings
let falsum = || false;
if falsum() { panic!(); }
if falsum() { panic!("hello"); }
if falsum() { panic!("hello",); }
if falsum() { panic!("hello {}", "world"); }
if falsum() { panic!("hello {}", "world",); }
}
#[cfg(std)]
#[test]
fn print() {
print!("hello");
print!("hello",);
print!("hello {}", "world");
print!("hello {}", "world",);
}
#[cfg(std)]
#[test]
fn println() {
println!();
println!("hello");
println!("hello",);
println!("hello {}", "world");
println!("hello {}", "world",);
}
// stringify! is N/A
#[cfg(std)]
#[test]
fn thread_local() {
// this has an optional trailing *semicolon*
thread_local! {
#[allow(unused)] pub static A: () = ()
}
thread_local! {
#[allow(unused)] pub static AA: () = ();
}
thread_local! {
#[allow(unused)] pub static AAA: () = ();
#[allow(unused)] pub static AAAA: () = ()
}
thread_local! {
#[allow(unused)] pub static AAAAG: () = ();
#[allow(unused)] pub static AAAAGH: () = ();
}
}
#[test]
fn try() {
fn inner() -> Result<(), ()> {
try!(Ok(()));
try!(Ok(()),);
Ok(())
}
inner().unwrap();
}
#[test]
fn unimplemented() {
// prevent 'unreachable code' warnings
let falsum = || false;
if falsum() { unimplemented!(); }
if falsum() { unimplemented!("hello"); }
if falsum() { unimplemented!("hello",); }
if falsum() { unimplemented!("hello {}", "world"); }
if falsum() { unimplemented!("hello {}", "world",); }
}
#[test]
fn unreachable() {
// prevent 'unreachable code' warnings
let falsum = || false;
if falsum() { unreachable!(); }
if falsum() { unreachable!("hello"); }
if falsum() { unreachable!("hello",); }
if falsum() { unreachable!("hello {}", "world"); }
if falsum() { unreachable!("hello {}", "world",); }
}
#[cfg(std)]
#[test]
fn vec() {
let _: Vec<()> = vec![];
let _ = vec![0];
let _ = vec![0,];
let _ = vec![0, 1];
let _ = vec![0, 1,];
}
// give a test body access to a fmt::Formatter, which seems
// to be the easiest way to use 'write!' on core.
macro_rules! test_with_formatter {
(
#[test]
fn $fname:ident($f:ident: &mut fmt::Formatter) $block:block
) => {
#[test]
fn $fname() {
struct Struct;
impl fmt::Display for Struct {
fn fmt(&self, $f: &mut fmt::Formatter) -> fmt::Result {
Ok($block)
}
}
// suppress "unused"
assert!(true, "{}", Struct);
}
};
}
test_with_formatter! {
#[test]
fn write(f: &mut fmt::Formatter) {
let _ = write!(f, "hello");
let _ = write!(f, "hello",);
let _ = write!(f, "hello {}", "world");
let _ = write!(f, "hello {}", "world",);
}
}
test_with_formatter! {
#[test]
fn writeln(f: &mut fmt::Formatter) {
let _ = writeln!(f);
let _ = writeln!(f,);
let _ = writeln!(f, "hello");
let _ = writeln!(f, "hello",);
let _ = writeln!(f, "hello {}", "world");
let _ = writeln!(f, "hello {}", "world",);
}
}