Skip to content

Commit 9d9906c

Browse files
committed
---
yaml --- r: 272760 b: refs/heads/beta c: 0d6b4e0 h: refs/heads/master
1 parent 417b6d1 commit 9d9906c

File tree

6 files changed

+105
-29
lines changed

6 files changed

+105
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 1d76ccd9d45e818e0554c8ce491d5ed20130e9c8
26+
refs/heads/beta: 0d6b4e03862065d0b1296e93c9bdfed25e0f60a4
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/COMPILER_TESTS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ whole, instead of just a few lines inside the test.
4242
* `ignore-test` always ignores the test
4343
* `ignore-lldb` and `ignore-gdb` will skip the debuginfo tests
4444
* `min-{gdb,lldb}-version`
45+
* `should-panic` indicates that the test should fail; used for "meta testing",
46+
where we test the compiletest program itself to check that it will generate
47+
errors in appropriate scenarios
4548

4649
## Revisions
4750

@@ -73,3 +76,9 @@ fn test_foo() {
7376
let x: usize = 32_u32; //[foo]~ ERROR mismatched types
7477
}
7578
```
79+
80+
Note that not all headers have meaning when customized too a revision.
81+
For example, the `ignore-test` header (and all "ignore" headers)
82+
currently only apply to the test as a whole, not to particular
83+
revisions. The only headers that are intended to really work when
84+
customized to a revision are error patterns and compiler flags.

branches/beta/src/compiletest/compiletest.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,16 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
354354
}
355355

356356
pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
357+
let early_props = header::early_props(config, &testpaths.file);
357358
test::TestDescAndFn {
358359
desc: test::TestDesc {
359360
name: make_test_name(config, testpaths),
360-
ignore: header::is_test_ignored(config, &testpaths.file),
361-
should_panic: test::ShouldPanic::No,
361+
ignore: early_props.ignore,
362+
should_panic: if early_props.should_panic {
363+
test::ShouldPanic::Yes
364+
} else {
365+
test::ShouldPanic::No
366+
},
362367
},
363368
testfn: make_test_closure(config, testpaths),
364369
}

branches/beta/src/compiletest/header.rs

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ pub fn load_props_into(props: &mut TestProps, testfile: &Path, cfg: Option<&str>
164164
if let Some(of) = parse_forbid_output(ln) {
165165
props.forbid_output.push(of);
166166
}
167-
168-
true
169167
});
170168

171169
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
@@ -179,7 +177,42 @@ pub fn load_props_into(props: &mut TestProps, testfile: &Path, cfg: Option<&str>
179177
}
180178
}
181179

182-
pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
180+
pub struct EarlyProps {
181+
pub ignore: bool,
182+
pub should_panic: bool,
183+
}
184+
185+
// scan the file to detect whether the test should be ignored and
186+
// whether it should panic; these are two things the test runner needs
187+
// to know early, before actually running the test
188+
pub fn early_props(config: &Config, testfile: &Path) -> EarlyProps {
189+
let mut props = EarlyProps {
190+
ignore: false,
191+
should_panic: false,
192+
};
193+
194+
iter_header(testfile, None, &mut |ln| {
195+
props.ignore =
196+
props.ignore ||
197+
parse_name_directive(ln, "ignore-test") ||
198+
parse_name_directive(ln, &ignore_target(config)) ||
199+
parse_name_directive(ln, &ignore_architecture(config)) ||
200+
parse_name_directive(ln, &ignore_stage(config)) ||
201+
parse_name_directive(ln, &ignore_env(config)) ||
202+
(config.mode == common::Pretty &&
203+
parse_name_directive(ln, "ignore-pretty")) ||
204+
(config.target != config.host &&
205+
parse_name_directive(ln, "ignore-cross-compile")) ||
206+
ignore_gdb(config, ln) ||
207+
ignore_lldb(config, ln);
208+
209+
props.should_panic =
210+
props.should_panic ||
211+
parse_name_directive(ln, "should-panic");
212+
});
213+
214+
return props;
215+
183216
fn ignore_target(config: &Config) -> String {
184217
format!("ignore-{}", util::get_os(&config.target))
185218
}
@@ -246,26 +279,11 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
246279
false
247280
}
248281
}
249-
250-
let val = iter_header(testfile, None, &mut |ln| {
251-
!parse_name_directive(ln, "ignore-test") &&
252-
!parse_name_directive(ln, &ignore_target(config)) &&
253-
!parse_name_directive(ln, &ignore_architecture(config)) &&
254-
!parse_name_directive(ln, &ignore_stage(config)) &&
255-
!parse_name_directive(ln, &ignore_env(config)) &&
256-
!(config.mode == common::Pretty && parse_name_directive(ln, "ignore-pretty")) &&
257-
!(config.target != config.host && parse_name_directive(ln, "ignore-cross-compile")) &&
258-
!ignore_gdb(config, ln) &&
259-
!ignore_lldb(config, ln)
260-
});
261-
262-
!val
263282
}
264283

265284
fn iter_header(testfile: &Path,
266285
cfg: Option<&str>,
267-
it: &mut FnMut(&str) -> bool)
268-
-> bool {
286+
it: &mut FnMut(&str)) {
269287
let rdr = BufReader::new(File::open(testfile).unwrap());
270288
for ln in rdr.lines() {
271289
// Assume that any directives will be found before the first
@@ -274,7 +292,7 @@ fn iter_header(testfile: &Path,
274292
let ln = ln.unwrap();
275293
let ln = ln.trim();
276294
if ln.starts_with("fn") || ln.starts_with("mod") {
277-
return true;
295+
return;
278296
} else if ln.starts_with("//[") {
279297
// A comment like `//[foo]` is specific to revision `foo`
280298
if let Some(close_brace) = ln.find("]") {
@@ -283,20 +301,18 @@ fn iter_header(testfile: &Path,
283301
Some(s) => s == &lncfg[..],
284302
None => false,
285303
};
286-
if matches && !it(&ln[close_brace+1..]) {
287-
return false;
304+
if matches {
305+
it(&ln[close_brace+1..]);
288306
}
289307
} else {
290308
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
291309
ln)
292310
}
293311
} else if ln.starts_with("//") {
294-
if !it(&ln[2..]) {
295-
return false;
296-
}
312+
it(&ln[2..]);
297313
}
298314
}
299-
return true;
315+
return;
300316
}
301317

302318
fn parse_error_pattern(line: &str) -> Option<String> {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// revisions: a
12+
// pretty-expanded FIXME #23616
13+
14+
// Counterpart to `meta-expected-error-wrong-rev.rs`
15+
16+
#[cfg(a)]
17+
fn foo() {
18+
let x: u32 = 22_usize; //[a]~ ERROR mismatched types
19+
}
20+
21+
fn main() { }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// revisions: a
12+
// should-panic
13+
// pretty-expanded FIXME #23616
14+
15+
// This is a "meta-test" of the compilertest framework itself. In
16+
// particular, it includes the right error message, but the message
17+
// targets the wrong revision, so we expect the execution to fail.
18+
// See also `meta-expected-error-correct-rev.rs`.
19+
20+
#[cfg(a)]
21+
fn foo() {
22+
let x: u32 = 22_usize; //[b]~ ERROR mismatched types
23+
}
24+
25+
fn main() { }

0 commit comments

Comments
 (0)