I really would like to be able to this:
fn outer(x: i32) -> i32 {
fn inner(a: i32, b: i32) -> i32 {
a + b
}
#[test]
fn test_inner() {
assert_eq!(inner(3, 5), 8);
}
inner(x, 5)
}
#[test]
fn test_outer() {
assert_eq!(outer(3), 8);
}
But why though ? Do you want to be able to test things inner to your function ? How about an assert_test! that would compile / trigger only when in test mode ? Just an idea.
Because this is convenient for testing nested functions. Currently I'd have to move the fn outside to be able to test it separately.
@Cobrand Yeah, something like this will be great:
assert!
assert_eq!
debug_assert!
debug_assert_eq!
test_assert!
test_assert_eq!
I'm just arguing against my own idea here, but that would require either :
My code is horrible so it doesn't have that much tests, is it possible to run tests in release mode ? If that is the case, the second option is a no-no I guess.
The problem with this is that the test harness needs to access the inner functions, which it can't do because you can't name them.
I'm marking as a diagnostics issue so that we print a warning in this case at least.
Why was the #51450 PR accepted, while the RFC is still unmerged?
I disagree with the approach taken (a new lint), we should either (https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397418564):
unused_attribute isn't firing, and let that handle the lint side#[test] functions anywhere, as per https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123
Most helpful comment
I'm marking as a diagnostics issue so that we print a warning in this case at least.