Skip to content

Commit 2fa13c1

Browse files
committed
---
yaml --- r: 51573 b: refs/heads/incoming c: 1616ffd h: refs/heads/master i: 51571: 6b52181 v: v3
1 parent b914235 commit 2fa13c1

File tree

10 files changed

+214
-325
lines changed

10 files changed

+214
-325
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: e93654c96d0288e6f2f00075d95dd4958b4cb4dc
9+
refs/heads/incoming: 1616ffd0c2627502b1015b6388480ed7429ef042
1010
refs/heads/dist-snap: 8b98e5a296d95c5e832db0756828e5bec31c6f50
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/compiletest/runtest.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
267267
// check if each line in props.check_lines appears in the
268268
// output (in order)
269269
let mut i = 0u;
270-
for str::lines(ProcRes.stdout).each |line| {
270+
for str::lines_each(ProcRes.stdout) |line| {
271271
if props.check_lines[i].trim() == line.trim() {
272272
i += 1u;
273273
}
@@ -297,8 +297,8 @@ fn check_error_patterns(props: TestProps,
297297
let mut next_err_idx = 0u;
298298
let mut next_err_pat = props.error_patterns[next_err_idx];
299299
let mut done = false;
300-
for str::split_char(ProcRes.stderr, '\n').each |line| {
301-
if str::contains(*line, next_err_pat) {
300+
for str::lines_each(ProcRes.stderr) |line| {
301+
if str::contains(line, next_err_pat) {
302302
debug!("found error pattern %s", next_err_pat);
303303
next_err_idx += 1u;
304304
if next_err_idx == vec::len(props.error_patterns) {
@@ -347,15 +347,15 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
347347
// filename:line1:col1: line2:col2: *warning:* msg
348348
// where line1:col1: is the starting point, line2:col2:
349349
// is the ending point, and * represents ANSI color codes.
350-
for str::split_char(ProcRes.stderr, '\n').each |line| {
350+
for str::lines_each(ProcRes.stderr) |line| {
351351
let mut was_expected = false;
352352
for vec::eachi(expected_errors) |i, ee| {
353353
if !found_flags[i] {
354354
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
355-
prefixes[i], ee.kind, ee.msg, *line);
356-
if (str::starts_with(*line, prefixes[i]) &&
357-
str::contains(*line, ee.kind) &&
358-
str::contains(*line, ee.msg)) {
355+
prefixes[i], ee.kind, ee.msg, line);
356+
if (str::starts_with(line, prefixes[i]) &&
357+
str::contains(line, ee.kind) &&
358+
str::contains(line, ee.msg)) {
359359
found_flags[i] = true;
360360
was_expected = true;
361361
break;
@@ -364,13 +364,13 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
364364
}
365365

366366
// ignore this msg which gets printed at the end
367-
if str::contains(*line, ~"aborting due to") {
367+
if str::contains(line, ~"aborting due to") {
368368
was_expected = true;
369369
}
370370

371-
if !was_expected && is_compiler_error_or_warning(*line) {
371+
if !was_expected && is_compiler_error_or_warning(str::from_slice(line)) {
372372
fatal_ProcRes(fmt!("unexpected compiler error or warning: '%s'",
373-
*line),
373+
line),
374374
ProcRes);
375375
}
376376
}

branches/incoming/src/libcore/io.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub trait ReaderUtil {
9999
/// Read len bytes into a new vec.
100100
fn read_bytes(&self, len: uint) -> ~[u8];
101101

102-
/// Read up until a specified character (which is not returned) or EOF.
103-
fn read_until(&self, c: char) -> ~str;
102+
/// Read up until a specified character (which is optionally included) or EOF.
103+
fn read_until(&self, c: char, include: bool) -> ~str;
104104

105105
/// Read up until the first '\n' char (which is not returned), or EOF.
106106
fn read_line(&self) -> ~str;
@@ -126,6 +126,9 @@ pub trait ReaderUtil {
126126
/// Iterate over every line until the iterator breaks or EOF.
127127
fn each_line(&self, it: &fn(&str) -> bool);
128128

129+
/// Read all the lines of the file into a vector.
130+
fn read_lines(&self) -> ~[~str];
131+
129132
/// Read n (between 1 and 8) little-endian unsigned integer bytes.
130133
fn read_le_uint_n(&self, nbytes: uint) -> u64;
131134

@@ -219,11 +222,14 @@ impl<T:Reader> ReaderUtil for T {
219222
bytes
220223
}
221224

222-
fn read_until(&self, c: char) -> ~str {
225+
fn read_until(&self, c: char, include: bool) -> ~str {
223226
let mut bytes = ~[];
224227
loop {
225228
let ch = self.read_byte();
226229
if ch == -1 || ch == c as int {
230+
if include && ch == c as int {
231+
bytes.push(ch as u8);
232+
}
227233
break;
228234
}
229235
bytes.push(ch as u8);
@@ -232,7 +238,7 @@ impl<T:Reader> ReaderUtil for T {
232238
}
233239

234240
fn read_line(&self) -> ~str {
235-
self.read_until('\n')
241+
self.read_until('\n', false)
236242
}
237243

238244
fn read_chars(&self, n: uint) -> ~[char] {
@@ -306,7 +312,7 @@ impl<T:Reader> ReaderUtil for T {
306312
}
307313

308314
fn read_c_str(&self) -> ~str {
309-
self.read_until(0 as char)
315+
self.read_until(0 as char, false)
310316
}
311317

312318
fn read_whole_stream(&self) -> ~[u8] {
@@ -329,7 +335,29 @@ impl<T:Reader> ReaderUtil for T {
329335

330336
fn each_line(&self, it: &fn(s: &str) -> bool) {
331337
while !self.eof() {
332-
if !it(self.read_line()) { break; }
338+
// include the \n, so that we can distinguish an entirely empty
339+
// line read after "...\n", and the trailing empty line in
340+
// "...\n\n".
341+
let mut line = self.read_until('\n', true);
342+
343+
// blank line at the end of the reader is ignored
344+
if self.eof() && line.is_empty() { break; }
345+
346+
// trim the \n, so that each_line is consistent with read_line
347+
let n = str::len(line);
348+
if line[n-1] == '\n' as u8 {
349+
unsafe { str::raw::set_len(&mut line, n-1); }
350+
}
351+
352+
if !it(line) { break; }
353+
}
354+
}
355+
356+
fn read_lines(&self) -> ~[~str] {
357+
do vec::build |push| {
358+
for self.each_line |line| {
359+
push(str::from_slice(line));
360+
}
333361
}
334362
}
335363

@@ -1335,6 +1363,21 @@ mod tests {
13351363
}
13361364
}
13371365
1366+
#[test]
1367+
fn test_read_lines() {
1368+
do io::with_str_reader(~"a\nb\nc\n") |inp| {
1369+
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
1370+
}
1371+
1372+
do io::with_str_reader(~"a\nb\nc") |inp| {
1373+
fail_unless!(inp.read_lines() == ~[~"a", ~"b", ~"c"]);
1374+
}
1375+
1376+
do io::with_str_reader(~"") |inp| {
1377+
fail_unless!(inp.read_lines().is_empty());
1378+
}
1379+
}
1380+
13381381
#[test]
13391382
fn test_readchars_wide() {
13401383
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";

0 commit comments

Comments
 (0)