Skip to content
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

debug_assertion validations #1797

Merged
merged 6 commits into from
Apr 10, 2020
Merged

debug_assertion validations #1797

merged 6 commits into from
Apr 10, 2020

Conversation

pksunkara
Copy link
Member

@pksunkara pksunkara commented Apr 8, 2020

Closes 5 issues. And provides the way we will be doing validations for programmer errors.

debug_assertions will be enabled when no optimizations exist. So, when people are using clap and use a test for it, this panicking happen. But if they build a release to distribute binary, this would not happen. In fact, the checks would not even occur making it more performant.

@pksunkara pksunkara linked an issue Apr 9, 2020 that may be closed by this pull request
@pksunkara pksunkara marked this pull request as ready for review April 9, 2020 14:52
Copy link
Contributor

@CreepySkeleton CreepySkeleton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exemplary. Almost.

Most of it is just nitpicking, but important one.

Also, #[should_panic(expected = "...")] can be replaced with #[should_panic = "..."] which is shorter.

Comment on lines +39 to +41
- name: Release profile tests
script:
- cargo test --release --features yaml unstable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will skip cfg(debug_assertions) and helped me catch a few issues with our tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do we need to skip them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests behave differently for normal execution and under release profile execution. I want to introduce testing both behaviour by doing:

#[test]
#[cfg_attr(debug_assertions, should_panic = "..."))]

But it's a step for later. This is setting up for it.

Copy link
Contributor

@CreepySkeleton CreepySkeleton Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems I confused you, sorry. My question is: why do you need to run tests in release in the first place? You see, if test are run only in debug mode, there's no "different behavior" problem. What does the release pass gives us on it's own and why can't we ditch it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those who release without proper testing deserve what they get. The desired

we are not entitled here to pass judgement on how people go about their dev process. Kindly refrain from making such comments in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not about debug and release versions having the same behaviour, it's about them having defined behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what is the defined behavior? I wouldn't try to define behavior in cases when user makes mistakes, like giving the same name for an arg and a group. If they do so but skip checks, they harvest what they sow (likely wrong behavior or indescriptive panics, like unwrapped on None); this is expected and we shouldn't encourage it.

In case the user did everything right, release and debug builds must behave identically, and this is the only reason I see to run release tests. Otherwise it's useless because if we are sure they are the same, just one run is enough. Anyway, this is not really important since we don't pay for the extra time wasted on CI; I'm just trying to decipher your logic 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined behaviour will be changing on case-to-case. Some of them just silently fail right now or show error messages which doesn't make sense. Some of them lead to panic. And this is a setup to start testing those too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waste of time if you ask me: ways to make an error are countless. We can't hope to catch all of them; the select ones we do cover are served by debug builds.

A user:

  • did everything right - clap works, sun shines, angels sing.
  • made a mistake (some action that's at disagreement with our documentation) and checked with debug build - they get nice descriptive error.
  • made a mistake but didn't make use of the debug check - they are on they own, no guarantees here.

I honestly don't see how release builds help anyone.

clap_derive/tests/flatten.rs Show resolved Hide resolved
tests/require.rs Outdated Show resolved Hide resolved
src/build/app/mod.rs Outdated Show resolved Hide resolved
src/build/app/mod.rs Show resolved Hide resolved
src/build/app/mod.rs Show resolved Hide resolved
src/build/app/settings.rs Show resolved Hide resolved
src/build/arg/mod.rs Outdated Show resolved Hide resolved
tests/groups.rs Show resolved Hide resolved
tests/help.rs Show resolved Hide resolved
@pksunkara
Copy link
Member Author

pksunkara commented Apr 9, 2020

Replied to your comments. Go ahead and resolve conversations which you feel has satisfied your comments.

The only actionable comments are should_panic and this, but the resolution for that would probably be creating a new issue since I haven't actually touched that part of the code other than moving it a bit.

@pksunkara
Copy link
Member Author

Id can be a struct

I think it used to be a String before but Kevin made it Id for performance reasons.

@CreepySkeleton
Copy link
Contributor

I think it used to be a String before but Kevin made it Id for performance reasons.

Precisely. This is why name: String is under #[cfg(debug_assertions)], i.e it will only be present in debug builds. In release mode, the struct will consist of the only id: u64, pretty much the same as we have currently. Performance concerns are not really relevant in debug builds, but "nicer debug messages" are vital sometimes.

@pksunkara
Copy link
Member Author

Ah, I missed that part. That would work. Could you create an issue please? Thanks.

@CreepySkeleton
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 10, 2020

Build succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants