-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
BTreeMap: check some invariants in unit tests #75480
Conversation
I think at this time I would avoid publicly exposing any introspection functions -- that shouldn't be needed for unit tests. If there's some reason we can't avoid it we can mark them unstable and |
I sympathise with that principle, but also with the viewpoint that unit tests shouldn't have more privilege than client code. Either way is fine for me. You tell me how to test things thoroughly.
|
I'm perfectly fine with unit tests having access to the internal - in fact, that seems like a good thing - but I don't want that access to leak to everyone using BTreeMap (i.e., the visibility shouldn't be more than pub(super) or so). If you put unit tests in a separate file and use |
My assessment of "true" unit tests was based on old experience, in hashmap code, right now I see it behaving just fine in btree. And on the fact that all so-called btree unit tests are modelled as integration tests, but looking at the history of Cargo.toml, that stems from a merge of collections into alloc. So are you saying that I can move the btree unit tests from the top tests directory to their "native" location? All of them, or what reason would there be to segregate? Some cases test immutable behaviour and I did not add check_invariant there, but that doesn't strike me as a good reason. |
It should be fine to do so, yes - I'm not sure why they're split today. I don't care if we move all or just add new ones to the new location. |
4b314d4
to
230e3f3
Compare
230e3f3
to
4e2fbb8
Compare
Hold on, in times of social distancing it did not trickle down how close unit tests can be... no need to touch map.rs |
4e2fbb8
to
31c69cd
Compare
31c69cd
to
9866601
Compare
I think we can probably just use panic! rather than returning a result with the invariant checking, seems cleaner (and easier to track down exactly where it failed). |
I started that way. It's a little easier to write, but I found it harder to locate where in a test case the violation occurred. And it would allow to collect all violations, but being able to print the tree entirely trumps that. So back to panic. Something that bugged me more is that there already is a function calculating length, and moreover it descends recursively, which in other places (in main code) is avoided. So an attempt at reusing this kind of tree navigation. |
ec2dcb4
to
8c4641b
Compare
@bors r+ |
📌 Commit 8c4641b has been approved by |
…rk-Simulacrum BTreeMap: check some invariants in unit tests
…rk-Simulacrum BTreeMap: check some invariants in unit tests
…rk-Simulacrum BTreeMap: check some invariants in unit tests
…rk-Simulacrum BTreeMap: check some invariants in unit tests
…rk-Simulacrum BTreeMap: check some invariants in unit tests
☀️ Test successful - checks-actions, checks-azure |
No description provided.