Skip to content

Commit 88b0b51

Browse files
committed
auto merge of #9578 : alexcrichton/rust/un-ignore-libuv-process-tests, r=brson
Closes #9341
2 parents fe4e747 + 02cbfce commit 88b0b51

File tree

2 files changed

+158
-142
lines changed

2 files changed

+158
-142
lines changed

src/libstd/rt/io/process.rs

Lines changed: 2 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -140,145 +140,5 @@ impl Drop for Process {
140140
}
141141
}
142142

143-
#[cfg(test)]
144-
mod tests {
145-
use prelude::*;
146-
use super::*;
147-
148-
use rt::io::{Reader, Writer};
149-
use rt::io::pipe::*;
150-
use str;
151-
152-
#[test]
153-
#[cfg(unix, not(android))]
154-
#[ignore] // FIXME(#9341)
155-
fn smoke() {
156-
let io = ~[];
157-
let args = ProcessConfig {
158-
program: "/bin/sh",
159-
args: [~"-c", ~"true"],
160-
env: None,
161-
cwd: None,
162-
io: io,
163-
};
164-
let p = Process::new(args);
165-
assert!(p.is_some());
166-
let mut p = p.unwrap();
167-
assert_eq!(p.wait(), 0);
168-
}
169-
170-
#[test]
171-
#[cfg(unix, not(android))]
172-
#[ignore] // FIXME(#9341)
173-
fn smoke_failure() {
174-
let io = ~[];
175-
let args = ProcessConfig {
176-
program: "if-this-is-a-binary-then-the-world-has-ended",
177-
args: [],
178-
env: None,
179-
cwd: None,
180-
io: io,
181-
};
182-
let p = Process::new(args);
183-
assert!(p.is_some());
184-
let mut p = p.unwrap();
185-
assert!(p.wait() != 0);
186-
}
187-
188-
#[test]
189-
#[cfg(unix, not(android))]
190-
#[ignore] // FIXME(#9341)
191-
fn exit_reported_right() {
192-
let io = ~[];
193-
let args = ProcessConfig {
194-
program: "/bin/sh",
195-
args: [~"-c", ~"exit 1"],
196-
env: None,
197-
cwd: None,
198-
io: io,
199-
};
200-
let p = Process::new(args);
201-
assert!(p.is_some());
202-
let mut p = p.unwrap();
203-
assert_eq!(p.wait(), 1);
204-
}
205-
206-
fn read_all(input: &mut Reader) -> ~str {
207-
let mut ret = ~"";
208-
let mut buf = [0, ..1024];
209-
loop {
210-
match input.read(buf) {
211-
None | Some(0) => { break }
212-
Some(n) => { ret = ret + str::from_utf8(buf.slice_to(n)); }
213-
}
214-
}
215-
return ret;
216-
}
217-
218-
fn run_output(args: ProcessConfig) -> ~str {
219-
let p = Process::new(args);
220-
assert!(p.is_some());
221-
let mut p = p.unwrap();
222-
assert!(p.io[0].is_none());
223-
assert!(p.io[1].is_some());
224-
let ret = read_all(p.io[1].get_mut_ref() as &mut Reader);
225-
assert_eq!(p.wait(), 0);
226-
return ret;
227-
}
228-
229-
#[test]
230-
#[cfg(unix, not(android))]
231-
#[ignore] // FIXME(#9341)
232-
fn stdout_works() {
233-
let pipe = PipeStream::new().unwrap();
234-
let io = ~[Ignored, CreatePipe(pipe, false, true)];
235-
let args = ProcessConfig {
236-
program: "/bin/sh",
237-
args: [~"-c", ~"echo foobar"],
238-
env: None,
239-
cwd: None,
240-
io: io,
241-
};
242-
assert_eq!(run_output(args), ~"foobar\n");
243-
}
244-
245-
#[test]
246-
#[cfg(unix, not(android))]
247-
#[ignore] // FIXME(#9341)
248-
fn set_cwd_works() {
249-
let pipe = PipeStream::new().unwrap();
250-
let io = ~[Ignored, CreatePipe(pipe, false, true)];
251-
let cwd = Some("/");
252-
let args = ProcessConfig {
253-
program: "/bin/sh",
254-
args: [~"-c", ~"pwd"],
255-
env: None,
256-
cwd: cwd,
257-
io: io,
258-
};
259-
assert_eq!(run_output(args), ~"/\n");
260-
}
261-
262-
#[test]
263-
#[cfg(unix, not(android))]
264-
#[ignore] // FIXME(#9341)
265-
fn stdin_works() {
266-
let input = PipeStream::new().unwrap();
267-
let output = PipeStream::new().unwrap();
268-
let io = ~[CreatePipe(input, true, false),
269-
CreatePipe(output, false, true)];
270-
let args = ProcessConfig {
271-
program: "/bin/sh",
272-
args: [~"-c", ~"read line; echo $line"],
273-
env: None,
274-
cwd: None,
275-
io: io,
276-
};
277-
let mut p = Process::new(args).expect("didn't create a proces?!");
278-
p.io[0].get_mut_ref().write("foobar".as_bytes());
279-
p.io[0] = None; // close stdin;
280-
let out = read_all(p.io[1].get_mut_ref() as &mut Reader);
281-
assert_eq!(p.wait(), 0);
282-
assert_eq!(out, ~"foobar\n");
283-
}
284-
}
143+
// Tests for this module can be found in the rtio-processes run-pass test, along
144+
// with the justification for why it's not located here.

