6 ms·
Regarding 2., I'm going to assume they have at least some unit tests. It's not clear that even 100% coverage would have picked up this bug, since it doesn't au
by QuantumChaos 12y ago
Regarding 2., I'm going to assume they have at least some unit tests.
It's not clear that even 100% coverage would have picked up this bug, since it doesn't automatically appear as a result of taking a particular code path.
I think that comparing to a naive algorithm on a large number of strings, or using a fuzzing tool, might be helpful, but this might also slow down the test suite excessively.
I find unit tests are a bit like good form at the gym. Whenever someone gets injured, they think back to the last exercise they did and find some imperfection in their form. They then attribute their injury to not using perfect form. Similarly, whenever a bug appears, there is a tendency to find a unit test that would have caught the bug, and therefore attribute it to insufficient testing.
The real value of testing (and good form) can only be demonstrated by having a criteria for good testing and seeing if following this reduces the number of bugs.
- Ono-Sendai 12y agoThey did have some tests, obviously not enough though.
- sitkack 12y agoI don't think it is the number but the depth. Something like QuickCheck would help. Or, having simpler code.
- cjbprime 12y agoThis is a really good point, and it looks like QuickCheck is supported on Rust -- here's one of several implementations: https://github.com/BurntSushi/quickcheck https://github.com/BurntSushi/quickcheck Would be pretty cool to see someone hook it up to the standard library tests.
- akkartik 12y agoNo unit tests for the string library: https://github.com/rust-lang/rust/blob/6843d8ccd5/src/libcoretest/str.rs https://github.com/rust-lang/rust/blob/6843d8ccd5/src/libcor... (That's the hash for tip at the time of this comment.)
- pcwalton 12y agoThere are more tests that test the string library in src/test/run-pass/. This reflects the fact that std::str predates the current unit testing infrastructure, basically.
- dbaupp 12y agoThere's a lot of tests: https://github.com/rust-lang/rust/blob/f66fd2eed10de2acacd8af73c704bf4d140410bb/src/libcollections/str.rs#L870-L2356 https://github.com/rust-lang/rust/blob/f66fd2eed10de2acacd8a... Testing is something Rust is very big on, e.g. we run the test suite on many architectures/platforms each pull request and merge only if it passes on all: master is always green.
- akkartik 12y agoAh, I see the ones for contains: https://github.com/rust-lang/rust/blob/f66fd2eed1/src/libcollections/str.rs#L1518 https://github.com/rust-lang/rust/blob/f66fd2eed1/src/libcol... Thanks for pointing them out.