test: Fix fallout in run-pass tests
This commit is contained in:
parent
84a89ed3ef
commit
adcd67272e
@ -8,9 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(old_io, io)]
|
||||
|
||||
fn main() {
|
||||
let _ = std::old_io::stdin();
|
||||
let _ = std::io::stdin();
|
||||
let _ = std::io::stdout();
|
||||
let _ = std::io::stderr();
|
||||
}
|
||||
|
@ -11,11 +11,8 @@
|
||||
// no-pretty-expanded FIXME #15189
|
||||
// ignore-windows FIXME #13259
|
||||
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unsafe_destructor, old_io, collections)]
|
||||
|
||||
use std::env;
|
||||
use std::old_io::process::Command;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::str;
|
||||
use std::ops::{Drop, FnMut, FnOnce};
|
||||
|
||||
@ -40,44 +37,49 @@ fn double() {
|
||||
panic!("once");
|
||||
}
|
||||
|
||||
fn runtest(me: &str) {
|
||||
let mut template = Command::new(me);
|
||||
template.env("IS_TEST", "1");
|
||||
fn template(me: &str) -> Command {
|
||||
let mut m = Command::new(me);
|
||||
m.env("IS_TEST", "1")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
return m;
|
||||
}
|
||||
|
||||
fn runtest(me: &str) {
|
||||
// Make sure that the stack trace is printed
|
||||
let p = template.clone().arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
|
||||
let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
|
||||
let out = p.wait_with_output().unwrap();
|
||||
assert!(!out.status.success());
|
||||
let s = str::from_utf8(&out.error).unwrap();
|
||||
let s = str::from_utf8(&out.stderr).unwrap();
|
||||
assert!(s.contains("stack backtrace") && s.contains("foo::h"),
|
||||
"bad output: {}", s);
|
||||
|
||||
// Make sure the stack trace is *not* printed
|
||||
// (Remove RUST_BACKTRACE from our own environment, in case developer
|
||||
// is running `make check` with it on.)
|
||||
let p = template.clone().arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
|
||||
let p = template(me).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
|
||||
let out = p.wait_with_output().unwrap();
|
||||
assert!(!out.status.success());
|
||||
let s = str::from_utf8(&out.error).unwrap();
|
||||
let s = str::from_utf8(&out.stderr).unwrap();
|
||||
assert!(!s.contains("stack backtrace") && !s.contains("foo::h"),
|
||||
"bad output2: {}", s);
|
||||
|
||||
// Make sure a stack trace is printed
|
||||
let p = template.clone().arg("double-fail").spawn().unwrap();
|
||||
let p = template(me).arg("double-fail").spawn().unwrap();
|
||||
let out = p.wait_with_output().unwrap();
|
||||
assert!(!out.status.success());
|
||||
let s = str::from_utf8(&out.error).unwrap();
|
||||
let s = str::from_utf8(&out.stderr).unwrap();
|
||||
// loosened the following from double::h to double:: due to
|
||||
// spurious failures on mac, 32bit, optimized
|
||||
assert!(s.contains("stack backtrace") && s.contains("double::"),
|
||||
"bad output3: {}", s);
|
||||
|
||||
// Make sure a stack trace isn't printed too many times
|
||||
let p = template.clone().arg("double-fail")
|
||||
let p = template(me).arg("double-fail")
|
||||
.env("RUST_BACKTRACE", "1").spawn().unwrap();
|
||||
let out = p.wait_with_output().unwrap();
|
||||
assert!(!out.status.success());
|
||||
let s = str::from_utf8(&out.error).unwrap();
|
||||
let s = str::from_utf8(&out.stderr).unwrap();
|
||||
let mut i = 0;
|
||||
for _ in 0..2 {
|
||||
i += s[i + 10..].find("stack backtrace").unwrap() + 10;
|
||||
|
@ -1,46 +0,0 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// exec-env:RUST_LOG=info
|
||||
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(box_syntax, old_io, rustc_private, std_misc)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use log::{set_logger, Logger, LogRecord};
|
||||
use std::sync::mpsc::channel;
|
||||
use std::fmt;
|
||||
use std::old_io::{ChanReader, ChanWriter, Reader, Writer};
|
||||
use std::thread;
|
||||
|
||||
struct MyWriter(ChanWriter);
|
||||
|
||||
impl Logger for MyWriter {
|
||||
fn log(&mut self, record: &LogRecord) {
|
||||
let MyWriter(ref mut inner) = *self;
|
||||
write!(inner, "{}", record.args);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
|
||||
let _t = thread::scoped(move|| {
|
||||
set_logger(box MyWriter(w) as Box<Logger+Send>);
|
||||
debug!("debug");
|
||||
info!("info");
|
||||
});
|
||||
let s = r.read_to_string().unwrap();
|
||||
assert!(s.contains("info"));
|
||||
assert!(!s.contains("debug"));
|
||||
}
|
@ -14,7 +14,6 @@
|
||||
#![feature(unboxed_closures, old_io)]
|
||||
|
||||
use std::mem;
|
||||
use std::old_io::stdio::println;
|
||||
|
||||
fn call_it<F>(f: F)
|
||||
where F : FnOnce(String) -> String
|
||||
@ -62,7 +61,8 @@ pub fn main() {
|
||||
|
||||
// External functions
|
||||
|
||||
call_bare(println);
|
||||
fn foo(s: &str) {}
|
||||
call_bare(foo);
|
||||
|
||||
call_bare_again(println);
|
||||
call_bare_again(foo);
|
||||
}
|
||||
|
@ -16,34 +16,34 @@
|
||||
// instead of in std.
|
||||
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
#![feature(old_io, libc, std_misc)]
|
||||
#![feature(libc, std_misc)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::old_io::{Process, Command, timer};
|
||||
use std::time::Duration;
|
||||
use std::process::{self, Command, Child, Output};
|
||||
use std::str;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
macro_rules! succeed { ($e:expr) => (
|
||||
match $e { Ok(..) => {}, Err(e) => panic!("panic: {}", e) }
|
||||
) }
|
||||
macro_rules! t {
|
||||
($e:expr) => (match $e { Ok(e) => e, Err(e) => panic!("error: {}", e) })
|
||||
}
|
||||
|
||||
fn test_destroy_once() {
|
||||
let mut p = sleeper();
|
||||
match p.signal_exit() {
|
||||
match p.kill() {
|
||||
Ok(()) => {}
|
||||
Err(e) => panic!("error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn sleeper() -> Process {
|
||||
pub fn sleeper() -> Child {
|
||||
Command::new("sleep").arg("1000").spawn().unwrap()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub fn sleeper() -> Process {
|
||||
pub fn sleeper() -> Child {
|
||||
// There's a `timeout` command on windows, but it doesn't like having
|
||||
// its output piped, so instead just ping ourselves a few times with
|
||||
// gaps in between so we're sure this process is alive for awhile
|
||||
@ -52,16 +52,12 @@ pub fn sleeper() -> Process {
|
||||
|
||||
fn test_destroy_twice() {
|
||||
let mut p = sleeper();
|
||||
succeed!(p.signal_exit()); // this shouldn't crash...
|
||||
let _ = p.signal_exit(); // ...and nor should this (and nor should the destructor)
|
||||
t!(p.kill()); // this shouldn't crash...
|
||||
let _ = p.kill(); // ...and nor should this (and nor should the destructor)
|
||||
}
|
||||
|
||||
pub fn test_destroy_actually_kills(force: bool) {
|
||||
use std::old_io::process::{Command, ProcessOutput, ExitStatus, ExitSignal};
|
||||
use std::old_io::timer;
|
||||
use libc;
|
||||
use std::str;
|
||||
|
||||
#[test]
|
||||
fn test_destroy_actually_kills() {
|
||||
#[cfg(all(unix,not(target_os="android")))]
|
||||
static BLOCK_COMMAND: &'static str = "cat";
|
||||
|
||||
@ -74,34 +70,16 @@ pub fn test_destroy_actually_kills(force: bool) {
|
||||
// this process will stay alive indefinitely trying to read from stdin
|
||||
let mut p = Command::new(BLOCK_COMMAND).spawn().unwrap();
|
||||
|
||||
assert!(p.signal(0).is_ok());
|
||||
|
||||
if force {
|
||||
p.signal_kill().unwrap();
|
||||
} else {
|
||||
p.signal_exit().unwrap();
|
||||
}
|
||||
p.kill().unwrap();
|
||||
|
||||
// Don't let this test time out, this should be quick
|
||||
let (tx, rx1) = channel();
|
||||
let mut t = timer::Timer::new().unwrap();
|
||||
let rx2 = t.oneshot(Duration::milliseconds(1000));
|
||||
let (tx, rx) = channel();
|
||||
thread::spawn(move|| {
|
||||
select! {
|
||||
_ = rx2.recv() => unsafe { libc::exit(1) },
|
||||
_ = rx1.recv() => {}
|
||||
thread::sleep_ms(1000);
|
||||
if rx.try_recv().is_err() {
|
||||
process::exit(1);
|
||||
}
|
||||
});
|
||||
match p.wait().unwrap() {
|
||||
ExitStatus(..) => panic!("expected a signal"),
|
||||
ExitSignal(..) => tx.send(()).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn test_unforced_destroy_actually_kills() {
|
||||
test_destroy_actually_kills(false);
|
||||
}
|
||||
|
||||
fn test_forced_destroy_actually_kills() {
|
||||
test_destroy_actually_kills(true);
|
||||
assert!(p.wait().unwrap().code().is_none());
|
||||
tx.send(());
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
#![feature(rand, rustc_private)]
|
||||
|
||||
extern crate serialize;
|
||||
extern crate rand;
|
||||
|
||||
mod submod {
|
||||
// if any of these are implemented without global calls for any
|
||||
@ -20,21 +19,21 @@ mod submod {
|
||||
#[derive(PartialEq, PartialOrd, Eq, Ord,
|
||||
Hash,
|
||||
Clone,
|
||||
Debug, Rand,
|
||||
Debug,
|
||||
Encodable, Decodable)]
|
||||
enum A { A1(usize), A2(isize) }
|
||||
|
||||
#[derive(PartialEq, PartialOrd, Eq, Ord,
|
||||
Hash,
|
||||
Clone,
|
||||
Debug, Rand,
|
||||
Debug,
|
||||
Encodable, Decodable)]
|
||||
struct B { x: usize, y: isize }
|
||||
|
||||
#[derive(PartialEq, PartialOrd, Eq, Ord,
|
||||
Hash,
|
||||
Clone,
|
||||
Debug, Rand,
|
||||
Debug,
|
||||
Encodable, Decodable)]
|
||||
struct C(usize, isize);
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(rand)]
|
||||
|
||||
use std::rand;
|
||||
|
||||
#[derive(Rand)]
|
||||
struct A;
|
||||
|
||||
#[derive(Rand)]
|
||||
struct B(isize, isize);
|
||||
|
||||
#[derive(Rand)]
|
||||
struct C {
|
||||
x: f64,
|
||||
y: (u8, u8)
|
||||
}
|
||||
|
||||
#[derive(Rand)]
|
||||
enum D {
|
||||
D0,
|
||||
D1(usize),
|
||||
D2 { x: (), y: () }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
// check there's no segfaults
|
||||
for _ in 0..20 {
|
||||
rand::random::<A>();
|
||||
rand::random::<B>();
|
||||
rand::random::<C>();
|
||||
rand::random::<D>();
|
||||
}
|
||||
}
|
@ -17,10 +17,8 @@
|
||||
//
|
||||
// See also drop-flag-skip-sanity-check.rs.
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::env;
|
||||
use std::old_io::process::{Command, ExitSignal, ExitStatus};
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
@ -20,7 +20,7 @@
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::env;
|
||||
use std::old_io::process::{Command, ExitSignal, ExitStatus};
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
@ -15,7 +15,7 @@
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::env;
|
||||
use std::old_io::process;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
pub fn main () {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
@ -29,7 +29,7 @@ pub fn main () {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut p = process::Command::new(&args[0]);
|
||||
p.arg("child").stdout(process::Ignored).stderr(process::Ignored);
|
||||
let mut p = Command::new(&args[0]);
|
||||
p.arg("child").stdout(Stdio::null()).stderr(Stdio::null());
|
||||
println!("{:?}", p.spawn().unwrap().wait());
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io, std_misc)]
|
||||
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
thread::spawn(move|| customtask()).join().ok().unwrap();
|
||||
}
|
||||
|
||||
fn customtask() {
|
||||
let mut timer = std::old_io::timer::Timer::new().unwrap();
|
||||
let periodic = timer.periodic(Duration::milliseconds(10));
|
||||
periodic.recv();
|
||||
}
|
@ -8,13 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io, std_misc)]
|
||||
|
||||
use std::old_io::timer;
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
timer::sleep(Duration::milliseconds(250));
|
||||
thread::sleep_ms(250);
|
||||
}
|
||||
|
@ -8,11 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io::Reader;
|
||||
pub trait Reader {}
|
||||
|
||||
enum Wrapper<'a> {
|
||||
WrapReader(&'a (Reader + 'a))
|
||||
|
@ -10,14 +10,15 @@
|
||||
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#![feature(fs, process, env, path, rand)]
|
||||
extern crate rustc_back;
|
||||
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::process;
|
||||
use std::rand::random;
|
||||
use std::str;
|
||||
use rustc_back::tempdir::TempDir;
|
||||
|
||||
fn main() {
|
||||
// If we're the child, make sure we were invoked correctly
|
||||
@ -27,7 +28,8 @@ fn main() {
|
||||
// checking that it ends_with the executable name. This
|
||||
// is needed because of Windows, which has a different behavior.
|
||||
// See #15149 for more info.
|
||||
return assert!(args[0].ends_with(&format!("mytest{}", env::consts::EXE_SUFFIX)));
|
||||
return assert!(args[0].ends_with(&format!("mytest{}",
|
||||
env::consts::EXE_SUFFIX)));
|
||||
}
|
||||
|
||||
test();
|
||||
@ -38,9 +40,8 @@ fn test() {
|
||||
let my_path = env::current_exe().unwrap();
|
||||
let my_dir = my_path.parent().unwrap();
|
||||
|
||||
let random_u32: u32 = random();
|
||||
let child_dir = my_dir.join(&format!("issue-15149-child-{}", random_u32));
|
||||
fs::create_dir(&child_dir).unwrap();
|
||||
let child_dir = TempDir::new_in(&my_dir, "issue-15140-child").unwrap();
|
||||
let child_dir = child_dir.path();
|
||||
|
||||
let child_path = child_dir.join(&format!("mytest{}",
|
||||
env::consts::EXE_SUFFIX));
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io::FileType;
|
||||
|
||||
pub fn main() {
|
||||
let _ = FileType::RegularFile.clone();
|
||||
}
|
@ -11,10 +11,8 @@
|
||||
|
||||
// Map representation
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io;
|
||||
use std::fmt;
|
||||
use std::io::prelude::*;
|
||||
use square::{bot, wall, rock, lambda, closed_lift, open_lift, earth, empty};
|
||||
|
||||
enum square {
|
||||
@ -60,9 +58,9 @@ fn square_from_char(c: char) -> square {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_board_grid<rdr:'static + old_io::Reader>(mut input: rdr)
|
||||
fn read_board_grid<rdr:'static + Read>(mut input: rdr)
|
||||
-> Vec<Vec<square>> {
|
||||
let mut input: &mut old_io::Reader = &mut input;
|
||||
let mut input: &mut Read = &mut input;
|
||||
let mut grid = Vec::new();
|
||||
let mut line = [0; 10];
|
||||
input.read(&mut line);
|
||||
|
@ -10,24 +10,17 @@
|
||||
|
||||
// rustc --test ignores2.rs && ./ignores2
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(unboxed_closures, old_path, std_misc)]
|
||||
pub struct Path;
|
||||
|
||||
use std::old_path::Path;
|
||||
use std::old_path;
|
||||
use std::result;
|
||||
use std::thunk::Thunk;
|
||||
|
||||
type rsrc_loader = Box<FnMut(&Path) -> (result::Result<String, String>) + 'static>;
|
||||
type rsrc_loader = Box<FnMut(&Path) -> Result<String, String>>;
|
||||
|
||||
fn tester()
|
||||
{
|
||||
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
|
||||
let mut loader: rsrc_loader = Box::new(move|_path| {
|
||||
result::Result::Ok("more blah".to_string())
|
||||
let mut loader: rsrc_loader = Box::new(move |_path| {
|
||||
Ok("more blah".to_string())
|
||||
});
|
||||
|
||||
let path = old_path::Path::new("blah");
|
||||
let path = Path;
|
||||
assert!(loader(&path).is_ok());
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,6 @@
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io::println;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
@ -22,6 +19,6 @@ pub fn main() {
|
||||
tx.send("hello, world").unwrap();
|
||||
|
||||
thread::spawn(move|| {
|
||||
println(rx.recv().unwrap());
|
||||
println!("{}", rx.recv().unwrap());
|
||||
}).join().ok().unwrap();
|
||||
}
|
||||
|
@ -10,9 +10,6 @@
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io;
|
||||
trait B {
|
||||
fn f(&self);
|
||||
}
|
||||
@ -23,7 +20,7 @@ trait T : B {
|
||||
struct A;
|
||||
|
||||
impl<U: T> B for U {
|
||||
fn f(&self) { old_io::println("Hey, I'm a T!"); }
|
||||
fn f(&self) { }
|
||||
}
|
||||
|
||||
impl T for A {
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io, io)]
|
||||
pub trait Writer {
|
||||
fn write(&mut self, b: &[u8]) -> Result<(), ()>;
|
||||
}
|
||||
|
||||
use std::old_io;
|
||||
|
||||
fn foo(a: &mut old_io::Writer) {
|
||||
fn foo(a: &mut Writer) {
|
||||
a.write(&[]).unwrap();
|
||||
}
|
||||
|
||||
|
@ -10,18 +10,13 @@
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(old_io, std_misc)]
|
||||
|
||||
use std::sync::mpsc::{TryRecvError, channel};
|
||||
use std::old_io::timer::Timer;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let _t = thread::scoped(move||{
|
||||
let mut timer = Timer::new().unwrap();
|
||||
timer.sleep(Duration::milliseconds(10));
|
||||
thread::sleep_ms(10);
|
||||
tx.send(()).unwrap();
|
||||
});
|
||||
loop {
|
||||
|
@ -17,7 +17,7 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::old_io::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
use std::str;
|
||||
|
||||
@ -31,9 +31,9 @@ fn main() {
|
||||
|
||||
let p = Command::new(&args[0])
|
||||
.arg("child")
|
||||
.spawn().unwrap().wait_with_output().unwrap();
|
||||
.output().unwrap();
|
||||
assert!(p.status.success());
|
||||
let mut lines = str::from_utf8(&p.error).unwrap().lines();
|
||||
let mut lines = str::from_utf8(&p.stderr).unwrap().lines();
|
||||
assert!(lines.next().unwrap().contains("foo"));
|
||||
assert!(lines.next().unwrap().contains("bar"));
|
||||
}
|
||||
|
@ -17,7 +17,8 @@
|
||||
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
use std::old_io::IoResult;
|
||||
|
||||
pub type IoResult<T> = Result<T, ()>;
|
||||
|
||||
trait MyWriter {
|
||||
fn my_write(&mut self, buf: &[u8]) -> IoResult<()>;
|
||||
|
@ -14,9 +14,9 @@
|
||||
//ignore-dragonfly
|
||||
//ignore-bitrig
|
||||
|
||||
#![feature(asm, old_io, std_misc)]
|
||||
#![feature(asm)]
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
use std::thread;
|
||||
|
||||
@ -41,7 +41,7 @@ fn main() {
|
||||
} else {
|
||||
let recurse = Command::new(&args[0]).arg("recurse").output().unwrap();
|
||||
assert!(!recurse.status.success());
|
||||
let error = String::from_utf8_lossy(&recurse.error);
|
||||
let error = String::from_utf8_lossy(&recurse.stderr);
|
||||
println!("wut");
|
||||
println!("`{}`", error);
|
||||
assert!(error.contains("has overflowed its stack"));
|
||||
|
@ -8,16 +8,16 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//ignore-android
|
||||
//ignore-linux
|
||||
//ignore-freebsd
|
||||
//ignore-ios
|
||||
//ignore-dragonfly
|
||||
//ignore-bitrig
|
||||
// ignore-android
|
||||
// ignore-linux
|
||||
// ignore-freebsd
|
||||
// ignore-ios
|
||||
// ignore-dragonfly
|
||||
// ignore-bitrig
|
||||
|
||||
#![feature(asm, old_io)]
|
||||
#![feature(asm)]
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
// lifted from the test module
|
||||
@ -41,7 +41,7 @@ fn main() {
|
||||
} else {
|
||||
let recurse = Command::new(&args[0]).arg("recurse").output().unwrap();
|
||||
assert!(!recurse.status.success());
|
||||
let error = String::from_utf8_lossy(&recurse.error);
|
||||
let error = String::from_utf8_lossy(&recurse.stderr);
|
||||
assert!(error.contains("has overflowed its stack"));
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
// ignore-android: FIXME (#20004)
|
||||
|
||||
#![feature(asm, old_io)]
|
||||
#![feature(asm)]
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
// lifted from the test module
|
||||
@ -42,12 +42,12 @@ fn main() {
|
||||
} else {
|
||||
let silent = Command::new(&args[0]).arg("silent").output().unwrap();
|
||||
assert!(!silent.status.success());
|
||||
let error = String::from_utf8_lossy(&silent.error);
|
||||
let error = String::from_utf8_lossy(&silent.stderr);
|
||||
assert!(error.contains("has overflowed its stack"));
|
||||
|
||||
let loud = Command::new(&args[0]).arg("loud").output().unwrap();
|
||||
assert!(!loud.status.success());
|
||||
let error = String::from_utf8_lossy(&silent.error);
|
||||
let error = String::from_utf8_lossy(&silent.stderr);
|
||||
assert!(error.contains("has overflowed its stack"));
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
#[cfg(all(unix, not(target_os="android")))]
|
||||
@ -49,7 +47,7 @@ fn main() {
|
||||
|
||||
let prog = cmd.spawn().unwrap();
|
||||
let result = prog.wait_with_output().unwrap();
|
||||
let output = String::from_utf8_lossy(&result.output);
|
||||
let output = String::from_utf8_lossy(&result.stdout);
|
||||
|
||||
assert!(!output.contains("RUN_TEST_NEW_ENV"),
|
||||
"found RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#![feature(start, os, std_misc, old_io)]
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::old_io::process::{Command, ProcessOutput};
|
||||
use std::process::{Command, Output};
|
||||
use std::os;
|
||||
use std::rt::unwind::try;
|
||||
use std::rt;
|
||||
@ -23,12 +23,12 @@ use std::thunk::Thunk;
|
||||
fn start(argc: isize, argv: *const *const u8) -> isize {
|
||||
if argc > 1 {
|
||||
unsafe {
|
||||
match **argv.offset(1) {
|
||||
1 => {}
|
||||
2 => println!("foo"),
|
||||
3 => assert!(try(|| {}).is_ok()),
|
||||
4 => assert!(try(|| panic!()).is_err()),
|
||||
5 => assert!(Command::new("test").spawn().is_err()),
|
||||
match **argv.offset(1) as char {
|
||||
'1' => {}
|
||||
'2' => println!("foo"),
|
||||
'3' => assert!(try(|| {}).is_ok()),
|
||||
'4' => assert!(try(|| panic!()).is_err()),
|
||||
'5' => assert!(Command::new("test").spawn().is_err()),
|
||||
_ => panic!()
|
||||
}
|
||||
}
|
||||
@ -41,25 +41,20 @@ fn start(argc: isize, argv: *const *const u8) -> isize {
|
||||
CStr::from_ptr(ptr).to_bytes().to_vec()
|
||||
}).collect::<Vec<_>>()
|
||||
};
|
||||
let me = &*args[0];
|
||||
let me = String::from_utf8(args[0].to_vec()).unwrap();
|
||||
|
||||
let x: &[u8] = &[1];
|
||||
pass(Command::new(me).arg(x).output().unwrap());
|
||||
let x: &[u8] = &[2];
|
||||
pass(Command::new(me).arg(x).output().unwrap());
|
||||
let x: &[u8] = &[3];
|
||||
pass(Command::new(me).arg(x).output().unwrap());
|
||||
let x: &[u8] = &[4];
|
||||
pass(Command::new(me).arg(x).output().unwrap());
|
||||
let x: &[u8] = &[5];
|
||||
pass(Command::new(me).arg(x).output().unwrap());
|
||||
pass(Command::new(&me).arg("1").output().unwrap());
|
||||
pass(Command::new(&me).arg("2").output().unwrap());
|
||||
pass(Command::new(&me).arg("3").output().unwrap());
|
||||
pass(Command::new(&me).arg("4").output().unwrap());
|
||||
pass(Command::new(&me).arg("5").output().unwrap());
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn pass(output: ProcessOutput) {
|
||||
fn pass(output: Output) {
|
||||
if !output.status.success() {
|
||||
println!("{:?}", str::from_utf8(&output.output));
|
||||
println!("{:?}", str::from_utf8(&output.error));
|
||||
println!("{:?}", str::from_utf8(&output.stdout));
|
||||
println!("{:?}", str::from_utf8(&output.stderr));
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(old_io)]
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
@ -21,7 +19,7 @@ fn main() {
|
||||
} else {
|
||||
let segfault = Command::new(&args[0]).arg("segfault").output().unwrap();
|
||||
assert!(!segfault.status.success());
|
||||
let error = String::from_utf8_lossy(&segfault.error);
|
||||
let error = String::from_utf8_lossy(&segfault.stderr);
|
||||
assert!(!error.contains("has overflowed its stack"));
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,8 @@
|
||||
|
||||
// ignore-windows
|
||||
|
||||
#![feature(old_io)]
|
||||
#![feature(os)]
|
||||
|
||||
use std::env;
|
||||
use std::old_io::process::{Command, ExitSignal, ExitStatus};
|
||||
use std::process::Command;
|
||||
|
||||
pub fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
@ -23,11 +20,6 @@ pub fn main() {
|
||||
unsafe { *(0 as *mut isize) = 0; }
|
||||
} else {
|
||||
let status = Command::new(&args[0]).arg("signal").status().unwrap();
|
||||
// Windows does not have signal, so we get exit status 0xC0000028 (STATUS_BAD_STACK).
|
||||
match status {
|
||||
ExitSignal(_) if cfg!(unix) => {},
|
||||
ExitStatus(0xC0000028) if cfg!(windows) => {},
|
||||
_ => panic!("invalid termination (was not signalled): {}", status)
|
||||
}
|
||||
assert!(status.code().is_none());
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-macos osx really doesn't like cycling through large numbers of
|
||||
// sockets as calls to connect() will start returning EADDRNOTAVAIL
|
||||
// quite quickly and it takes a few seconds for the sockets to get
|
||||
// recycled.
|
||||
|
||||
#![feature(old_io, io, std_misc)]
|
||||
|
||||
use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile, TcpStream};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
static N: usize = 8;
|
||||
static M: usize = 20;
|
||||
|
||||
fn main() {
|
||||
test();
|
||||
}
|
||||
|
||||
fn test() {
|
||||
let mut l = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let addr = l.socket_name().unwrap();
|
||||
let mut a = l.listen().unwrap();
|
||||
let cnt = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
let (srv_tx, srv_rx) = channel();
|
||||
let (cli_tx, cli_rx) = channel();
|
||||
let _t = (0..N).map(|_| {
|
||||
let a = a.clone();
|
||||
let cnt = cnt.clone();
|
||||
let srv_tx = srv_tx.clone();
|
||||
thread::scoped(move|| {
|
||||
let mut a = a;
|
||||
loop {
|
||||
match a.accept() {
|
||||
Ok(..) => {
|
||||
if cnt.fetch_add(1, Ordering::SeqCst) == N * M - 1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
Err(ref e) if e.kind == EndOfFile => break,
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
srv_tx.send(());
|
||||
})
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let _t = (0..N).map(|_| {
|
||||
let cli_tx = cli_tx.clone();
|
||||
thread::scoped(move|| {
|
||||
for _ in 0..M {
|
||||
let _s = TcpStream::connect(addr).unwrap();
|
||||
}
|
||||
cli_tx.send(());
|
||||
})
|
||||
}).collect::<Vec<_>>();
|
||||
drop((cli_tx, srv_tx));
|
||||
|
||||
// wait for senders
|
||||
if cli_rx.iter().take(N).count() != N {
|
||||
a.close_accept().unwrap();
|
||||
panic!("clients panicked");
|
||||
}
|
||||
|
||||
// wait for one acceptor to die
|
||||
let _ = srv_rx.recv();
|
||||
|
||||
// Notify other receivers should die
|
||||
a.close_accept().unwrap();
|
||||
|
||||
// wait for receivers
|
||||
assert_eq!(srv_rx.iter().take(N - 1).count(), N - 1);
|
||||
|
||||
// Everything should have been accepted.
|
||||
assert_eq!(cnt.load(Ordering::SeqCst), N * M);
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-pretty
|
||||
// compile-flags:--test
|
||||
// exec-env:RUST_TEST_THREADS=1
|
||||
|
||||
// Tests for the connect_timeout() function on a TcpStream. This runs with only
|
||||
// one test task to ensure that errors are timeouts, not file descriptor
|
||||
// exhaustion.
|
||||
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
#![allow(unused_imports)]
|
||||
#![feature(old_io, std_misc, io)]
|
||||
|
||||
use std::old_io::*;
|
||||
use std::old_io::test::*;
|
||||
use std::old_io;
|
||||
use std::time::Duration;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
#[cfg_attr(target_os = "freebsd", ignore)]
|
||||
fn eventual_timeout() {
|
||||
let addr = next_test_ip4();
|
||||
|
||||
let (tx1, rx1) = channel();
|
||||
let (_tx2, rx2) = channel::<()>();
|
||||
let _t = thread::scoped(move|| {
|
||||
let _l = TcpListener::bind(addr).unwrap().listen();
|
||||
tx1.send(()).unwrap();
|
||||
let _ = rx2.recv();
|
||||
});
|
||||
rx1.recv().unwrap();
|
||||
|
||||
let mut v = Vec::new();
|
||||
for _ in 0_usize..10000 {
|
||||
match TcpStream::connect_timeout(addr, Duration::milliseconds(100)) {
|
||||
Ok(e) => v.push(e),
|
||||
Err(ref e) if e.kind == old_io::TimedOut => return,
|
||||
Err(e) => panic!("other error: {}", e),
|
||||
}
|
||||
}
|
||||
panic!("never timed out!");
|
||||
}
|
||||
|
||||
fn timeout_success() {
|
||||
let addr = next_test_ip4();
|
||||
let _l = TcpListener::bind(addr).unwrap().listen();
|
||||
|
||||
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_ok());
|
||||
}
|
||||
|
||||
fn timeout_error() {
|
||||
let addr = next_test_ip4();
|
||||
|
||||
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_err());
|
||||
}
|
||||
|
||||
fn connect_timeout_zero() {
|
||||
let addr = next_test_ip4();
|
||||
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(0)).is_err());
|
||||
}
|
||||
|
||||
fn connect_timeout_negative() {
|
||||
let addr = next_test_ip4();
|
||||
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(-1)).is_err());
|
||||
}
|
@ -1,213 +0,0 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-windows TempDir may cause IoError on windows: #10463
|
||||
|
||||
// These tests are here to exercise the functionality of the `tempfile` module.
|
||||
// One might expect these tests to be located in that module, but sadly they
|
||||
// cannot. The tests need to invoke `os::change_dir` which cannot be done in the
|
||||
// normal test infrastructure. If the tests change the current working
|
||||
// directory, then *all* tests which require relative paths suddenly break b/c
|
||||
// they're in a different location than before. Hence, these tests are all run
|
||||
// serially here.
|
||||
|
||||
#![feature(old_io, old_path, os, old_fs)]
|
||||
|
||||
use std::old_path::{Path, GenericPath};
|
||||
use std::old_io::fs::PathExtensions;
|
||||
use std::old_io::{fs, TempDir};
|
||||
use std::old_io;
|
||||
use std::env;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
fn test_tempdir() {
|
||||
let path = {
|
||||
let p = TempDir::new_in(&Path::new("."), "foobar").unwrap();
|
||||
let p = p.path();
|
||||
assert!(p.as_str().unwrap().contains("foobar"));
|
||||
p.clone()
|
||||
};
|
||||
assert!(!path.exists());
|
||||
}
|
||||
|
||||
fn test_rm_tempdir() {
|
||||
let (tx, rx) = channel();
|
||||
let f = move|| -> () {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
tx.send(tmp.path().clone()).unwrap();
|
||||
panic!("panic to unwind past `tmp`");
|
||||
};
|
||||
thread::spawn(f).join();
|
||||
let path = rx.recv().unwrap();
|
||||
assert!(!path.exists());
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
let path = tmp.path().clone();
|
||||
let f = move|| -> () {
|
||||
let _tmp = tmp;
|
||||
panic!("panic to unwind past `tmp`");
|
||||
};
|
||||
thread::spawn(f).join();
|
||||
assert!(!path.exists());
|
||||
|
||||
let path;
|
||||
{
|
||||
let f = move || {
|
||||
TempDir::new("test_rm_tempdir").unwrap()
|
||||
};
|
||||
// FIXME(#16640) `: TempDir` annotation shouldn't be necessary
|
||||
let tmp: TempDir = thread::scoped(f).join();
|
||||
path = tmp.path().clone();
|
||||
assert!(path.exists());
|
||||
}
|
||||
assert!(!path.exists());
|
||||
|
||||
let path;
|
||||
{
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
path = tmp.into_inner();
|
||||
}
|
||||
assert!(path.exists());
|
||||
fs::rmdir_recursive(&path);
|
||||
assert!(!path.exists());
|
||||
}
|
||||
|
||||
fn test_rm_tempdir_close() {
|
||||
let (tx, rx) = channel();
|
||||
let f = move|| -> () {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
tx.send(tmp.path().clone()).unwrap();
|
||||
tmp.close();
|
||||
panic!("panic when unwinding past `tmp`");
|
||||
};
|
||||
thread::spawn(f).join();
|
||||
let path = rx.recv().unwrap();
|
||||
assert!(!path.exists());
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
let path = tmp.path().clone();
|
||||
let f = move|| -> () {
|
||||
let tmp = tmp;
|
||||
tmp.close();
|
||||
panic!("panic when unwinding past `tmp`");
|
||||
};
|
||||
thread::spawn(f).join();
|
||||
assert!(!path.exists());
|
||||
|
||||
let path;
|
||||
{
|
||||
let f = move || {
|
||||
TempDir::new("test_rm_tempdir").unwrap()
|
||||
};
|
||||
// FIXME(#16640) `: TempDir` annotation shouldn't be necessary
|
||||
let tmp: TempDir = thread::scoped(f).join();
|
||||
path = tmp.path().clone();
|
||||
assert!(path.exists());
|
||||
tmp.close();
|
||||
}
|
||||
assert!(!path.exists());
|
||||
|
||||
let path;
|
||||
{
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
path = tmp.into_inner();
|
||||
}
|
||||
assert!(path.exists());
|
||||
fs::rmdir_recursive(&path);
|
||||
assert!(!path.exists());
|
||||
}
|
||||
|
||||
// Ideally these would be in std::os but then core would need
|
||||
// to depend on std
|
||||
fn recursive_mkdir_rel() {
|
||||
let path = Path::new("frob");
|
||||
let cwd = Path::new(env::current_dir().unwrap().to_str().unwrap());
|
||||
println!("recursive_mkdir_rel: Making: {} in cwd {} [{}]", path.display(),
|
||||
cwd.display(), path.exists());
|
||||
fs::mkdir_recursive(&path, old_io::USER_RWX);
|
||||
assert!(path.is_dir());
|
||||
fs::mkdir_recursive(&path, old_io::USER_RWX);
|
||||
assert!(path.is_dir());
|
||||
}
|
||||
|
||||
fn recursive_mkdir_dot() {
|
||||
let dot = Path::new(".");
|
||||
fs::mkdir_recursive(&dot, old_io::USER_RWX);
|
||||
let dotdot = Path::new("..");
|
||||
fs::mkdir_recursive(&dotdot, old_io::USER_RWX);
|
||||
}
|
||||
|
||||
fn recursive_mkdir_rel_2() {
|
||||
let path = Path::new("./frob/baz");
|
||||
let cwd = Path::new(env::current_dir().unwrap().to_str().unwrap());
|
||||
println!("recursive_mkdir_rel_2: Making: {} in cwd {} [{}]", path.display(),
|
||||
cwd.display(), path.exists());
|
||||
fs::mkdir_recursive(&path, old_io::USER_RWX);
|
||||
assert!(path.is_dir());
|
||||
assert!(path.dir_path().is_dir());
|
||||
let path2 = Path::new("quux/blat");
|
||||
println!("recursive_mkdir_rel_2: Making: {} in cwd {}", path2.display(),
|
||||
cwd.display());
|
||||
fs::mkdir_recursive(&path2, old_io::USER_RWX);
|
||||
assert!(path2.is_dir());
|
||||
assert!(path2.dir_path().is_dir());
|
||||
}
|
||||
|
||||
// Ideally this would be in core, but needs TempFile
|
||||
pub fn test_rmdir_recursive_ok() {
|
||||
let rwx = old_io::USER_RWX;
|
||||
|
||||
let tmpdir = TempDir::new("test").ok().expect("test_rmdir_recursive_ok: \
|
||||
couldn't create temp dir");
|
||||
let tmpdir = tmpdir.path();
|
||||
let root = tmpdir.join("foo");
|
||||
|
||||
println!("making {}", root.display());
|
||||
fs::mkdir(&root, rwx);
|
||||
fs::mkdir(&root.join("foo"), rwx);
|
||||
fs::mkdir(&root.join("foo").join("bar"), rwx);
|
||||
fs::mkdir(&root.join("foo").join("bar").join("blat"), rwx);
|
||||
fs::rmdir_recursive(&root);
|
||||
assert!(!root.exists());
|
||||
assert!(!root.join("bar").exists());
|
||||
assert!(!root.join("bar").join("blat").exists());
|
||||
}
|
||||
|
||||
pub fn dont_double_panic() {
|
||||
let r: Result<(), _> = thread::spawn(move|| {
|
||||
let tmpdir = TempDir::new("test").unwrap();
|
||||
// Remove the temporary directory so that TempDir sees
|
||||
// an error on drop
|
||||
fs::rmdir(tmpdir.path());
|
||||
// Panic. If TempDir panics *again* due to the rmdir
|
||||
// error then the process will abort.
|
||||
panic!();
|
||||
}).join();
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
fn in_tmpdir<F>(f: F) where F: FnOnce() {
|
||||
let tmpdir = TempDir::new("test").ok().expect("can't make tmpdir");
|
||||
assert!(env::set_current_dir(tmpdir.path().as_str().unwrap()).is_ok());
|
||||
|
||||
f();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
in_tmpdir(test_tempdir);
|
||||
in_tmpdir(test_rm_tempdir);
|
||||
in_tmpdir(test_rm_tempdir_close);
|
||||
in_tmpdir(recursive_mkdir_rel);
|
||||
in_tmpdir(recursive_mkdir_dot);
|
||||
in_tmpdir(recursive_mkdir_rel_2);
|
||||
in_tmpdir(test_rmdir_recursive_ok);
|
||||
in_tmpdir(dont_double_panic);
|
||||
}
|
@ -17,11 +17,19 @@ use std::default::Default;
|
||||
use std::iter::FromIterator;
|
||||
use std::ops::Add;
|
||||
use std::option::IntoIter as OptionIter;
|
||||
use std::rand::Rand;
|
||||
use std::rand::XorShiftRng as DummyRng;
|
||||
// FIXME the glob std::prelude::*; import of Vec is missing non-static inherent methods.
|
||||
// FIXME the glob std::prelude::*; import of Vec is missing non-static inherent
|
||||
// methods.
|
||||
use std::vec::Vec;
|
||||
|
||||
pub struct XorShiftRng;
|
||||
use XorShiftRng as DummyRng;
|
||||
impl Rng for XorShiftRng {}
|
||||
pub trait Rng {}
|
||||
pub trait Rand: Default + Sized {
|
||||
fn rand<R: Rng>(rng: &mut R) -> Self { Default::default() }
|
||||
}
|
||||
impl Rand for i32 { }
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
struct Newt<T>(T);
|
||||
|
||||
@ -29,7 +37,7 @@ fn id<T>(x: T) -> T { x }
|
||||
fn eq<T: Eq>(a: T, b: T) -> bool { a == b }
|
||||
fn u8_as_i8(x: u8) -> i8 { x as i8 }
|
||||
fn odd(x: usize) -> bool { x % 2 == 1 }
|
||||
fn dummy_rng() -> DummyRng { DummyRng::new_unseeded() }
|
||||
fn dummy_rng() -> DummyRng { XorShiftRng }
|
||||
|
||||
trait Size: Sized {
|
||||
fn size() -> usize { std::mem::size_of::<Self>() }
|
||||
|
@ -12,7 +12,7 @@
|
||||
#![feature(rand, core)]
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
use std::rand::{thread_rng, Rng, Rand};
|
||||
use std::__rand::{thread_rng, Rng};
|
||||
use std::thread;
|
||||
|
||||
const REPEATS: usize = 5;
|
||||
@ -36,18 +36,7 @@ static drop_counts: [AtomicUsize; MAX_LEN] =
|
||||
static creation_count: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
|
||||
struct DropCounter { x: usize, creation_id: usize }
|
||||
|
||||
impl Rand for DropCounter {
|
||||
fn rand<R: Rng>(rng: &mut R) -> DropCounter {
|
||||
// (we're not using this concurrently, so Relaxed is fine.)
|
||||
let num = creation_count.fetch_add(1, Ordering::Relaxed);
|
||||
DropCounter {
|
||||
x: rng.gen(),
|
||||
creation_id: num
|
||||
}
|
||||
}
|
||||
}
|
||||
struct DropCounter { x: u32, creation_id: usize }
|
||||
|
||||
impl Drop for DropCounter {
|
||||
fn drop(&mut self) {
|
||||
@ -64,9 +53,13 @@ pub fn main() {
|
||||
// IDs start from 0.
|
||||
creation_count.store(0, Ordering::Relaxed);
|
||||
|
||||
let main = thread_rng().gen_iter::<DropCounter>()
|
||||
.take(len)
|
||||
.collect::<Vec<DropCounter>>();
|
||||
let mut rng = thread_rng();
|
||||
let main = (0..len).map(|_| {
|
||||
DropCounter {
|
||||
x: rng.next_u32(),
|
||||
creation_id: creation_count.fetch_add(1, Ordering::Relaxed),
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
// work out the total number of comparisons required to sort
|
||||
// this array...
|
||||
|
@ -9,11 +9,11 @@
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(libc, old_io)]
|
||||
#![feature(libc)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::old_io::process::Command;
|
||||
use std::process::Command;
|
||||
|
||||
use libc::funcs::posix88::unistd;
|
||||
|
||||
@ -38,7 +38,7 @@ fn find_zombies() {
|
||||
|
||||
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
|
||||
let ps_cmd_output = Command::new("ps").args(&["-A", "-o", "pid,ppid,args"]).output().unwrap();
|
||||
let ps_output = String::from_utf8_lossy(&ps_cmd_output.output);
|
||||
let ps_output = String::from_utf8_lossy(&ps_cmd_output.stdout);
|
||||
|
||||
for (line_no, line) in ps_output.split('\n').enumerate() {
|
||||
if 0 < line_no && 0 < line.len() &&
|
||||
@ -59,7 +59,7 @@ fn main() {
|
||||
let too_long = format!("/NoSuchCommand{:0300}", 0u8);
|
||||
|
||||
let _failures = (0..100).map(|_| {
|
||||
let cmd = Command::new(&too_long);
|
||||
let mut cmd = Command::new(&too_long);
|
||||
let failed = cmd.spawn();
|
||||
assert!(failed.is_err(), "Make sure the command fails to spawn(): {:?}", cmd);
|
||||
failed
|
||||
|
Loading…
x
Reference in New Issue
Block a user