On 27/08/12 03:25, Steve Jenson wrote:
Based on that, I came up with a super naive attempt. I realize this is basically trying to write Java in rust so I apologize in advance.trait TestSuite { fn setup(); fn teardown(); } struct Calculator { fn add(m: int, n: int) -> int { return m + n; } } impl CalculatorTest : TestSuite { // error: use of undeclared type name `CalculatorTest` // without this, I have nothing to call //let calculator = Calculator(); fn setup() {} fn teardown() {} fn test_addition() -> bool { return true; } }
The impl syntax goes something like: `impl NameOfExistingType : NameOfExistingTraitThatIsBeingImplemented { ... }`. I suppose you might declare `impl Calculator : TestSuite { ... }` instead of `impl CalculatorTest : TestSuite { ... }`.
I am no expert but I can't think of a natural way to replicate an inheritance based JUnit like system in rust. I guess I would try building something based on first class functions instead. An alternative though (in-case you don't already know) is the test system built in to the compiler: http://dl.rust-lang.org/doc/tutorial.html#testing.
Gareth _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
