about summary refs log tree commit diff
path: root/src/compiletest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-10 04:31:24 -0700
committerbors <bors@rust-lang.org>2013-10-10 04:31:24 -0700
commit0ede2ea4e2e9384ac5bd614012d85ed213873dab (patch)
tree1c1273aa2aabe17e0557c01b41d4d438c5dd130e /src/compiletest
parent34d123db4eb03c1b2378b6248ebea5f0f40f2a4f (diff)
parent413747176c9ce52a87775175e096b3eca88e6b64 (diff)
auto merge of #9749 : alexcrichton/rust/less-io, r=brson
This implements a number of the baby steps needed to start eliminating everything inside of `std::io`. It turns out that there are a *lot* of users of that module, so I'm going to try to tackle them separately instead of bringing down the whole system all at once.

This pull implements a large amount of unimplemented functionality inside of `std::rt::io` including:

* Native file I/O (file descriptors, *FILE)
* Native stdio (through the native file descriptors)
* Native processes (extracted from `std::run`)

I also found that there are a number of users of `std::io` which desire to read an input line-by-line, so I added an implementation of `read_until` and `read_line` to `BufferedReader`.

With all of these changes in place, I started to axe various usages of `std::io`. There's a lot of one-off uses here-and-there, but the major use-case remaining that doesn't have a fantastic solution is `extra::json`. I ran into a few compiler bugs when attempting to remove that, so I figured I'd come back to it later instead. 

There is one fairly major change in this pull, and it's moving from native stdio to uv stdio via `print` and `println`. Unfortunately logging still goes through native I/O (via `dumb_println`). This is going to need some thinking, because I still want the goal of logging/printing to be 0 allocations, and this is not possible if `io::stdio::stderr()` is called on each log message. Instead I think that this may need to be cached as the `logger` field inside the `Task` struct, but that will require a little more workings to get right (this is also a similar problem for print/println, do we cache `stdout()` to not have to re-create it every time?).
Diffstat (limited to 'src/compiletest')
-rw-r--r--src/compiletest/errors.rs15
-rw-r--r--src/compiletest/header.rs18
-rw-r--r--src/compiletest/procsrv.rs2
3 files changed, 22 insertions, 13 deletions
diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs
index 02195e684e3..e49a9701460 100644
--- a/src/compiletest/errors.rs
+++ b/src/compiletest/errors.rs
@@ -8,17 +8,21 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::io;
-
 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 rdr = io::file_reader(testfile).unwrap();
+    let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
     let mut line_num = 1u;
-    while !rdr.eof() {
-        let ln = rdr.read_line();
+    loop {
+        let ln = match rdr.read_line() {
+            Some(ln) => ln, None => break,
+        };
         error_patterns.push_all_move(parse_expected(line_num, ln));
         line_num += 1u;
     }
@@ -26,6 +30,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
 }
 
 fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
+    let line = line.trim();
     let error_tag = ~"//~";
     let mut idx;
     match line.find_str(error_tag) {
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs
index 36780abc7ee..730df66af23 100644
--- a/src/compiletest/header.rs
+++ b/src/compiletest/header.rs
@@ -12,8 +12,6 @@ use common::config;
 use common;
 use util;
 
-use std::io;
-
 pub struct TestProps {
     // Lines that should be expected, in order, on standard out
     error_patterns: ~[~str],
@@ -104,17 +102,23 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
     !val
 }
 
-fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
-    let rdr = io::file_reader(testfile).unwrap();
-    while !rdr.eof() {
-        let ln = rdr.read_line();
+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;
+
+    let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
+    loop {
+        let ln = match rdr.read_line() {
+            Some(ln) => ln, None => break
+        };
 
         // Assume that any directives will be found before the first
         // module or function. This doesn't seem to be an optimization
         // with a warm page cache. Maybe with a cold one.
         if ln.starts_with("fn") || ln.starts_with("mod") {
             return true;
-        } else { if !(it(ln)) { return false; } }
+        } else { if !(it(ln.trim())) { return false; } }
     }
     return true;
 }
diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs
index ef8049aa717..829916117d2 100644
--- a/src/compiletest/procsrv.rs
+++ b/src/compiletest/procsrv.rs
@@ -57,7 +57,7 @@ pub fn run(lib_path: &str,
     });
 
     for input in input.iter() {
-        proc.input().write_str(*input);
+        proc.input().write(input.as_bytes());
     }
     let output = proc.finish_with_output();