Skip to content

Commit 1c8d33d

Browse files
committed
---
yaml --- r: 136041 b: refs/heads/master c: cc31d9c h: refs/heads/master i: 136039: ffde64b v: v3
1 parent f7d21ef commit 1c8d33d

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
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: a29df44f51f950549957128ad1b65b2576a48383
2+
refs/heads/master: cc31d9cabcc6c8ad396c1aae6257a4b5ea25cb46
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 749ff5e76a0d08837964e44c66654679a3a88bb8
55
refs/heads/try: ca87704735687dad44b26788c773df2d87b3b710

trunk/src/libsyntax/test.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,30 +274,43 @@ fn strip_test_functions(krate: ast::Crate) -> ast::Crate {
274274
fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
275275
let has_test_attr = attr::contains_name(i.attrs.as_slice(), "test");
276276

277-
fn has_test_signature(i: &ast::Item) -> bool {
277+
#[deriving(PartialEq)]
278+
enum HasTestSignature {
279+
Yes,
280+
No,
281+
NotEvenAFunction,
282+
}
283+
284+
fn has_test_signature(i: &ast::Item) -> HasTestSignature {
278285
match &i.node {
279286
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
280287
let no_output = match decl.output.node {
281288
ast::TyNil => true,
282-
_ => false
289+
_ => false,
283290
};
284-
decl.inputs.is_empty()
285-
&& no_output
286-
&& !generics.is_parameterized()
291+
if decl.inputs.is_empty()
292+
&& no_output
293+
&& !generics.is_parameterized() {
294+
Yes
295+
} else {
296+
No
297+
}
287298
}
288-
_ => false
299+
_ => NotEvenAFunction,
289300
}
290301
}
291302

292-
if has_test_attr && !has_test_signature(i) {
303+
if has_test_attr {
293304
let diag = cx.span_diagnostic;
294-
diag.span_err(
295-
i.span,
296-
"functions used as tests must have signature fn() -> ()."
297-
);
305+
match has_test_signature(i) {
306+
Yes => {},
307+
No => diag.span_err(i.span, "functions used as tests must have signature fn() -> ()"),
308+
NotEvenAFunction => diag.span_err(i.span,
309+
"only functions may be used as tests"),
310+
}
298311
}
299312

300-
return has_test_attr && has_test_signature(i);
313+
return has_test_attr && has_test_signature(i) == Yes;
301314
}
302315

303316
fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// compile-flags: --test
12+
13+
#[test]
14+
mod foo {} //~ ERROR only functions may be used as tests
15+
16+
fn main() {}

0 commit comments

Comments
 (0)