Skip to content

Commit 2237ac9

Browse files
committed
test: Fix fallout in run-pass tests
1 parent 51e2ce0 commit 2237ac9

36 files changed

+143
-722
lines changed

src/test/run-pass-valgrind/cleanup-stdin.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(old_io, io)]
12-
1311
fn main() {
14-
let _ = std::old_io::stdin();
1512
let _ = std::io::stdin();
13+
let _ = std::io::stdout();
14+
let _ = std::io::stderr();
1615
}

src/test/run-pass/backtrace.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
// no-pretty-expanded FIXME #15189
1212
// ignore-windows FIXME #13259
1313

14-
#![feature(unboxed_closures)]
15-
#![feature(unsafe_destructor, old_io, collections)]
16-
1714
use std::env;
18-
use std::old_io::process::Command;
15+
use std::process::{Command, Stdio};
1916
use std::str;
2017
use std::ops::{Drop, FnMut, FnOnce};
2118

@@ -40,44 +37,49 @@ fn double() {
4037
panic!("once");
4138
}
4239

43-
fn runtest(me: &str) {
44-
let mut template = Command::new(me);
45-
template.env("IS_TEST", "1");
40+
fn template(me: &str) -> Command {
41+
let mut m = Command::new(me);
42+
m.env("IS_TEST", "1")
43+
.stdout(Stdio::piped())
44+
.stderr(Stdio::piped());
45+
return m;
46+
}
4647

48+
fn runtest(me: &str) {
4749
// Make sure that the stack trace is printed
48-
let p = template.clone().arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
50+
let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
4951
let out = p.wait_with_output().unwrap();
5052
assert!(!out.status.success());
51-
let s = str::from_utf8(&out.error).unwrap();
53+
let s = str::from_utf8(&out.stderr).unwrap();
5254
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
5355
"bad output: {}", s);
5456

5557
// Make sure the stack trace is *not* printed
5658
// (Remove RUST_BACKTRACE from our own environment, in case developer
5759
// is running `make check` with it on.)
58-
let p = template.clone().arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
60+
let p = template(me).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
5961
let out = p.wait_with_output().unwrap();
6062
assert!(!out.status.success());
61-
let s = str::from_utf8(&out.error).unwrap();
63+
let s = str::from_utf8(&out.stderr).unwrap();
6264
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
6365
"bad output2: {}", s);
6466

6567
// Make sure a stack trace is printed
66-
let p = template.clone().arg("double-fail").spawn().unwrap();
68+
let p = template(me).arg("double-fail").spawn().unwrap();
6769
let out = p.wait_with_output().unwrap();
6870
assert!(!out.status.success());
69-
let s = str::from_utf8(&out.error).unwrap();
71+
let s = str::from_utf8(&out.stderr).unwrap();
7072
// loosened the following from double::h to double:: due to
7173
// spurious failures on mac, 32bit, optimized
7274
assert!(s.contains("stack backtrace") && s.contains("double::"),
7375
"bad output3: {}", s);
7476

7577
// Make sure a stack trace isn't printed too many times
76-
let p = template.clone().arg("double-fail")
78+
let p = template(me).arg("double-fail")
7779
.env("RUST_BACKTRACE", "1").spawn().unwrap();
7880
let out = p.wait_with_output().unwrap();
7981
assert!(!out.status.success());
80-
let s = str::from_utf8(&out.error).unwrap();
82+
let s = str::from_utf8(&out.stderr).unwrap();
8183
let mut i = 0;
8284
for _ in 0..2 {
8385
i += s[i + 10..].find("stack backtrace").unwrap() + 10;

src/test/run-pass/capturing-logging.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/test/run-pass/closure-reform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(unboxed_closures, old_io)]
1515

1616
use std::mem;
17-
use std::old_io::stdio::println;
1817

1918
fn call_it<F>(f: F)
2019
where F : FnOnce(String) -> String
@@ -62,7 +61,8 @@ pub fn main() {
6261

6362
// External functions
6463

65-
call_bare(println);
64+
fn foo(s: &str) {}
65+
call_bare(foo);
6666

67-
call_bare_again(println);
67+
call_bare_again(foo);
6868
}

src/test/run-pass/core-run-destroy.rs

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616
// instead of in std.
1717

1818
#![reexport_test_harness_main = "test_main"]
19-
#![feature(old_io, libc, std_misc)]
19+
#![feature(libc, std_misc)]
2020

2121
extern crate libc;
2222

23-
use std::old_io::{Process, Command, timer};
24-
use std::time::Duration;
23+
use std::process::{self, Command, Child, Output};
2524
use std::str;
2625
use std::sync::mpsc::channel;
2726
use std::thread;
27+
use std::time::Duration;
2828

29-
macro_rules! succeed { ($e:expr) => (
30-
match $e { Ok(..) => {}, Err(e) => panic!("panic: {}", e) }
31-
) }
29+
macro_rules! t {
30+
($e:expr) => (match $e { Ok(e) => e, Err(e) => panic!("error: {}", e) })
31+
}
3232

