]> git.lizzy.rs Git - rust.git/blob - tests/ui/macros/macro-comma-support-rpass.rs
Rollup merge of #106973 - oli-obk:tait_ice_closure_in_impl_header, r=lcnr
[rust.git] / tests / ui / macros / macro-comma-support-rpass.rs
1 // run-pass
2 // This is meant to be a comprehensive test of invocations with/without
3 // trailing commas (or other, similar optionally-trailing separators).
4 // Every macro is accounted for, even those not tested in this file.
5 // (There will be a note indicating why).
6
7 // std and core are both tested because they may contain separate
8 // implementations for some macro_rules! macros as an implementation
9 // detail.
10
11 // ignore-pretty issue #37195
12
13 // compile-flags: --test -C debug_assertions=yes
14 // revisions: std core
15
16 #![cfg_attr(core, no_std)]
17
18 #![allow(deprecated)] // for deprecated `try!()` macro
19 #![feature(concat_idents)]
20
21 #[cfg(std)] use std::fmt;
22 #[cfg(core)] use core::fmt;
23
24 #[test]
25 fn assert() {
26     assert!(true);
27     assert!(true,);
28     assert!(true, "hello");
29     assert!(true, "hello",);
30     assert!(true, "hello {}", "world");
31     assert!(true, "hello {}", "world",);
32 }
33
34 #[test]
35 fn assert_eq() {
36     assert_eq!(1, 1);
37     assert_eq!(1, 1,);
38     assert_eq!(1, 1, "hello");
39     assert_eq!(1, 1, "hello",);
40     assert_eq!(1, 1, "hello {}", "world");
41     assert_eq!(1, 1, "hello {}", "world",);
42 }
43
44 #[test]
45 fn assert_ne() {
46     assert_ne!(1, 2);
47     assert_ne!(1, 2,);
48     assert_ne!(1, 2, "hello");
49     assert_ne!(1, 2, "hello",);
50     assert_ne!(1, 2, "hello {}", "world");
51     assert_ne!(1, 2, "hello {}", "world",);
52 }
53
54 #[test]
55 fn cfg() {
56     let _ = cfg!(pants);
57     let _ = cfg!(pants,);
58     let _ = cfg!(pants = "pants");
59     let _ = cfg!(pants = "pants",);
60     let _ = cfg!(all(pants));
61     let _ = cfg!(all(pants),);
62     let _ = cfg!(all(pants,));
63     let _ = cfg!(all(pants,),);
64 }
65
66 #[test]
67 fn column() {
68     let _ = column!();
69 }
70
71 // compile_error! is in a check-fail companion to this test
72
73 #[test]
74 fn concat() {
75     let _ = concat!();
76     let _ = concat!("hello");
77     let _ = concat!("hello",);
78     let _ = concat!("hello", " world");
79     let _ = concat!("hello", " world",);
80 }
81
82 #[test]
83 fn concat_idents() {
84     fn foo() {}
85     fn foobar() {}
86
87     concat_idents!(foo)();
88     concat_idents!(foo,)();
89     concat_idents!(foo, bar)();
90     concat_idents!(foo, bar,)();
91 }
92
93 #[test]
94 fn debug_assert() {
95     debug_assert!(true);
96     debug_assert!(true, );
97     debug_assert!(true, "hello");
98     debug_assert!(true, "hello",);
99     debug_assert!(true, "hello {}", "world");
100     debug_assert!(true, "hello {}", "world",);
101 }
102
103 #[test]
104 fn debug_assert_eq() {
105     debug_assert_eq!(1, 1);
106     debug_assert_eq!(1, 1,);
107     debug_assert_eq!(1, 1, "hello");
108     debug_assert_eq!(1, 1, "hello",);
109     debug_assert_eq!(1, 1, "hello {}", "world");
110     debug_assert_eq!(1, 1, "hello {}", "world",);
111 }
112
113 #[test]
114 fn debug_assert_ne() {
115     debug_assert_ne!(1, 2);
116     debug_assert_ne!(1, 2,);
117     debug_assert_ne!(1, 2, "hello");
118     debug_assert_ne!(1, 2, "hello",);
119     debug_assert_ne!(1, 2, "hello {}", "world");
120     debug_assert_ne!(1, 2, "hello {}", "world",);
121 }
122
123 #[test]
124 fn env() {
125     let _ = env!("PATH");
126     let _ = env!("PATH",);
127     let _ = env!("PATH", "not found");
128     let _ = env!("PATH", "not found",);
129 }
130
131 #[cfg(std)]
132 #[test]
133 fn eprint() {
134     eprint!("hello");
135     eprint!("hello",);
136     eprint!("hello {}", "world");
137     eprint!("hello {}", "world",);
138 }
139
140 #[cfg(std)]
141 #[test]
142 fn eprintln() {
143     eprintln!();
144     eprintln!("hello");
145     eprintln!("hello",);
146     eprintln!("hello {}", "world");
147     eprintln!("hello {}", "world",);
148 }
149
150 #[test]
151 fn file() {
152     let _ = file!();
153 }
154
155 #[cfg(std)]
156 #[test]
157 fn format() {
158     let _ = format!("hello");
159     let _ = format!("hello",);
160     let _ = format!("hello {}", "world");
161     let _ = format!("hello {}", "world",);
162 }
163
164 #[test]
165 fn format_args() {
166     let _ = format_args!("hello");
167     let _ = format_args!("hello",);
168     let _ = format_args!("hello {}", "world");
169     let _ = format_args!("hello {}", "world",);
170 }
171
172 #[test]
173 fn include() {
174     let _ = include!("auxiliary/macro-comma-support.rs");
175     let _ = include!("auxiliary/macro-comma-support.rs",);
176 }
177
178 #[test]
179 fn include_bytes() {
180     let _ = include_bytes!("auxiliary/macro-comma-support.rs");
181     let _ = include_bytes!("auxiliary/macro-comma-support.rs",);
182 }
183
184 #[test]
185 fn include_str() {
186     let _ = include_str!("auxiliary/macro-comma-support.rs");
187     let _ = include_str!("auxiliary/macro-comma-support.rs",);
188 }
189
190 #[test]
191 fn line() {
192     let _ = line!();
193 }
194
195 #[test]
196 fn matches() {
197     let _ = matches!(1, x if x > 0);
198     let _ = matches!(1, x if x > 0,);
199 }
200
201 #[test]
202 fn module_path() {
203     let _ = module_path!();
204 }
205
206 #[test]
207 fn option_env() {
208     let _ = option_env!("PATH");
209     let _ = option_env!("PATH",);
210 }
211
212 #[test]
213 fn panic() {
214     // prevent 'unreachable code' warnings
215     let falsum = || false;
216
217     if falsum() { panic!(); }
218     if falsum() { panic!("hello"); }
219     if falsum() { panic!("hello",); }
220     if falsum() { panic!("hello {}", "world"); }
221     if falsum() { panic!("hello {}", "world",); }
222 }
223
224 #[cfg(std)]
225 #[test]
226 fn print() {
227     print!("hello");
228     print!("hello",);
229     print!("hello {}", "world");
230     print!("hello {}", "world",);
231 }
232
233 #[cfg(std)]
234 #[test]
235 fn println() {
236     println!();
237     println!("hello");
238     println!("hello",);
239     println!("hello {}", "world");
240     println!("hello {}", "world",);
241 }
242
243 // stringify! is N/A
244
245 #[cfg(std)]
246 #[test]
247 fn thread_local() {
248     // this has an optional trailing *semicolon*
249     thread_local! {
250         #[allow(unused)] pub static A: () = ()
251     }
252
253     thread_local! {
254         #[allow(unused)] pub static AA: () = ();
255     }
256
257     thread_local! {
258         #[allow(unused)] pub static AAA: () = ();
259         #[allow(unused)] pub static AAAA: () = ()
260     }
261
262     thread_local! {
263         #[allow(unused)] pub static AAAAG: () = ();
264         #[allow(unused)] pub static AAAAGH: () = ();
265     }
266 }
267
268 #[test]
269 fn try() {
270     fn inner() -> Result<(), ()> {
271         try!(Ok(()));
272         try!(Ok(()),);
273         Ok(())
274     }
275
276     inner().unwrap();
277 }
278
279 #[test]
280 fn unimplemented() {
281     // prevent 'unreachable code' warnings
282     let falsum = || false;
283
284     if falsum() { unimplemented!(); }
285     if falsum() { unimplemented!("hello"); }
286     if falsum() { unimplemented!("hello",); }
287     if falsum() { unimplemented!("hello {}", "world"); }
288     if falsum() { unimplemented!("hello {}", "world",); }
289 }
290
291 #[test]
292 fn unreachable() {
293     // prevent 'unreachable code' warnings
294     let falsum = || false;
295
296     if falsum() { unreachable!(); }
297     if falsum() { unreachable!("hello"); }
298     if falsum() { unreachable!("hello",); }
299     if falsum() { unreachable!("hello {}", "world"); }
300     if falsum() { unreachable!("hello {}", "world",); }
301 }
302
303 #[cfg(std)]
304 #[test]
305 fn vec() {
306     let _: Vec<()> = vec![];
307     let _ = vec![0];
308     let _ = vec![0,];
309     let _ = vec![0, 1];
310     let _ = vec![0, 1,];
311 }
312
313 // give a test body access to a fmt::Formatter, which seems
314 // to be the easiest way to use 'write!' on core.
315 macro_rules! test_with_formatter {
316     (
317         #[test]
318         fn $fname:ident($f:ident: &mut fmt::Formatter) $block:block
319     ) => {
320         #[test]
321         fn $fname() {
322             struct Struct;
323             impl fmt::Display for Struct {
324                 fn fmt(&self, $f: &mut fmt::Formatter) -> fmt::Result {
325                     Ok($block)
326                 }
327             }
328
329             // suppress "unused"
330             assert!(true, "{}", Struct);
331         }
332     };
333 }
334
335 test_with_formatter! {
336     #[test]
337     fn write(f: &mut fmt::Formatter) {
338         let _ = write!(f, "hello");
339         let _ = write!(f, "hello",);
340         let _ = write!(f, "hello {}", "world");
341         let _ = write!(f, "hello {}", "world",);
342     }
343 }
344
345 test_with_formatter! {
346     #[test]
347     fn writeln(f: &mut fmt::Formatter) {
348         let _ = writeln!(f);
349         let _ = writeln!(f,);
350         let _ = writeln!(f, "hello");
351         let _ = writeln!(f, "hello",);
352         let _ = writeln!(f, "hello {}", "world");
353         let _ = writeln!(f, "hello {}", "world",);
354     }
355 }