]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/atomic-print.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / test / run-pass / atomic-print.rs
CommitLineData
9346a6ac
AL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11use std::{env, fmt, process, sync, thread};
12
13struct SlowFmt(u32);
14impl fmt::Debug for SlowFmt {
15 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
16 thread::sleep_ms(3);
17 self.0.fmt(f)
18 }
19}
20
21fn do_print(x: u32) {
22 let x = SlowFmt(x);
23 println!("{:?}{:?}{:?}{:?}{:?}", x, x, x, x, x);
24}
25
26fn main(){
27 if env::args().count() == 2 {
28 let barrier = sync::Arc::new(sync::Barrier::new(2));
29 let tbarrier = barrier.clone();
30 let t = thread::spawn(move || {
31 tbarrier.wait();
32 do_print(1);
33 });
34 barrier.wait();
35 do_print(2);
36 t.join();
37 } else {
38 let this = env::args().next().unwrap();
39 let output = process::Command::new(this).arg("-").output().unwrap();
40 for line in String::from_utf8(output.stdout).unwrap().lines() {
41 match line.chars().next().unwrap() {
42 '1' => assert_eq!(line, "11111"),
43 '2' => assert_eq!(line, "22222"),
92a42be0 44 chr => panic!("unexpected character {:?}", chr)
9346a6ac
AL
45 }
46 }
47 }
48}