]> git.lizzy.rs Git - rust.git/blob - src/test/ui/atomic-print.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / atomic-print.rs
1 // run-pass
2
3 #![allow(unused_must_use)]
4 #![allow(deprecated)]
5 // ignore-emscripten no threads support
6 // ignore-sgx no processes
7
8 use std::{env, fmt, process, sync, thread};
9
10 struct SlowFmt(u32);
11 impl fmt::Debug for SlowFmt {
12     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13         thread::sleep_ms(3);
14         self.0.fmt(f)
15     }
16 }
17
18 fn do_print(x: u32) {
19     let x = SlowFmt(x);
20     println!("{:?}{:?}{:?}{:?}{:?}", x, x, x, x, x);
21 }
22
23 fn main(){
24     if env::args().count() == 2 {
25         let barrier = sync::Arc::new(sync::Barrier::new(2));
26         let tbarrier = barrier.clone();
27         let t = thread::spawn(move || {
28             tbarrier.wait();
29             do_print(1);
30         });
31         barrier.wait();
32         do_print(2);
33         t.join();
34     } else {
35         let this = env::args().next().unwrap();
36         let output = process::Command::new(this).arg("-").output().unwrap();
37         for line in String::from_utf8(output.stdout).unwrap().lines() {
38             match line.chars().next().unwrap() {
39                 '1' => assert_eq!(line, "11111"),
40                 '2' => assert_eq!(line, "22222"),
41                 chr => panic!("unexpected character {:?}", chr)
42             }
43         }
44     }
45 }