Skip to content

Commit e576b45

Browse files
committed
---
yaml --- r: 114327 b: refs/heads/master c: 4dff9cb h: refs/heads/master i: 114325: ea83cec 114323: 1ca573c 114319: 2640b46 v: v3
1 parent a961c10 commit e576b45

File tree

6 files changed

+41
-69
lines changed

6 files changed

+41
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c9ab33a8fde708c8a4cf70b03f5d69370220665c
2+
refs/heads/master: 4dff9cbf58bb7a274a693eb7d19006402945fc7e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/compiletest/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -91,6 +91,9 @@ pub struct Config {
9191
// Only run tests that match this filter
9292
pub filter: Option<Regex>,
9393

94+
// Precompiled regex for finding expected errors in cfail
95+
pub cfail_regex: Regex,
96+
9497
// Write out a parseable log of tests that were run
9598
pub logfile: Option<Path>,
9699

@@ -144,5 +147,4 @@ pub struct Config {
144147

145148
// Explain what's going on
146149
pub verbose: bool
147-
148150
}

trunk/src/compiletest/compiletest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -33,6 +33,7 @@ use getopts::{optopt, optflag, reqopt};
3333
use common::Config;
3434
use common::{Pretty, DebugInfoGdb, Codegen};
3535
use util::logv;
36+
use regex::Regex;
3637

3738
pub mod procsrv;
3839
pub mod util;
@@ -147,6 +148,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
147148
.as_slice()).expect("invalid mode"),
148149
run_ignored: matches.opt_present("ignored"),
149150
filter: filter,
151+
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
150152
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
151153
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
152154
ratchet_metrics:

trunk/src/compiletest/errors.rs

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -9,68 +9,36 @@
99
// except according to those terms.
1010

1111
use std::io::{BufferedReader, File};
12+
use regex::Regex;
1213

1314
pub struct ExpectedError {
1415
pub line: uint,
1516
pub kind: StrBuf,
1617
pub msg: StrBuf,
1718
}
1819

19-
// Load any test directives embedded in the file
20-
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
20+
pub static EXPECTED_PATTERN : &'static str = r"//~(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)";
2121

22-
let mut error_patterns = Vec::new();
22+
// Load any test directives embedded in the file
23+
pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
2324
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
24-
let mut line_num = 1u;
25-
for ln in rdr.lines() {
26-
error_patterns.push_all_move(parse_expected(line_num,
27-
ln.unwrap().to_strbuf()));
28-
line_num += 1u;
29-
}
30-
return error_patterns;
31-
}
32-
33-
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
34-
let line = line.as_slice().trim().to_strbuf();
35-
let error_tag = "//~".to_strbuf();
36-
let mut idx;
37-
match line.as_slice().find_str(error_tag.as_slice()) {
38-
None => return Vec::new(),
39-
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
40-
}
41-
42-
// "//~^^^ kind msg" denotes a message expected
43-
// three lines above current line:
44-
let mut adjust_line = 0u;
45-
let len = line.len();
46-
while idx < len && line.as_slice()[idx] == ('^' as u8) {
47-
adjust_line += 1u;
48-
idx += 1u;
49-
}
5025

51-
// Extract kind:
52-
while idx < len && line.as_slice()[idx] == (' ' as u8) {
53-
idx += 1u;
54-
}
55-
let start_kind = idx;
56-
while idx < len && line.as_slice()[idx] != (' ' as u8) {
57-
idx += 1u;
58-
}
59-
60-
let kind = line.as_slice().slice(start_kind, idx);
61-
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();
62-
63-
// Extract msg:
64-
while idx < len && line.as_slice()[idx] == (' ' as u8) {
65-
idx += 1u;
66-
}
67-
let msg = line.as_slice().slice(idx, len).to_strbuf();
68-
69-
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
26+
rdr.lines().enumerate().filter_map(|(line_no, ln)| {
27+
parse_expected(line_no + 1, ln.unwrap(), re)
28+
}).collect()
29+
}
7030

71-
return vec!(ExpectedError{
72-
line: line_num - adjust_line,
73-
kind: kind,
74-
msg: msg,
75-
});
31+
fn parse_expected(line_num: uint, line: &str, re: &Regex) -> Option<ExpectedError> {
32+
re.captures(line).and_then(|caps| {
33+
let adjusts = caps.name("adjusts").len();
34+
let kind = caps.name("kind").to_ascii().to_lower().into_str().to_strbuf();
35+
let msg = caps.name("msg").trim().to_strbuf();
36+
37+
debug!("line={} kind={} msg={}", line_num, kind, msg);
38+
Some(ExpectedError {
39+
line: line_num - adjusts,
40+
kind: kind,
41+
msg: msg,
42+
})
43+
})
7644
}

trunk/src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -79,7 +79,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testfile: &Path) {
7979

8080
check_correct_failure_status(&proc_res);
8181

82-
let expected_errors = errors::load_errors(testfile);
82+
let expected_errors = errors::load_errors(&config.cfail_regex, testfile);
8383
if !expected_errors.is_empty() {
8484
if !props.error_patterns.is_empty() {
8585
fatal("both error pattern and expected errors \

trunk/src/doc/rust.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,11 @@ extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for externa
848848
##### Use declarations
849849

850850
~~~~ {.notrust .ebnf .gram}
851-
use_decl : "pub" ? "use" ident [ '=' path
852-
| "::" path_glob ] ;
851+
use_decl : "pub" ? "use" [ ident '=' path
852+
| path_glob ] ;
853853
854-
path_glob : ident [ "::" path_glob ] ?
855-
| '*'
854+
path_glob : ident [ "::" [ path_glob
855+
| '*' ] ] ?
856856
| '{' ident [ ',' ident ] * '}' ;
857857
~~~~
858858

@@ -1743,7 +1743,7 @@ import public items from their destination, not private items.
17431743
attribute : '#' '!' ? '[' meta_item ']' ;
17441744
meta_item : ident [ '=' literal
17451745
| '(' meta_seq ')' ] ? ;
1746-
meta_seq : meta_item [ ',' meta_seq ]* ;
1746+
meta_seq : meta_item [ ',' meta_seq ] ? ;
17471747
~~~~
17481748

17491749
Static entities in Rust &mdash; crates, modules and items &mdash; may have _attributes_
@@ -3027,11 +3027,11 @@ then any `else` block is executed.
30273027
### Match expressions
30283028

30293029
~~~~ {.notrust .ebnf .gram}
3030-
match_expr : "match" expr '{' match_arm [ '|' match_arm ] * '}' ;
3030+
match_expr : "match" expr '{' match_arm * '}' ;
30313031
3032-
match_arm : match_pat "=>" [ expr "," | '{' block '}' ] ;
3032+
match_arm : attribute * match_pat "=>" [ expr "," | '{' block '}' ] ;
30333033
3034-
match_pat : pat [ ".." pat ] ? [ "if" expr ] ;
3034+
match_pat : pat [ '|' pat ] * [ "if" expr ] ? ;
30353035
~~~~
30363036

30373037
A `match` expression branches on a *pattern*. The exact form of matching that
@@ -3137,7 +3137,7 @@ using the `ref` keyword,
31373137
or to a mutable reference using `ref mut`.
31383138

31393139
Subpatterns can also be bound to variables by the use of the syntax
3140-
`variable @ pattern`.
3140+
`variable @ subpattern`.
31413141
For example:
31423142

31433143
~~~~

0 commit comments

Comments
 (0)