Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin finalizing the io::file module #10179

Merged
merged 5 commits into from
Nov 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ CTEST_BUILD_BASE_rpass = run-pass
CTEST_MODE_rpass = run-pass
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_rpass-full = run-pass-full
CTEST_BUILD_BASE_rpass-full = run-pass-full
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)

Expand Down Expand Up @@ -673,7 +673,7 @@ PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
PRETTY_DIRNAME_pretty-rpass = run-pass
PRETTY_DIRNAME_pretty-rpass-full = run-pass-full
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty
Expand Down
3 changes: 2 additions & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern mod extra;

use std::os;
use std::rt;
use std::rt::io::fs;

use extra::getopts;
use extra::getopts::groups::{optopt, optflag, reqopt};
Expand Down Expand Up @@ -247,7 +248,7 @@ pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
debug!("making tests from {}",
config.src_base.display());
let mut tests = ~[];
let dirs = os::list_dir_path(&config.src_base);
let dirs = fs::readdir(&config.src_base);
for file in dirs.iter() {
let file = file.clone();
debug!("inspecting file {}", file.display());
Expand Down
8 changes: 4 additions & 4 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::rt::io::buffered::BufferedReader;
use std::rt::io::File;

pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }

// Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
use std::rt::io::Open;
use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader;

