Skip to content

Commit d38aa4b

Browse files
committed
---
yaml --- r: 137208 b: refs/heads/release-prep c: cc31d9c h: refs/heads/master v: v3
1 parent 3b097f0 commit d38aa4b

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
@@ -29,4 +29,4 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2929
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
3030
refs/heads/libuv-update-temp-branch: 6ed22c618766f1f2a2e108eef8ce3f51be0f70b7
3131
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
32-
refs/heads/release-prep: a29df44f51f950549957128ad1b65b2576a48383
32+
refs/heads/release-prep: cc31d9cabcc6c8ad396c1aae6257a4b5ea25cb46

branches/release-prep/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)