Almost agree. Strongly agree in terms of public API of libraries. But when it comes to writing tests, I pretty quickly reach for macros. But in my defense, they are usually pretty simple.
-
-
Replying to @burntsushi5 @pcwalton
Sounds interesting. Could you link/name an example repo?
1 reply 0 retweets 0 likes -
Replying to @jacobegner @pcwalton
This one is pretty tame: https://github.com/BurntSushi/rust-csv/blob/90cdd240e875108f2510ef8251685278e9a43706/csv-core/src/reader.rs#L1329 … The tests in the regex crate take it all the way to 11 though.
2 replies 0 retweets 2 likes -
Replying to @burntsushi5 @pcwalton
I'm a newcomer to Rust, so hopefully I can get some sanity checks here. The csv macro is a macro instead of a function so you can pass variable number of args? And parses_to helps you create same sort of test with different parameters?
1 reply 0 retweets 0 likes -
Replying to @jacobegner @pcwalton
The latter case more than the former, but yes. And also, it creates the `#[test] fn
$name() { ... }` for you too. Here's another example, where most tests are just one line because of the use of macros: https://github.com/BurntSushi/ripgrep/blob/41695c66fa7d423f961e09741cc75a1b8488e081/globset/src/glob.rs#L1008 …1 reply 0 retweets 1 like -
Replying to @burntsushi5 @pcwalton
Right, I was thinking if Rust had equivalent of NUnit's TestCase attribute (https://github.com/nunit/docs/wiki/TestCase-Attribute …), parses_to could have been a fn. Maybe I should see if Rust leadership would be open to a PR for such a feature.
1 reply 0 retweets 0 likes -
Replying to @jacobegner @pcwalton
Not familiar with nunit. But I don't actually think using macros for this is that bad. They are flexible to permit a lot of interesting ways to write tests.
1 reply 0 retweets 0 likes -
Replying to @burntsushi5 @pcwalton
Sure, I was just thinking it'd be nice to have one standard and general macro so people don't have to write their own macros.
1 reply 0 retweets 0 likes -
-
Replying to @burntsushi5 @pcwalton
So you're saying that if I make the general macro, you'll be impressed
(or I poorly communicated my proposed general macro).1 reply 0 retweets 0 likes
Assuming we are thinking about the same thing here, then yes, I would be impressed. :-) You might consider looking at the regex crate's use of macros. Macros are used to parameterize the entire test suite.
-
-
Replying to @burntsushi5 @pcwalton
The test-case crate (https://crates.io/crates/test-case …) does what I was imagining. #[test_case(arg1, arg2 => expectedReturnValue ; "failure message"] could be used on a parses_to function that returns the 'got' value.
1 reply 0 retweets 1 like -
@frondeus you're impressing people0 replies 0 retweets 0 likes
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.