let mut error_patterns = ~[];
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
let mut line_num = 1u;
loop {
let ln = match rdr.read_line() {
Expand Down
5 changes: 2 additions & 3 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
}

fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
use std::rt::io::Open;
use std::rt::io::file::FileInfo;
use std::rt::io::buffered::BufferedReader;
use std::rt::io::File;

let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
loop {
let ln = match rdr.read_line() {
Some(ln) => ln, None => break
Expand Down
50 changes: 11 additions & 39 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,18 @@ use procsrv;
use util;
use util::logv;

use std::cell::Cell;
use std::rt::io;
use std::rt::io::Writer;
use std::rt::io::Reader;
use std::rt::io::file::FileInfo;
use std::rt::io::fs;
use std::rt::io::File;
use std::os;
use std::str;
use std::task::{spawn_sched, SingleThreaded};
use std::vec;
use std::unstable::running_on_valgrind;

use extra::test::MetricMap;

pub fn run(config: config, testfile: ~str) {
let config = Cell::new(config);
let testfile = Cell::new(testfile);
// FIXME #6436: Creating another thread to run the test because this
// is going to call waitpid. The new scheduler has some strange
// interaction between the blocking tasks and 'friend' schedulers
// that destroys parallelism if we let normal schedulers block.
// It should be possible to remove this spawn once std::run is
// rewritten to be non-blocking.
//
// We do _not_ create another thread if we're running on V because
// it serializes all threads anyways.
if running_on_valgrind() {
let config = config.take();
let testfile = testfile.take();
let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
} else {
do spawn_sched(SingleThreaded) {
let config = config.take();
let testfile = testfile.take();
let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
}
}
let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
}

pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {
Expand Down Expand Up @@ -173,7 +147,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let rounds =
match props.pp_exact { Some(_) => 1, None => 2 };

let src = testfile.open_reader(io::Open).read_to_end();
let src = File::open(testfile).read_to_end();
let src = str::from_utf8_owned(src);
let mut srcs = ~[src];

Expand All @@ -195,7 +169,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
let mut expected = match props.pp_exact {
Some(ref file) => {
let filepath = testfile.dir_path().join(file);
let s = filepath.open_reader(io::Open).read_to_end();
let s = File::open(&filepath).read_to_end();
str::from_utf8_owned(s)
}
None => { srcs[srcs.len() - 2u].clone() }
Expand Down Expand Up @@ -651,10 +625,8 @@ fn compose_and_run_compiler(
}

fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail!("can't make dir {}", path.display());
}
if path.is_dir() { return; }
fs::mkdir(path, io::UserRWX);
}

fn compose_and_run(config: &config, testfile: &Path,
Expand Down Expand Up @@ -768,7 +740,7 @@ fn dump_output(config: &config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &config, testfile: &Path,
out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension);
outfile.open_writer(io::CreateOrTruncate).write(out.as_bytes());
File::create(&outfile).write(out.as_bytes());
}

fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
Expand Down Expand Up @@ -924,7 +896,7 @@ fn _dummy_exec_compiled_test(config: &config, props: &TestProps,
fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
let tdir = aux_output_dir_name(config, testfile);

let dirs = os::list_dir_path(&tdir);
let dirs = fs::readdir(&tdir);
for file in dirs.iter() {
if file.extension_str() == Some("so") {
// FIXME (#9639): This needs to handle non-utf8 paths
Expand Down Expand Up @@ -1019,7 +991,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,


fn count_extracted_lines(p: &Path) -> uint {
let x = p.with_extension("ll").open_reader(io::Open).read_to_end();
let x = File::open(&p.with_extension("ll")).read_to_end();
let x = str::from_utf8_owned(x);
x.line_iter().len()
}
Expand Down
1 change: 1 addition & 0 deletions src/etc/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void posix88_consts() {
put_const(S_IFBLK, int);
put_const(S_IFDIR, int);
put_const(S_IFREG, int);
put_const(S_IFLNK, int);
put_const(S_IFMT, int);

put_const(S_IEXEC, int);
Expand Down
13 changes: 10 additions & 3 deletions src/libextra/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/

use std::{os, path};
use std::rt::io;
use std::rt::io::fs;
use std::path::is_sep;

use sort;
Expand Down Expand Up @@ -146,9 +148,14 @@ impl Iterator<Path> for GlobIterator {
}

fn list_dir_sorted(path: &Path) -> ~[Path] {
let mut children = os::list_dir_path(path);
sort::quick_sort(children, |p1, p2| p2.filename().unwrap() <= p1.filename().unwrap());
children
match io::result(|| fs::readdir(path)) {
Ok(children) => {
let mut children = children;
sort::quick_sort(children, |p1, p2| p2.filename() <= p1.filename());
children
}
Err(*) => ~[]
}
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/libextra/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use std::os;
use std::rand::Rng;
use std::rand;
use std::rt::io;
use std::rt::io::fs;

/// A wrapper for a path to temporary directory implementing automatic
/// scope-pased deletion.
Expand All @@ -36,8 +38,9 @@ impl TempDir {
let mut r = rand::rng();
for _ in range(0u, 1000) {
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
if os::make_dir(&p, 0x1c0) { // 700
return Some(TempDir { path: Some(p) });
match io::result(|| fs::mkdir(&p, io::UserRWX)) {
Err(*) => {}
Ok(()) => return Some(TempDir { path: Some(p) })
}
}
None
Expand Down Expand Up @@ -69,7 +72,9 @@ impl TempDir {
impl Drop for TempDir {
fn drop(&mut self) {
for path in self.path.iter() {
os::remove_dir_recursive(path);
if path.exists() {
fs::rmdir_recursive(path);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/terminfo/parser/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,6 @@ mod test {
#[ignore(reason = "no ncurses on buildbots, needs a bundled terminfo file to test against")]
fn test_parse() {
// FIXME #6870: Distribute a compiled file in src/tests and test there
// parse(io::file_reader(&p("/usr/share/terminfo/r/rxvt-256color")).unwrap(), false);
// parse(io::fs_reader(&p("/usr/share/terminfo/r/rxvt-256color")).unwrap(), false);
}
}
10 changes: 5 additions & 5 deletions src/libextra/terminfo/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use std::{os, str};
use std::os::getenv;
use std::rt::io;
use std::rt::io::file::FileInfo;
use std::rt::io::File;

/// Return path to database entry for `term`
pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
Expand Down Expand Up @@ -56,16 +56,16 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {

// Look for the terminal in all of the search directories
for p in dirs_to_search.iter() {
if os::path_exists(p) {
if p.exists() {
let f = str::from_char(first_char);
let newp = p.join_many([f.as_slice(), term]);
if os::path_exists(&newp) {
if newp.exists() {
return Some(~newp);
}
// on some installations the dir is named after the hex of the char (e.g. OS X)
let f = format!("{:x}", first_char as uint);
let newp = p.join_many([f.as_slice(), term]);
if os::path_exists(&newp) {
if newp.exists() {
return Some(~newp);
}
}
Expand All @@ -76,7 +76,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
/// Return open file for `term`
pub fn open(term: &str) -> Result<@mut io::Reader, ~str> {
match get_dbpath_for_term(term) {
Some(x) => Ok(@mut x.open_reader(io::Open).unwrap() as @mut io::Reader),
Some(x) => Ok(@mut File::open(x) as @mut io::Reader),
None => Err(format!("could not find terminfo entry for {}", term))
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use treemap::TreeMap;
use std::clone::Clone;
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
use std::rt::io;
use std::rt::io::file::FileInfo;
use std::rt::io::File;
use std::task;
use std::to_str::ToStr;
use std::f64;
Expand Down Expand Up @@ -353,10 +353,7 @@ struct ConsoleTestState {
impl ConsoleTestState {
pub fn new(opts: &TestOpts) -> ConsoleTestState {
let log_out = match opts.logfile {
Some(ref path) => {
let out = path.open_writer(io::CreateOrTruncate);
Some(@mut out as @mut io::Writer)
},
Some(ref path) => Some(@mut File::create(path) as @mut io::Writer),
None => None
};
let out = @mut io::stdio::stdout() as @mut io::Writer;
Expand Down Expand Up @@ -938,16 +935,15 @@ impl MetricMap {

/// Load MetricDiff from a file.
pub fn load(p: &Path) -> MetricMap {
assert!(os::path_exists(p));
let f = @mut p.open_reader(io::Open) as @mut io::Reader;
assert!(p.exists());
let f = @mut File::open(p) as @mut io::Reader;
let mut decoder = json::Decoder(json::from_reader(f).unwrap());
MetricMap(Decodable::decode(&mut decoder))
}

/// Write MetricDiff to a file.
pub fn save(&self, p: &Path) {
let f = @mut p.open_writer(io::CreateOrTruncate);
self.to_json().to_pretty_writer(f as @mut io::Writer);
self.to_json().to_pretty_writer(@mut File::create(p) as @mut io::Writer);
}

/// Compare against another MetricMap. Optionally compare all
Expand Down Expand Up @@ -1032,7 +1028,7 @@ impl MetricMap {
/// `MetricChange`s are `Regression`. Returns the diff as well
/// as a boolean indicating whether the ratchet succeeded.
pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) {
let old = if os::path_exists(p) {
let old = if p.exists() {
MetricMap::load(p)
} else {
MetricMap::new()
Expand Down
1 change: 0 additions & 1 deletion src/libextra/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ mod test {

#[test]
fn test_serialize_round_trip() {
use std;
use ebml;
use serialize::{Encodable, Decodable};

Expand Down
Loading