Skip to content

Commit d1f7220

Browse files
committed
auto merge of #6111 : pnkfelix/rust/issue4391-rustc-should-not-silently-skip-erroneous-tests, r=pnkfelix
...e. Fixes #4391.
2 parents 5458d7d + 9862cf7 commit d1f7220

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

src/libcore/hashmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ pub impl <T:Hash + Eq> HashSet<T> {
833833
}
834834
}
835835

836-
#[test]
836+
#[cfg(test)]
837837
mod test_map {
838838
use container::{Container, Map, Set};
839839
use option::{None, Some};
@@ -1009,7 +1009,7 @@ mod test_map {
10091009
}
10101010
}
10111011

1012-
#[test]
1012+
#[cfg(test)]
10131013
mod test_set {
10141014
use super::*;
10151015
use container::{Container, Map, Set};

src/libcore/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
673673
}
674674
}
675675
676-
#[test]
676+
#[cfg(test)]
677677
struct P {a: int, b: float}
678678
679679
#[test]

src/libcore/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ fn test_run_basic() {
797797
po.recv();
798798
}
799799
800-
#[test]
800+
#[cfg(test)]
801801
struct Wrapper {
802802
mut f: Option<Chan<()>>
803803
}

src/librustc/front/test.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn fold_item(cx: @mut TestCtxt, i: @ast::item, fld: @fold::ast_fold)
141141
debug!("current path: %s",
142142
ast_util::path_name_i(copy cx.path, cx.sess.parse_sess.interner));
143143

144-
if is_test_fn(i) || is_bench_fn(i) {
144+
if is_test_fn(cx, i) || is_bench_fn(i) {
145145
match i.node {
146146
ast::item_fn(_, purity, _, _, _) if purity == ast::unsafe_fn => {
147147
let sess = cx.sess;
@@ -169,7 +169,7 @@ fn fold_item(cx: @mut TestCtxt, i: @ast::item, fld: @fold::ast_fold)
169169
return res;
170170
}
171171

172-
fn is_test_fn(i: @ast::item) -> bool {
172+
fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool {
173173
let has_test_attr = !attr::find_attrs_by_name(i.attrs,
174174
~"test").is_empty();
175175

@@ -188,6 +188,13 @@ fn is_test_fn(i: @ast::item) -> bool {
188188
}
189189
}
190190

191+
if has_test_attr && !has_test_signature(i) {
192+
let sess = cx.sess;
193+
sess.span_err(
194+
i.span,
195+
~"functions used as tests must have signature fn() -> ()."
196+
);
197+
}
191198
return has_test_attr && has_test_signature(i);
192199
}
193200

src/libstd/cmp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn test_fuzzy_eq_eps() {
6464
assert!(!(&1.5f).fuzzy_eq_eps(&0.9, &0.5));
6565
}
6666

67-
#[test]
67+
#[cfg(test)]
6868
mod test_complex{
6969
use cmp::*;
7070

src/libstd/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mod tests {
353353
assert!(*deq.get(3) == d);
354354
}
355355

356-
#[test]
356+
#[cfg(test)]
357357
fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
358358
let mut deq = Deque::new();
359359
assert!(deq.len() == 0);

src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ mod test {
418418
new_parser_from_source_str(ps,~[],~"bogofile",source_str)
419419
}
420420

421-
#[test] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
421+
#[cfg(test)] fn to_json_str<E : Encodable<std::json::Encoder>>(val: @E) -> ~str {
422422
do io::with_str_writer |writer| {
423423
val.encode(~std::json::Encoder(writer));
424424
}

0 commit comments

Comments
 (0)