-
Notifications
You must be signed in to change notification settings - Fork 24
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
Formatter: Documentation #14
Comments
Problem I see with this is that we support several different sources:
The problem is with the last two in particular, as we can only retrieve a string from a panic, no structured data (such as "expected: …", "found: …", etc). |
From Panics string we can just put the string and let it go for now. As goes the saying: “Two seated intellectuals goes less far that a walking dumb guy“. ;-) |
I agree. :) Rust's Or we would have to provide our own macro which would return Simple proof-of-concept: struct IsEqError {
lhs: String,
rhs: String,
file: &'static str,
line: u32,
column: u32,
}
macro_rules! is_eq {
($lhs:expr, $rhs:expr) => {
if $lhs == $rhs {
Ok(())
} else {
Err(IsEqError {
lhs: $lhs.to_string(),
rhs: $rhs.to_string(),
file: file!(),
line: line!(),
column: column!(),
})
}
}
}
fn test<F>(f: F) where F: Fn() -> Result<(), IsEqError> {
match f() {
Ok(()) => println!("ok"),
Err(IsEqError { lhs, rhs, file, line, column }) => {
println!("Failure/Error: ({}:{}:{})", file, line, column);
println!("");
println!(" Expected: {} == {}", lhs, rhs);
println!(" Found: {} != {}", lhs, rhs);
}
}
}
fn main() {
let foo = 1;
test(|| is_eq!(foo, 2));
} … producing this:
|
This being said I think in the long run we need to improve Rust's testing API instead of trying to shoehorn our far more expressive API into it. These hacks should—if at all—only be seen as temporary fixes and no more. Especially as tight 1st-class integration with |
Tests are documentation, and the formatters should represent that. Rspec has some nice examples of a doc output, mocha.js also.
Here is an example of how it looks like:
Not hard to do. Just some work.
The text was updated successfully, but these errors were encountered: