blob: d3e88b13738f5ae27c827c366b6ed35f586c9878 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
use std;
import std::run;
import std::os;
import std::io;
import std::option;
import std::istr;
import std::vec;
// Regression test for memory leaks
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[test]
fn test_leaks() {
run::run_program(~"echo", []);
run::start_program(~"echo", []);
run::program_output(~"echo", []);
}
// FIXME
#[cfg(target_os = "win32")]
#[test]
#[ignore]
fn test_leaks() { }
#[test]
fn test_pipes() {
let pipe_in = os::pipe();
let pipe_out = os::pipe();
let pipe_err = os::pipe();
let pid =
run::spawn_process(~"cat", [],
pipe_in.in, pipe_out.out, pipe_err.out);
os::libc::close(pipe_in.in);
os::libc::close(pipe_out.out);
os::libc::close(pipe_err.out);
if pid == -1 { fail; }
let expected = ~"test";
writeclose(pipe_in.out, expected);
let actual = readclose(pipe_out.in);
readclose(pipe_err.in);
os::waitpid(pid);
log expected;
log actual;
assert (expected == actual);
fn writeclose(fd: int, s: &istr) {
let writer = io::new_writer(io::fd_buf_writer(fd, option::none));
writer.write_str(s);
os::libc::close(fd);
}
fn readclose(fd: int) -> istr {
// Copied from run::program_output
let file = os::fd_FILE(fd);
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
let buf = ~"";
while !reader.eof() {
let bytes = reader.read_bytes(4096u);
buf += istr::unsafe_from_bytes(bytes);
}
os::libc::fclose(file);
ret buf;
}
}
|