Skip to content

Issue 4391: rustc should not silently skip tests with erroneous signatur... #6111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ pub impl <T:Hash + Eq> HashSet<T> {
}
}

#[test]
#[cfg(test)]
mod test_map {
use container::{Container, Map, Set};
use option::{None, Some};
Expand Down Expand Up @@ -1009,7 +1009,7 @@ mod test_map {
}
}

#[test]
#[cfg(test)]
mod test_set {
use super::*;
use container::{Container, Map, Set};
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
}
}

#[test]
#[cfg(test)]
struct P {a: int, b: float}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ fn test_run_basic() {
po.recv();
}

#[test]
#[cfg(test)]
struct Wrapper {
mut f: Option<Chan<()>>
}
Expand Down
11 changes: 9 additions & 2 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn fold_item(cx: @mut TestCtxt, i: @ast::item, fld: @fold::ast_fold)
debug!("current path: %s",
ast_util::path_name_i(copy cx.path, cx.sess.parse_sess.interner));

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

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

Expand All @@ -188,6 +188,13 @@ fn is_test_fn(i: @ast::item) -> bool {
}
}

if has_test_attr && !has_test_signature(i) {
let sess = cx.sess;
sess.span_err(
i.span,
~"functions used as tests must have signature fn() -> ()."
);
}
return has_test_attr && has_test_signature(i);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn test_fuzzy_eq_eps() {
assert!(!(&1.5f).fuzzy_eq_eps(&0.9, &0.5));
}

#[test]
#[cfg(test)]
mod test_complex{
use cmp::*;

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ mod tests {
assert!(*deq.get(3) == d);
}

#[test]
#[cfg(test)]
fn test_parameterized<T:Copy + Eq + Durable>(a: T, b: T, c: T, d: T) {
let mut deq = Deque::new();
assert!(deq.len() == 0);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ mod test {
new_parser_from_source_str(ps,~[],~"bogofile",source_str)
}

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