Skip to content

Commit 94d34c7

Browse files
committed
---
yaml --- r: 174911 b: refs/heads/snap-stage3 c: 2e888d0 h: refs/heads/master i: 174909: b0e66c6 174907: 32d81c8 174903: 22be2d1 174895: a244e28 174879: cee84f7 174847: 1c4abd0 v: v3
1 parent e9e0ff6 commit 94d34c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5005
-370
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: a0f86de49748b472d4d189d9688b0d856c000914
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 0430a43d635841db44978bb648e9cf7e7cfa1bba
4+
refs/heads/snap-stage3: 2e888d0341e81de1744b257c25b012c2c148f0ba
55
refs/heads/try: 08f6380a9f0b866796080094f44fe25ea5636547
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/mk/crates.mk

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
TARGET_CRATES := libc std flate arena term \
5353
serialize getopts collections test rand \
54-
log graphviz core rbml alloc \
54+
log regex graphviz core rbml alloc \
5555
unicode rustc_bitflags
5656
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
5757
rustc_trans rustc_back rustc_llvm rustc_privacy
@@ -95,15 +95,16 @@ DEPS_term := std log
9595
DEPS_getopts := std
9696
DEPS_collections := core alloc unicode
9797
DEPS_num := std
98-
DEPS_test := std getopts serialize rbml term native:rust_test_helpers
98+
DEPS_test := std getopts serialize rbml term regex native:rust_test_helpers
9999
DEPS_rand := core
100-
DEPS_log := std
100+
DEPS_log := std regex
101+
DEPS_regex := std
101102
DEPS_fmt_macros = std
102103

103104
TOOL_DEPS_compiletest := test getopts
104105
TOOL_DEPS_rustdoc := rustdoc
105106
TOOL_DEPS_rustc := rustc_driver
106-
TOOL_DEPS_rustbook := std rustdoc
107+
TOOL_DEPS_rustbook := std regex rustdoc
107108
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
108109
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
109110
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
@@ -129,8 +130,9 @@ DOC_CRATES := $(filter-out rustc, \
129130
$(filter-out rustc_driver, \
130131
$(filter-out rustc_privacy, \
131132
$(filter-out log, \
133+
$(filter-out regex, \
132134
$(filter-out getopts, \
133-
$(filter-out syntax, $(CRATES)))))))))))
135+
$(filter-out syntax, $(CRATES))))))))))))
134136
COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_resolve \
135137
rustc_typeck rustc_driver syntax rustc_privacy
136138

branches/snap-stage3/src/compiletest/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub use self::Mode::*;
1111

1212
use std::fmt;
1313
use std::str::FromStr;
14+
use regex::Regex;
1415

