-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
T-dev-toolsRelevant to the development tools team, which will review and decide on the RFC.Relevant to the development tools team, which will review and decide on the RFC.
Description
Issue by Kimundi
Monday Feb 04, 2013 at 12:53 GMT
For earlier discussion, see rust-lang/rust#4782
This issue was labelled with: A-an-interesting-project, A-testsuite, A-traits, I-wishlist in the Rust repository
After an discussion about how for example 0 == -0
, and how it interacts with traits, I had the thought it might be nice to have unit tests on traits that get generated for for each impl
of it.
Example:
trait Bar {
static fn zero() -> Self;
fn neg(&self) -> Self;
}
#[test(trait)]
fn test_bar<T: Bar>() {
let x: T = Bar::zero();
let y = x.neg();
assert x == y;
}
in some other crate:
impl Bar for float {
static fn zero() -> float { 0.0 }
fn neg(&self) -> float { - *self }
}
Then a rustc --test for that crate would generate this function:
#[test]
fn test_bar_float() { test_bar::<float>() }
This would require trait test to somehow be made publicly callable from other crates for test compilation.
Alternative example, which might be easier to implement:
trait Bar {
static fn zero() -> Self;
fn neg(&self) -> Self;
#[test]
fn test_bar() {
let x: Self = zero();
let y = x.neg();
assert x == y;
}
}
la10736, burdges, carado, zroug, esoterra and 5 moregilescope
Metadata
Metadata
Assignees
Labels
T-dev-toolsRelevant to the development tools team, which will review and decide on the RFC.Relevant to the development tools team, which will review and decide on the RFC.