src/test/run-pass/rtio-processes.rs

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2013 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+
11+
// compile-flags: --test
12+
// xfail-fast
13+
14+
// In the current state of affairs, libuv registers a SIGCHLD handler when a
15+
// process is spawned through it. This is not done with a SA_RESTART flag,
16+
// meaning that all of our syscalls run the risk of returning EINTR. This error
17+
// is not correctly handled in the majority of std::io, so these can't run with
18+
// the main body of tests there.
19+
//
20+
// That being said, libuv correctly handles EINTR completely, so these tests
21+
// themselves are safe against that. Currently the test runner may run into this
22+
// problem, but it's less likely than a whole suite of tests...
23+
//
24+
// See #9341
25+
26+
use std::rt::io::process::*;
27+
use std::rt::io::{Reader, Writer};
28+
use std::rt::io::pipe::*;
29+
use std::str;
30+
31+
#[test]
32+
#[cfg(unix, not(android))]
33+
fn smoke() {
34+
let io = ~[];
35+
let args = ProcessConfig {
36+
program: "/bin/sh",
37+
args: [~"-c", ~"true"],
38+
env: None,
39+
cwd: None,
40+
io: io,
41+
};
42+
let p = Process::new(args);
43+
assert!(p.is_some());
44+
let mut p = p.unwrap();
45+
assert_eq!(p.wait(), 0);
46+
}
47+
48+
#[test]
49+
#[cfg(unix, not(android))]
50+
fn smoke_failure() {
51+
let io = ~[];
52+
let args = ProcessConfig {
53+
program: "if-this-is-a-binary-then-the-world-has-ended",
54+
args: [],
55+
env: None,
56+
cwd: None,
57+
io: io,
58+
};
59+
let p = Process::new(args);
60+
assert!(p.is_some());
61+
let mut p = p.unwrap();
62+
assert!(p.wait() != 0);
63+
}
64+
65+
#[test]
66+
#[cfg(unix, not(android))]
67+
fn exit_reported_right() {
68+
let io = ~[];
69+
let args = ProcessConfig {
70+
program: "/bin/sh",
71+
args: [~"-c", ~"exit 1"],
72+
env: None,
73+
cwd: None,
74+
io: io,
75+
};
76+
let p = Process::new(args);
77+
assert!(p.is_some());
78+
let mut p = p.unwrap();
79+
assert_eq!(p.wait(), 1);
80+
}
81+
82+
fn read_all(input: &mut Reader) -> ~str {
83+
let mut ret = ~"";
84+
let mut buf = [0, ..1024];
85+
loop {
86+
match input.read(buf) {
87+
None | Some(0) => { break }
88+
Some(n) => { ret = ret + str::from_utf8(buf.slice_to(n)); }
89+
}
90+
}
91+
return ret;
92+
}
93+
94+
fn run_output(args: ProcessConfig) -> ~str {
95+
let p = Process::new(args);
96+
assert!(p.is_some());
97+
let mut p = p.unwrap();
98+
assert!(p.io[0].is_none());
99+
assert!(p.io[1].is_some());
100+
let ret = read_all(p.io[1].get_mut_ref() as &mut Reader);
101+
assert_eq!(p.wait(), 0);
102+
return ret;
103+
}
104+
105+
#[test]
106+
#[cfg(unix, not(android))]
107+
fn stdout_works() {
108+
let pipe = PipeStream::new().unwrap();
109+
let io = ~[Ignored, CreatePipe(pipe, false, true)];
110+
let args = ProcessConfig {
111+
program: "/bin/sh",
112+
args: [~"-c", ~"echo foobar"],
113+
env: None,
114+
cwd: None,
115+
io: io,
116+
};
117+
assert_eq!(run_output(args), ~"foobar\n");
118+
}
119+
120+
#[test]
121+
#[cfg(unix, not(android))]
122+
fn set_cwd_works() {
123+
let pipe = PipeStream::new().unwrap();
124+
let io = ~[Ignored, CreatePipe(pipe, false, true)];
125+
let cwd = Some("/");
126+
let args = ProcessConfig {
127+
program: "/bin/sh",
128+
args: [~"-c", ~"pwd"],
129+
env: None,
130+
cwd: cwd,
131+
io: io,
132+
};
133+
assert_eq!(run_output(args), ~"/\n");
134+
}
135+
136+
#[test]
137+
#[cfg(unix, not(android))]
138+
fn stdin_works() {
139+
let input = PipeStream::new().unwrap();
140+
let output = PipeStream::new().unwrap();
141+
let io = ~[CreatePipe(input, true, false),
142+
CreatePipe(output, false, true)];
143+
let args = ProcessConfig {
144+
program: "/bin/sh",
145+
args: [~"-c", ~"read line; echo $line"],
146+
env: None,
147+
cwd: None,
148+
io: io,
149+
};
150+
let mut p = Process::new(args).expect("didn't create a proces?!");
151+
p.io[0].get_mut_ref().write("foobar".as_bytes());
152+
p.io[0] = None; // close stdin;
153+
let out = read_all(p.io[1].get_mut_ref() as &mut Reader);
154+
assert_eq!(p.wait(), 0);
155+
assert_eq!(out, ~"foobar\n");
156+
}

0 commit comments

Comments
 (0)