Skip to content

unit testing improperly ignores test funs that take args #4391

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
jbclements opened this issue Jan 9, 2013 · 3 comments
Closed

unit testing improperly ignores test funs that take args #4391

jbclements opened this issue Jan 9, 2013 · 3 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@jbclements
Copy link
Contributor

First bug report submitted using github: apologies in advance for any #githubfail :

It appears to me that the unit testing framework silently ignores functions marked #[test] that accept an argument.

Here's the file:

extern mod std;

#[test]
fn boozle(t :int) -> int {
  return 9;
}

fn main() {
  io::println("abc");
}

here's the transcript of running this:

jclements-09740:tmp clements$ rustc --test ./badtest.rs -o badtest
./badtest.rs:4:10: 4:13 warning: unused variable: `t`
./badtest.rs:4 fn boozle(t :int) -> int {
                         ^~~
warning: no debug symbols in executable (-arch x86_64)
jclements-09740:tmp clements$ ./badtest

running 0 tests

result: ok. 0 passed; 0 failed; 0 ignored

jclements-09740:tmp clements$ 

I would have expected either a compile-time error or a failed test. A compile-time error, really.

@pnkfelix
Copy link
Member

Indeed; we are already issuing a fatal error when someone tries to insert an unsafe function, so other kinds of mismatches seem plausible to me. I think all of the relevant code here is contained within librustc/front/test.rs

@graydon
Copy link
Contributor

graydon commented May 1, 2013

just a bug, de-milestoning.

bors added a commit that referenced this issue May 2, 2013
…ly-skip-erroneous-tests, r=pnkfelix

...e.

Fixes #4391.
@pnkfelix
Copy link
Member

pnkfelix commented May 2, 2013

Fixed by SHA: d1f7220 and its parents (namely SHA: 5f1a90e )

@pnkfelix pnkfelix closed this as completed May 2, 2013
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jan 17, 2021
Sander Maijers reports that #[test] functions that return a `Result`
with a named lifetime fail to compile with a "functions used as tests
must have signature fn() -> ()" error message—but that can't really be
right, because #[test] functions that return a `Result` with a static
lifetime are accepted!

It turns out that this error message dates all the way back to April
2013's 5f1a90e ("Issue 4391: rustc should not silently skip tests
with erroneous signature."). But after RFC 1937, we actually do accept
non-unit return types in tests. Let's edit the error message
accordingly.

This resolves rust-lang#55228, and is of historical interest to rust-lang#4391.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

No branches or pull requests

3 participants