3333
fn test_destroy_once() {
3434
let mut p = sleeper();
35-
match p.signal_exit() {
35+
match p.kill() {
3636
Ok(()) => {}
3737
Err(e) => panic!("error: {}", e),
3838
}
3939
}
4040

4141
#[cfg(unix)]
42-
pub fn sleeper() -> Process {
42+
pub fn sleeper() -> Child {
4343
Command::new("sleep").arg("1000").spawn().unwrap()
4444
}
4545
#[cfg(windows)]
46-
pub fn sleeper() -> Process {
46+
pub fn sleeper() -> Child {
4747
// There's a `timeout` command on windows, but it doesn't like having
4848
// its output piped, so instead just ping ourselves a few times with
4949
// gaps in between so we're sure this process is alive for awhile
@@ -52,16 +52,12 @@ pub fn sleeper() -> Process {
5252

5353
fn test_destroy_twice() {
5454
let mut p = sleeper();
55-
succeed!(p.signal_exit()); // this shouldn't crash...
56-
let _ = p.signal_exit(); // ...and nor should this (and nor should the destructor)
55+
t!(p.kill()); // this shouldn't crash...
56+
let _ = p.kill(); // ...and nor should this (and nor should the destructor)
5757
}
5858

59-
pub fn test_destroy_actually_kills(force: bool) {
60-
use std::old_io::process::{Command, ProcessOutput, ExitStatus, ExitSignal};
61-
use std::old_io::timer;
62-
use libc;
63-
use std::str;
64-
59+
#[test]
60+
fn test_destroy_actually_kills() {
6561
#[cfg(all(unix,not(target_os="android")))]
6662
static BLOCK_COMMAND: &'static str = "cat";
6763

@@ -74,34 +70,16 @@ pub fn test_destroy_actually_kills(force: bool) {
7470
// this process will stay alive indefinitely trying to read from stdin
7571
let mut p = Command::new(BLOCK_COMMAND).spawn().unwrap();
7672

77-
assert!(p.signal(0).is_ok());
78-
79-
if force {
80-
p.signal_kill().unwrap();
81-
} else {
82-
p.signal_exit().unwrap();
83-
}
73+
p.kill().unwrap();
8474

8575
// Don't let this test time out, this should be quick
86-
let (tx, rx1) = channel();
87-
let mut t = timer::Timer::new().unwrap();
88-
let rx2 = t.oneshot(Duration::milliseconds(1000));
76+
let (tx, rx) = channel();
8977
thread::spawn(move|| {
90-
select! {
91-
_ = rx2.recv() => unsafe { libc::exit(1) },
92-
_ = rx1.recv() => {}
78+
thread::sleep_ms(1000);
79+
if rx.try_recv().is_err() {
80+
process::exit(1);
9381
}
9482
});
95-
match p.wait().unwrap() {
96-
ExitStatus(..) => panic!("expected a signal"),
97-
ExitSignal(..) => tx.send(()).unwrap(),
98-
}
99-
}
100-
101-
fn test_unforced_destroy_actually_kills() {
102-
test_destroy_actually_kills(false);
103-
}
104-
105-
fn test_forced_destroy_actually_kills() {
106-
test_destroy_actually_kills(true);
83+
assert!(p.wait().unwrap().code().is_none());
84+
tx.send(());
10785
}

src/test/run-pass/deriving-global.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![feature(rand, rustc_private)]
1212

1313
extern crate serialize;
14-
extern crate rand;
1514

1615
mod submod {
1716
// if any of these are implemented without global calls for any
@@ -20,21 +19,21 @@ mod submod {
2019
#[derive(PartialEq, PartialOrd, Eq, Ord,
2120
Hash,
2221
Clone,
23-
Debug, Rand,
22+
Debug,
2423
Encodable, Decodable)]
2524
enum A { A1(usize), A2(isize) }
2625

2726
#[derive(PartialEq, PartialOrd, Eq, Ord,
2827
Hash,
2928
Clone,
30-
Debug, Rand,
29+
Debug,
3130
Encodable, Decodable)]
3231
struct B { x: usize, y: isize }
3332

3433
#[derive(PartialEq, PartialOrd, Eq, Ord,
3534
Hash,
3635
Clone,
37-
Debug, Rand,
36+
Debug,
3837
Encodable, Decodable)]
3938
struct C(usize, isize);
4039

src/test/run-pass/deriving-rand.rs

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/test/run-pass/drop-flag-sanity-check.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
//
1818
// See also drop-flag-skip-sanity-check.rs.
1919

20-
#![feature(old_io)]
21-
2220
use std::env;
23-
use std::old_io::process::{Command, ExitSignal, ExitStatus};
21+
use std::process::Command;
2422

2523
fn main() {
2624
let args: Vec<String> = env::args().collect();

src/test/run-pass/drop-flag-skip-sanity-check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![feature(old_io)]
2121

2222
use std::env;
23-
use std::old_io::process::{Command, ExitSignal, ExitStatus};
23+
use std::process::Command;
2424

2525
fn main() {
2626
let args: Vec<String> = env::args().collect();

src/test/run-pass/issue-10626.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#![feature(old_io)]
1616

1717
use std::env;
18-
use std::old_io::process;
18+
use std::process::{Command, Stdio};
1919

2020
pub fn main () {
2121
let args: Vec<String> = env::args().collect();
@@ -29,7 +29,7 @@ pub fn main () {
2929
return;
3030
}
3131

32-
let mut p = process::Command::new(&args[0]);
33-
p.arg("child").stdout(process::Ignored).stderr(process::Ignored);
32+
let mut p = Command::new(&args[0]);
33+
p.arg("child").stdout(Stdio::null()).stderr(Stdio::null());
3434
println!("{:?}", p.spawn().unwrap().wait());
3535
}

0 commit comments

Comments
 (0)