2 use std
::io
::prelude
::*;
3 use std
::io
::BufReader
;
4 use std
::process
::{Command, Stdio}
;
14 Err(e
) => panic
!("{} failed with {}", stringify
!($e
), e
),
20 if env
::var("I_AM_THE_CLIENT").is_ok() {
28 let me
= t
!(env
::current_exe());
29 let client
= t
!(Client
::new(1));
30 let mut cmd
= Command
::new(me
);
31 cmd
.env("I_AM_THE_CLIENT", "1").stdout(Stdio
::piped());
32 client
.configure(&mut cmd
);
33 let acq
= client
.acquire().unwrap();
34 let mut child
= t
!(cmd
.spawn());
35 let stdout
= child
.stdout
.take().unwrap();
36 let (tx
, rx
) = mpsc
::channel();
37 let t
= thread
::spawn(move || {
38 for line
in BufReader
::new(stdout
).lines() {
39 tx
.send(t
!(line
)).unwrap();
44 assert
!(rx
.try_recv().is_err());
48 assert_eq
!(rx
.recv().unwrap(), "hello!");
50 assert
!(rx
.recv().is_err());
51 client
.acquire().unwrap();
55 let client
= unsafe { Client::from_env().unwrap() }
;
56 let acq
= client
.acquire().unwrap();