Fix queen-attack's #[should_panic] parameter#259
Fix queen-attack's #[should_panic] parameter#259gnuvince wants to merge 1 commit intoexercism:masterfrom
Conversation
The .unwrap() method does not generate a panic string, so the test always failed. The test can be fixed either by keeping the .unwrap() call and removing the `expected` argument from the attribute, or by keeping the attribute as-is, and using the .expect() method. I've picked the former option to remain consistent with other tests (in this problem and others) that use .unwrap().
There was a problem hiding this comment.
the test always failed
Well, there must be at least one implementation that is able to pass the tests, since otherwise the example solution would have failed the tests too. And we wouldn't have merged a PR without passing tests (otherwise there is a risk we could make unsolvable tests), so it is probably the case that the example solution passes the test.
It looks like after this was added in #119 we started preferring not explicitly checking error messages e.g. #147 (comment) and #169.
So on the same tack we should remove this expected from this should_panic. If you grep for all should_panic, the only other should_panic are in grains where we deliberately expect a panic, unlike queen-attack.
As an alternative, we may use is_err() instead, but note that this requires the student to use Result, whereas with the changed proposed in this PR the student may use both Result or Option (or even any other type that has an unwrap()...!)
Please, if anyone think we should use is_err instead, speak up. Otherwise I would suggest it be merged as-is (but maybe edit the commit message to reflect the reality instead of "the test always failed")
|
If Err is constructed with a string, that string is returned as part of the panic. At least that was true when I wrote this code. I doubt that a recent Rust release has changed that behavior, as that would seem to be a breaking change. I prefer the current approach because:
|
|
If the current approach is to be kept, then it would be preferable to offer a skeleton lib.rs file as some other problems do, or at least include a link to the relevant Rust book's chapter. In the 25+ previous problems I have completed, whenever a function or method returns a value of type (Also, as a general tip for writing Rust, don't use |
|
Ordered in increasing order of relevance to this particular PR:
Doh, guilty. I may have to redo some submissions. https://doc.rust-lang.org/book/error-handling.html#defining-your-own-error-type agrees with what you say. And this leads very well into the next point.
It's agreed that it's natural if one writes minimal code to pass the tests. Obviously we would hope that a real library does not do this, but if we do not control what types the student might put into the error type, it is difficult to test. On that note, we can see that if we use an So as a side question, we may discuss: should more exercises' test suites in this track explicitly define enums for possible errors and then explicitly check that the correct enum variant is used? Note that from what I know of the Swift track, they consistently do this. I don't have time to show y'all all the examples, but:
Should we double down on this by showing it twice, or is showing it once in https://github.com/exercism/xrust/blob/master/exercises/grains/tests/grains.rs#L46 sufficient?
After looking at the first few tests in this file (I should have done that instead of just looking at the changed)... Wow, I was completely wrong in this. There were already tests above that use That means that the test
My recommendation is now:
|
|
Just drop the test. |
Closes exercism#259 As discussed in exercism#259 this test can be removed.
|
Thanks for helping us improve the tests, @gnuvince! |
The .unwrap() method does not generate a panic string, so the test
always failed. The test can be fixed either by keeping the .unwrap()
call and removing the
expectedargument from the attribute, or bykeeping the attribute as-is, and using the .expect() method.
I've picked the former option to remain consistent with other tests (in
this problem and others) that use .unwrap().