1516
#[derive(Clone, PartialEq, Debug)]
1617
pub enum Mode {
@@ -100,7 +101,10 @@ pub struct Config {
100101
pub run_ignored: bool,
101102

102103
// Only run tests that match this filter
103-
pub filter: Option<String>,
104+
pub filter: Option<Regex>,
105+
106+
// Precompiled regex for finding expected errors in cfail
107+
pub cfail_regex: Regex,
104108

105109
// Write out a parseable log of tests that were run
106110
pub logfile: Option<Path>,

branches/snap-stage3/src/compiletest/compiletest.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern crate getopts;
2222

2323
#[macro_use]
2424
extern crate log;
25+
extern crate regex;
2526

2627
use std::os;
2728
use std::io;
@@ -32,6 +33,7 @@ use getopts::{optopt, optflag, reqopt};
3233
use common::Config;
3334
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
3435
use util::logv;
36+
use regex::Regex;
3537

3638
pub mod procsrv;
3739
pub mod util;
@@ -114,7 +116,14 @@ pub fn parse_config(args: Vec<String> ) -> Config {
114116
}
115117

116118
let filter = if !matches.free.is_empty() {
117-
Some(matches.free[0].clone())
119+
let s = matches.free[0].as_slice();
120+
match regex::Regex::new(s) {
121+
Ok(re) => Some(re),
122+
Err(e) => {
123+
println!("failed to parse filter /{}/: {:?}", s, e);
124+
panic!()
125+
}
126+
}
118127
} else {
119128
None
120129
};
@@ -136,6 +145,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
136145
.as_slice()).expect("invalid mode"),
137146
run_ignored: matches.opt_present("ignored"),
138147
filter: filter,
148+
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
139149
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
140150
runtool: matches.opt_str("runtool"),
141151
host_rustcflags: matches.opt_str("host-rustcflags"),
@@ -364,24 +374,18 @@ fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
364374
if full_version_line.as_slice().trim().len() > 0 => {
365375
let full_version_line = full_version_line.as_slice().trim();
366376

367-
// used to be a regex "(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)"
368-
for (pos, c) in full_version_line.char_indices() {
369-
if !c.is_digit(10) { continue }
370-
if pos + 2 >= full_version_line.len() { continue }
371-
if full_version_line.char_at(pos + 1) != '.' { continue }
372-
if !full_version_line.char_at(pos + 2).is_digit(10) { continue }
373-
if pos > 0 && full_version_line.char_at_reverse(pos).is_digit(10) {
374-
continue
377+
let re = Regex::new(r"(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)").unwrap();
378+
379+
match re.captures(full_version_line) {
380+
Some(captures) => {
381+
Some(captures.at(2).unwrap_or("").to_string())
375382
}
376-
if pos + 3 < full_version_line.len() &&
377-
full_version_line.char_at(pos + 3).is_digit(10) {
378-
continue
383+
None => {
384+
println!("Could not extract GDB version from line '{}'",
385+
full_version_line);
386+
None
379387
}
380-
return Some(full_version_line[pos..pos+3].to_string());
381388
}
382-
println!("Could not extract GDB version from line '{}'",
383-
full_version_line);
384-
None
385389
},
386390
_ => None
387391
}
@@ -404,26 +408,18 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
404408
if full_version_line.as_slice().trim().len() > 0 => {
405409
let full_version_line = full_version_line.as_slice().trim();
406410

407-
for (pos, l) in full_version_line.char_indices() {
408-
if l != 'l' && l != 'L' { continue }
409-
if pos + 5 >= full_version_line.len() { continue }
410-
let l = full_version_line.char_at(pos + 1);
411-
if l != 'l' && l != 'L' { continue }
412-
let d = full_version_line.char_at(pos + 2);
413-
if d != 'd' && d != 'D' { continue }
414-
let b = full_version_line.char_at(pos + 3);
415-
if b != 'b' && b != 'B' { continue }
416-
let dash = full_version_line.char_at(pos + 4);
417-
if dash != '-' { continue }
418-
419-
let vers = full_version_line[pos + 5..].chars().take_while(|c| {
420-
c.is_digit(10)
421-
}).collect::<String>();
422-
if vers.len() > 0 { return Some(vers) }
411+
let re = Regex::new(r"[Ll][Ll][Dd][Bb]-([0-9]+)").unwrap();
412+
413+
match re.captures(full_version_line) {
414+
Some(captures) => {
415+
Some(captures.at(1).unwrap_or("").to_string())
416+
}
417+
None => {
418+
println!("Could not extract LLDB version from line '{}'",
419+
full_version_line);
420+
None
421+
}
423422
}
424-
println!("Could not extract LLDB version from line '{}'",
425-
full_version_line);
426-
None
427423
},
428424
_ => None
429425
}

branches/snap-stage3/src/compiletest/errors.rs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,32 @@
99
// except according to those terms.
1010
use self::WhichLine::*;
1111

12+
use std::ascii::AsciiExt;
1213
use std::io::{BufferedReader, File};
14+
use regex::Regex;
1315

1416
pub struct ExpectedError {
1517
pub line: uint,
1618
pub kind: String,
1719
pub msg: String,
1820
}
1921

20-
#[derive(PartialEq, Show)]
21-
enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
22-
2322
/// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
2423
/// The former is a "follow" that inherits its target from the preceding line;
2524
/// the latter is an "adjusts" that goes that many lines up.
2625
///
2726
/// Goal is to enable tests both like: //~^^^ ERROR go up three
2827
/// and also //~^ ERROR message one for the preceding line, and
2928
/// //~| ERROR message two for that same line.
29+
30+
pub static EXPECTED_PATTERN : &'static str =
31+
r"//~(?P<follow>\|)?(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)";
32+
33+
#[derive(PartialEq, Show)]
34+
enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
35+
3036
// Load any test directives embedded in the file
31-
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
37+
pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
3238
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
3339

3440
// `last_nonfollow_error` tracks the most recently seen
@@ -44,7 +50,7 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
4450
rdr.lines().enumerate().filter_map(|(line_no, ln)| {
4551
parse_expected(last_nonfollow_error,
4652
line_no + 1,
47-
ln.unwrap().as_slice())
53+
ln.unwrap().as_slice(), re)
4854
.map(|(which, error)| {
4955
match which {
5056
FollowPrevious(_) => {}
@@ -57,39 +63,30 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
5763

5864
fn parse_expected(last_nonfollow_error: Option<uint>,
5965
line_num: uint,
60-
line: &str) -> Option<(WhichLine, ExpectedError)> {
61-
let start = match line.find_str("//~") { Some(i) => i, None => return None };
62-
let (follow, adjusts) = if line.char_at(start + 3) == '|' {
63-
(true, 0)
64-
} else {
65-
(false, line[start + 3..].chars().take_while(|c| *c == '^').count())
66-
};
67-
let kind_start = start + 3 + adjusts + (follow as usize);
68-
let letters = line[kind_start..].chars();
69-
let kind = letters.skip_while(|c| c.is_whitespace())
70-
.take_while(|c| !c.is_whitespace())
71-
.map(|c| c.to_lowercase())
72-
.collect::<String>();
73-
let letters = line[kind_start..].chars();
74-
let msg = letters.skip_while(|c| c.is_whitespace())
75-
.skip_while(|c| !c.is_whitespace())
76-
.collect::<String>().trim().to_string();
66+
line: &str,
67+
re: &Regex) -> Option<(WhichLine, ExpectedError)> {
68+
re.captures(line).and_then(|caps| {
69+
let adjusts = caps.name("adjusts").unwrap_or("").len();
70+
let kind = caps.name("kind").unwrap_or("").to_ascii_lowercase();
71+
let msg = caps.name("msg").unwrap_or("").trim().to_string();
72+
let follow = caps.name("follow").unwrap_or("").len() > 0;
7773

78-
let (which, line) = if follow {
79-
assert!(adjusts == 0, "use either //~| or //~^, not both.");
80-
let line = last_nonfollow_error.unwrap_or_else(|| {
81-
panic!("encountered //~| without preceding //~^ line.")
82-
});
83-
(FollowPrevious(line), line)
84-
} else {
85-
let which =
86-
if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
87-
let line = line_num - adjusts;
88-
(which, line)
89-
};
74+
let (which, line) = if follow {
75+
assert!(adjusts == 0, "use either //~| or //~^, not both.");
76+
let line = last_nonfollow_error.unwrap_or_else(|| {
77+
panic!("encountered //~| without preceding //~^ line.")
78+
});
79+
(FollowPrevious(line), line)
80+
} else {
81+
let which =
82+
if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine };
83+
let line = line_num - adjusts;
84+
(which, line)
85+
};
9086

91-
debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg);
92-
Some((which, ExpectedError { line: line,
93-
kind: kind,
94-
msg: msg, }))
87+
debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg);
88+
Some((which, ExpectedError { line: line,
89+
kind: kind,
90+
msg: msg, }))
91+
})
9592
}

branches/snap-stage3/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testfile: &Path) {
9999
}
100100

101101
let output_to_check = get_output(props, &proc_res);
102-
let expected_errors = errors::load_errors(testfile);
102+
let expected_errors = errors::load_errors(&config.cfail_regex, testfile);
103103
if !expected_errors.is_empty() {
104104
if !props.error_patterns.is_empty() {
105105
fatal("both error pattern and expected errors specified");

branches/snap-stage3/src/grammar/verify.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
extern crate syntax;
1414
extern crate rustc;
1515

16+
extern crate regex;
17+
1618
#[macro_use]
1719
extern crate log;
1820

1921
use std::collections::HashMap;
2022
use std::io::File;
23+
use regex::Regex;
2124

2225
use syntax::parse;
2326
use syntax::parse::lexer;
@@ -164,19 +167,15 @@ fn count(lit: &str) -> usize {
164167
}
165168

166169
fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>) -> TokenAndSpan {
167-
// old regex:
168-
// \[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]
169-
let start = s.find_str("[@").unwrap();
170-
let comma = start + s[start..].find_str(",").unwrap();
171-
let colon = comma + s[comma..].find_str(":").unwrap();
172-
let content_start = colon + s[colon..].find_str("='").unwrap();
173-
let content_end = content_start + s[content_start..].find_str("',<").unwrap();
174-
let toknum_end = content_end + s[content_end..].find_str(">,").unwrap();
175-
176-
let start = &s[comma + 1 .. colon];
177-
let end = &s[colon + 1 .. content_start];
178-
let content = &s[content_start + 2 .. content_end];
179-
let toknum = &s[content_end + 3 .. toknum_end];
170+
let re = Regex::new(
171+
r"\[@(?P<seq>\d+),(?P<start>\d+):(?P<end>\d+)='(?P<content>.+?)',<(?P<toknum>-?\d+)>,\d+:\d+]"
172+
).unwrap();
173+
174+
let m = re.captures(s).expect(format!("The regex didn't match {}", s).as_slice());
175+
let start = m.name("start").unwrap_or("");
176+
let end = m.name("end").unwrap_or("");
177+
let toknum = m.name("toknum").unwrap_or("");
178+
let content = m.name("content").unwrap_or("");
180179

181180
let proto_tok = tokens.get(toknum).expect(format!("didn't find token {:?} in the map",
182181
toknum).as_slice());

branches/snap-stage3/src/libcoretest/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ mod num;
1414
fn test_format_flags() {
1515
// No residual flags left by pointer formatting
1616
let p = "".as_ptr();
17-
assert_eq!(format!("{:p} {:x}", p, 16), format!("{:p} 10", p));
17+
assert_eq!(format!("{:p} {:x}", p, 16u), format!("{:p} 10", p));
1818
}

0 commit comments

Comments
 (0)